Пример #1
0
def signinup(request) :
    from .forms import SignInUpForm, UserEmail
    from .models import create_user

    if request.method == 'POST' :
        forgot = request.POST.get('forgot', None)
        if forgot :
            email = request.POST.get('email', None)
            if email :
                email = email.strip()
            
            if not UserEmail.objects.filter(email=email).exists() :
                pass
            else :
                for ue in UserEmail.objects.filter(email=email, is_confirmed=True).all() :
                    PasswordRecovery.objects.filter(user=ue.user).delete()
                    r = PasswordRecovery.create(user=ue.user)
                    r.save()

                from django.core.mail import EmailMultiAlternatives

                url = request.build_absolute_uri(reverse('openauth:recover', kwargs={ 'code' : r.rcode }))

                body_text = render_to_string('openauth/_email_recover.txt', RequestContext(request, {
                            'addr' : email,
                            'url'  : url,
                        }))
                body_html = render_to_string('openauth/_email_recover.html', RequestContext(request, {
                            'addr' : email,
                            'url'  : url,
                        }))

                msg = EmailMultiAlternatives('Notewave | Recover Password', body_text, '*****@*****.**', [email])
                msg.attach_alternative(body_html, 'text/html')
                try :
                    msg.send(fail_silently=True)
                except Exception, e :
                    print e

            return render_to_response('openauth/recovery_sent.html', {
                                                    'email' : email,
                                            }, context_instance=RequestContext(request))

        else :
            form = SignInUpForm(request.POST)
            if form.is_valid() :
                user = form.get_user()
                if not user :
                    if not UserEmail.objects.filter(email=form.cleaned_data['email'], is_confirmed=True).exists() :
                        user = create_user(request, form.cleaned_data['email'], form.cleaned_data['password'])
                    else :
                        form._errors[''] = "Password mismatch"

                if user :
                    user = authenticate(user=user)
                    login(request, user)

                    return HttpResponseRedirect(reverse('point:home'))
Пример #2
0
    def form_valid(self, form):
        mail = form.cleaned_data['email']
        ip = self.request.META['REMOTE_ADDR']

        user = User.objects.get(email=mail)
        model = PasswordRecovery(user=user,
                                 ip_addr=self.request.META['REMOTE_ADDR'])
        model.save()

        args = 'secret=%s&mail=%s' % (model.secret, mail)
        update_uri = reverse('password.update') + '?' + args
        absolute_update_uri = self.request.build_absolute_uri(update_uri)

        mailhelpers.utils.send_mail(settings.FORGOT_PASSWORD_MAIL_SUBJECT,
            [mail], settings.FORGOT_PASSWORD_MAIL_FROM,
            'mmm/password_recovery_mail.txt',
            'mmm/password_recovery_mail.html',
            params={'recovery': model,
                    'update_uri': absolute_update_uri})
        return super(RecoverPasswordView, self).form_valid(form)
Пример #3
0
    def form_valid(self, form):
        mail = form.cleaned_data['email']
        ip = self.request.META['REMOTE_ADDR']

        user = User.objects.get(email=mail)
        model = PasswordRecovery(user=user,
                                 ip_addr=self.request.META['REMOTE_ADDR'])
        model.save()

        args = 'secret=%s&mail=%s' % (model.secret, mail)
        update_uri = reverse('password.update') + '?' + args
        absolute_update_uri = self.request.build_absolute_uri(update_uri)

        mailhelpers.utils.send_mail(settings.FORGOT_PASSWORD_MAIL_SUBJECT,
                                    [mail],
                                    settings.FORGOT_PASSWORD_MAIL_FROM,
                                    'mmm/password_recovery_mail.txt',
                                    'mmm/password_recovery_mail.html',
                                    params={
                                        'recovery': model,
                                        'update_uri': absolute_update_uri
                                    })
        return super(RecoverPasswordView, self).form_valid(form)
Пример #4
0
def password_recovery_begin(request):
    context = RequestContext(request)
    
    success = False
    
    if not request.POST:
        form = PasswordRecoveryForm()
    else:
        form = PasswordRecoveryForm(request.POST)
        if form.is_valid() and form.user:
            token = get_random_string(length=50)
            
            recovery = PasswordRecovery(user=form.user, email=form.cleaned_data['email'], token=token)
            recovery.save()
            
            url = request.build_absolute_uri(reverse('account_password_recovery', args=[token]))
            
            message = render_to_string("registration/recoverymsg.txt", {'url' : url}, context_instance=context)
            
            send_branded_email("Récupération de compte", message, form.cleaned_data['email'])
            
            success = True

    return render(request, 'registration/recovery_begin.html', {'form' : form, 'success' : success})
Пример #5
0
def account_reset_request_by_mail(request):
    assert_post_parameters(request, ['emailAddress'])
    emailAddress = request.POST['emailAddress']
    user = assert_active_user(email=emailAddress)
    recovery = PasswordRecovery.create(user)
    try:
        send_mail(settings.REGISTRATION_RECOVERY_TITLE,
                  settings.REGISTRATION_RECOVERY_BODY + ' ' +
                  settings.FINDECO_BASE_URL + '/#confirm/' + str(recovery.key),
                  settings.EMAIL_HOST_USER,
                  [user.email])

        return json_response({'accountResetRequestByNameResponse': {}})
    except SMTPException:
        recovery.delete()
        raise