Example #1
0
def password_reset_form(request, verification_key):
    """
    Password reset form
    """
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('home'))
    user_profile = get_object_or_404(UserProfile,
                                     verification_key=verification_key)
    naive_date = user_profile.key_expires.replace(tzinfo=None)
    if naive_date < datetime.datetime.today():
        return render_to_response('expired.html',
                                  context_instance=RequestContext(request))

    user_account = user_profile.user
    temp_password = create_key(user_account.username, 2)
    user_account.set_password(temp_password)
    user_account.save()
    user = authenticate(username=user_account.username, password=temp_password)
    if user is not None:
        if user.is_active:
            login(request, user)
        else:
            return HttpResponse("This account is inactive.")
    #remove reset key
    user_profile.verification_key = ""
    user_profile.save()
    reset_form = PasswordResetForm()
    return render_to_response('password_reset_form.html',
                              context_instance=RequestContext(
            request, {"reset_form": reset_form}))
Example #2
0
 def send_reset_link(self):
     response = reply_object()
     user = User.objects.get(email=self.cleaned_data["email"])
     if not user.is_active:
         response["code"] = settings.APP_CODE["SERVER MESSAGE"]
         response["server_message"] = "This account is inactive. Please contact site administrator"
         return response
     profile = user.get_profile()
     key_object = create_key(user.username, 2)
     profile.verification_key = key_object["key"]
     profile.key_expires = key_object["expiry"]
     send_password_reset_email(user.email, key_object["key"])
     profile.save()
     response["code"] = settings.APP_CODE["CALLBACK"]
     return response
Example #3
0
def create_user_profile(sender, instance, created, **kwargs):
    """
    Signal for creating a new profile and setting activation key
    """

    if created:
        profile = UserProfile.objects.create(user=instance)

        if settings.EMAIL_VERIFICATION_REQUIRED:
            key_object = create_key(instance.username, 2)
            profile.verification_key = key_object["key"]
            profile.key_expires = key_object["expiry"]
            send_activation_email(instance.email, key_object["key"])

        profile.save()
    return