Пример #1
0
def process_passwd(request, req):
    if request.method == 'POST':
        form = ProcessPasswdForm(request.POST)
        
        if form.is_valid():
            try:
                db = helpers.default_database()
                user = LdapUser(database = db, primary_value = req.uid)
                user.hashedPassword = form.cleaned_data['passwd'].encode('utf-8')
                user.save()

            except ConstraintViolation:
                request.flash['error'] = "Le mot de passe fourni ne respecte pas les règles de sécurité de l'annuaire LDAP"

            else:
                req.delete()

                request.flash['success'] = "Votre mot de passe a été réinitialisé avec succès."
                return HttpResponseRedirect(reverse('ldap_server.views.login'))
    
    else:
        form = ProcessPasswdForm(label_suffix='')

    vars = { 'form': form }
    vars.update(csrf(request))

    return render_to_response('process_passwd.html', vars, context_instance=RequestContext(request))
Пример #2
0
def process_passwd(request, req):
    if request.method == 'POST':
        form = ProcessPasswdForm(request.POST)

        if form.is_valid():
            try:
                db = helpers.default_database()
                user = LdapUser(database=db, primary_value=req.uid)
                user.hashedPassword = form.cleaned_data['passwd'].encode(
                    'utf-8')
                user.save()

            except ConstraintViolation:
                request.flash[
                    'error'] = "Le mot de passe fourni ne respecte pas les règles de sécurité de l'annuaire LDAP"

            else:
                req.delete()

                request.flash[
                    'success'] = "Votre mot de passe a été réinitialisé avec succès."
                return HttpResponseRedirect(reverse('ldap_server.views.login'))

    else:
        form = ProcessPasswdForm(label_suffix='')

    vars = {'form': form}
    vars.update(csrf(request))

    return render_to_response('process_passwd.html',
                              vars,
                              context_instance=RequestContext(request))
Пример #3
0
def passwd(request):
    if request.method == 'POST':
        form = RequestPasswdForm(request.POST)

        if form.is_valid():
            req = form.save(commit=False)
            db = helpers.default_database()

            user = LdapUser(database=db,
                            primary_value=req.uid,
                            custom_filter='(mail=%s)' % req.email)

            if not user.dn:
                request.flash[
                    'error'] = "Aucune entrée correspondant au couple identifiant, adresse email de contact n'a pu être trouvé."

            else:
                req.type = Request.PASSWD
                req.save()

                t = loader.get_template('accounts/mailer/passwd_request')
                c = Context({
                    'name':
                    user.display_name,
                    'url':
                    request.build_absolute_uri(
                        reverse(process, kwargs={'token': req.token})),
                    'expire_in':
                    settings.REQ_EXPIRE_STR,
                })

                send_mail(u'Changement de mot de passe Supélec Rézo',
                          t.render(c),
                          settings.EMAIL_FROM, [req.email],
                          fail_silently=False)

                request.flash[
                    'success'] = "Un email a été envoyé à <a href=\"mailto:%(email)s\">%(email)s</a> pour que vous puissiez changer votre mot de passe." % {
                        'email': req.email.encode("utf-8")
                    }
                return HttpResponseRedirect(reverse('ldap_server.views.login'))
    else:
        form = RequestPasswdForm(label_suffix='')

    vars = {'form': form}
    vars.update(csrf(request))

    return render_to_response('passwd.html',
                              vars,
                              context_instance=RequestContext(request))
Пример #4
0
def passwd(request):
    if request.method == 'POST':
        form = RequestPasswdForm(request.POST)

        if form.is_valid():
            req = form.save(commit=False)
            db = helpers.default_database()
            
            user = LdapUser(database = db, primary_value = req.uid, custom_filter = '(mail=%s)' % req.email)
            
            if not user.dn:
                request.flash['error'] = "Aucune entrée correspondant au couple identifiant, adresse email de contact n'a pu être trouvé."

            else:
                req.type = Request.PASSWD
                req.save()

                t = loader.get_template('accounts/mailer/passwd_request')
                c = Context({
                        'name': user.display_name,
                        'url': request.build_absolute_uri(reverse(process, kwargs={ 'token': req.token })),
                        'expire_in': settings.REQ_EXPIRE_STR,
                    })

                send_mail(u'Changement de mot de passe Supélec Rézo', 
                        t.render(c),
                        settings.EMAIL_FROM, 
                        [req.email], 
                        fail_silently=False)

                request.flash['success'] = "Un email a été envoyé à <a href=\"mailto:%(email)s\">%(email)s</a> pour que vous puissiez changer votre mot de passe." % {'email': req.email.encode("utf-8")}
                return HttpResponseRedirect(reverse('ldap_server.views.login'))
    else:
        form = RequestPasswdForm(label_suffix='')

    vars = { 'form': form }
    vars.update(csrf(request))

    return render_to_response('passwd.html', vars, context_instance=RequestContext(request))