コード例 #1
0
ファイル: views.py プロジェクト: koblas/notewave
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
ファイル: views.py プロジェクト: justelex/Findeco
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