invite/views.py
def reset(request):
    '''users land here to reset their django user passwords'''
    if request.method == 'POST':
        reset_code = request.GET.get('reset_code')
        form = forms.ResetForm(request.POST)
        if form.is_valid():
            # get invitation object so we can deleted it afterwards
            pri = (PasswordResetInvitation
                   .objects
                   .get(activation_code=reset_code))
            # determine user from password reset invitation.
            user = User.objects.get(username=pri.username)
            user.set_password(form.cleaned_data['password'])
            user.save()
            pri.send_confirm(request=request)
            pri.delete()
            user = authenticate(
                username=pri.username,
                password=form.cleaned_data['password'],
            )
            if user is not None:
                return HttpResponseRedirect(reverse('invite:login'))
            else:
                return render(
                    request,
                    'invite/contact.html',
                    {
                        'reset_contact':  app_settings.INVITE_CONTACT_EMAIL,
                    }
                )
        else:
            return render(
                request,
                'invite/reset.html',
                {
                    'resetform': form,
                    'reset_code': reset_code,
                }
            )
    elif request.method == 'GET':
        # they come bearing a reset_code
        if 'reset_code' in request.GET.keys():
            try:
                pri = PasswordResetInvitation.objects.get(
                    activation_code=request.GET.get('reset_code'))
            except PasswordResetInvitation.DoesNotExist:
                return render(
                    request,
                    'invite/denied.html'
                )
            # set expiration for activation_code at the end of next day
            if (date.today() - pri.date_invited).days > 1:
                pri.delete()
                return render(
                    request,
                    'invite/denied.html'
                )
            else:
                return render(
                    request,
                    'invite/reset.html',
                    {
                        'reset_code': pri.activation_code,
                        'resetform': forms.ResetForm(),
                    }
                )
        # or an email address
        elif 'email' in request.GET.keys():
            return render(
                request,
                'invite/confirm_reset.html',
                {
                    'email': request.GET.get('email'),
                    'resetform': forms.ResetForm(),
                }
            )
        # otherwise tell em to scram
        else:
            return render(
                request,
                'invite/index.html',
                {
                    'resetform': forms.ResetForm(),
                }
            )
users land here to reset their django user passwords
users land here to reset their django user passwords
users land here to reset their django user passwords
def reset(request):
    if request.method == 'POST':
        reset_code = request.GET.get('reset_code')
        form = forms.ResetForm(request.POST)
        if form.is_valid():
            pri = (PasswordResetInvitation
                   .objects
                   .get(activation_code=reset_code))
            user = User.objects.get(username=pri.username)
            user.set_password(form.cleaned_data['password'])
            user.save()
            pri.send_confirm(request=request)
            pri.delete()
            user = authenticate(
                username=pri.username,
                password=form.cleaned_data['password'],
            )
            if user is not None:
                return HttpResponseRedirect(reverse('invite:login'))
            else:
                return render(
                    request,
                    'invite/contact.html',
                    {
                        'reset_contact':  app_settings.INVITE_CONTACT_EMAIL,
                    }
                )
        else:
            return render(
                request,
                'invite/reset.html',
                {
                    'resetform': form,
                    'reset_code': reset_code,
                }
            )
    elif request.method == 'GET':
        if 'reset_code' in request.GET.keys():
            try:
                pri = PasswordResetInvitation.objects.get(
                    activation_code=request.GET.get('reset_code'))
            except PasswordResetInvitation.DoesNotExist:
                return render(
                    request,
                    'invite/denied.html'
                )
            if (date.today() - pri.date_invited).days > 1:
                pri.delete()
                return render(
                    request,
                    'invite/denied.html'
                )
            else:
                return render(
                    request,
                    'invite/reset.html',
                    {
                        'reset_code': pri.activation_code,
                        'resetform': forms.ResetForm(),
                    }
                )
        elif 'email' in request.GET.keys():
            return render(
                request,
                'invite/confirm_reset.html',
                {
                    'email': request.GET.get('email'),
                    'resetform': forms.ResetForm(),
                }
            )
        else:
            return render(
                request,
                'invite/index.html',
                {
                    'resetform': forms.ResetForm(),
                }
            )
def reset ( request ) : if request . method == 'POST' : reset_code = request . GET . get ( 'reset_code' ) form = forms . ResetForm ( request . POST ) if form . is_valid ( ) : pri = ( PasswordResetInvitation . objects . get ( activation_code = reset_code ) ) user = User . objects . get ( username = pri . username ) user . set_password ( form . cleaned_data [ 'password' ] ) user . save ( ) pri . send_confirm ( request = request ) pri . delete ( ) user = authenticate ( username = pri . username , password = form . cleaned_data [ 'password' ] , ) if user is not None : return HttpResponseRedirect ( reverse ( 'invite:login' ) ) else : return render ( request , 'invite/contact.html' , { 'reset_contact' : app_settings . INVITE_CONTACT_EMAIL , } ) else : return render ( request , 'invite/reset.html' , { 'resetform' : form , 'reset_code' : reset_code , } ) elif request . method == 'GET' : if 'reset_code' in request . GET . keys ( ) : try : pri = PasswordResetInvitation . objects . get ( activation_code = request . GET . get ( 'reset_code' ) ) except PasswordResetInvitation . DoesNotExist : return render ( request , 'invite/denied.html' ) if ( date . today ( ) - pri . date_invited ) . days > 1 : pri . delete ( ) return render ( request , 'invite/denied.html' ) else : return render ( request , 'invite/reset.html' , { 'reset_code' : pri . activation_code , 'resetform' : forms . ResetForm ( ) , } ) elif 'email' in request . GET . keys ( ) : return render ( request , 'invite/confirm_reset.html' , { 'email' : request . GET . get ( 'email' ) , 'resetform' : forms . ResetForm ( ) , } ) else : return render ( request , 'invite/index.html' , { 'resetform' : forms . ResetForm ( ) , } )
users land here to reset their django user passwords
users land here to reset their django user passwords
'''users land here to reset their django user passwords''' # get invitation object so we can deleted it afterwards # determine user from password reset invitation. # they come bearing a reset_code # set expiration for activation_code at the end of next day # or an email address # otherwise tell em to scram
request