Commit 145e96fe authored by Gabriel Detraz's avatar Gabriel Detraz

Support de la redirection mail à la création du compte crans

parent 27b58257
......@@ -15,6 +15,7 @@ urlpatterns = patterns('',
url('^chgpass/(?P<ptype>adh)/(?P<uid>[0-9]+)/(?P<next>.*)/$', views.chgpass, name='chgpass'),
url('^redirection/$', views.redirection, name='redirection'),
url('^redirection/(?P<uid>[0-9]+)/$', views.redirection, name='redirection'),
url('^redirection/(?P<uid>[0-9]+)/(?P<generate>True)/(?P<next>.*)/$', views.redirection, name='redirection'),
url('^alias/$', views.alias, name='alias'),
url('^alias/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.alias, name='alias'),
url('^alias/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.alias, name='alias'),
......
......@@ -258,16 +258,24 @@ class RedirectionView(CableurOrSelfMixin, View):
form = MailForm(luser)
return render(request, self.template_name, {'form': form, 'luser': luser})
def post(self, request, aid, *args, **kwargs):
def post(self, request, aid, generate=False, next='/compte/', *args, **kwargs):
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % aid)[0]
form = MailForm(luser, request.POST)
if form.is_valid():
# La redirection n'est pas un champ ldap
if 'mailredirect' in form.changed_data:
mailredirect = unicode(form.cleaned_data['mailredirect'])
redirection_mail = subprocess.Popen(["sudo", "-n", "/usr/scripts/utils/forward.py", "--write", "--mail=%s" % mailredirect, "--name=%s" % luser['uid'][0]])
messages.success(request, u"""Votre redirection a bien été changée""")
return redirect("/compte/")
if mailredirect != "":
if not generate:
redirection_mail = subprocess.Popen(["sudo", "-n", "/usr/scripts/utils/forward.py", "--write", "--mail=%s" % mailredirect, "--name=%s" % luser['uid'][0]])
else:
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % aid, mode='w')[0]
with luser as adh:
adh['mailExt']=mailredirect
adh.history_gen()
adh.save()
messages.success(request, u"""Votre redirection a bien été prise en compte""")
return redirect(next)
return render(request, self.template_name, {'form': form, 'luser': luser})
......@@ -546,7 +554,11 @@ class ComptecransView(CableurMixin, View):
luser.history_gen()
luser.save()
messages.success(request, u"""Compte Crans crée, choisir un mot de passe""")
return redirect(reverse('compte:chgpass', args=(ptype,uid)))
if ptype == 'adh':
redir_url = reverse('compte:redirection', args=(luser['aid'][0], True, '/compte/'))
return redirect(reverse('compte:chgpass', args=(u'adh', luser['aid'][0], redir_url)))
else:
return redirect(reverse('compte:chgpass', args=(ptype,uid)))
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
comptecrans = ComptecransView.as_view()
......@@ -644,8 +656,9 @@ class CreateCompteView(CableurMixin, View):
adherent.create()
messages.success(request, u"""Compte crée""")
adh_url = reverse('compte:adhesion', args=(u'adh', adherent['aid'][0]))
redir_url = reverse('compte:redirection', args=(adherent['aid'][0], True, adh_url))
if comptecrans:
return redirect(reverse('compte:chgpass', args=(u'adh', adherent['aid'][0], adh_url)))
return redirect(reverse('compte:chgpass', args=(u'adh', adherent['aid'][0], redir_url)))
else:
return redirect(adh_url)
return render(request, self.template_name, {'form1' : form1, 'form2' : form2, 'form3' : form3, 'confirm' : confirm, 'comptecrans': comptecrans})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment