def ask_reset_password(request): if request.method == 'POST': form = AskResetPasswordForm(request.POST) if form.is_valid(): data = form.cleaned_data user = User.objects.get(email=data['email']) profile = Profile.objects.get(user=user) # Set hash and date profile.password_reset_token = get_random_hash() profile.password_reset_token_date = datetime_now_utc() profile.save() logger.debug("Reset password in: " +\ reverse(reset_password, args=[user.id, profile.password_reset_token])) # Send email messages.success(request, "An email has been sent to your account") return redirect("/") else: form = AskResetPasswordForm() context = { 'form': form, } return render_to_response('userprofile/ask-reset-password.html', context, context_instance=RequestContext(request))
def user_post_save(sender, instance, created, **kwargs): """Create a user profile when a new user account is created""" if created: p = Profile() p.user = instance p.activation_token = get_random_hash() # set the level to 0s (For the first user when syncdb catch exception) try: p.level = Level.objects.get(level_number=0) except ObjectDoesNotExist: pass p.save()
def test_user_whrong_activation(self): """ Tests if the user activation works worng """ user = User() user.username = "******" user.save() profile = Profile.objects.get(user=user) self.assertFalse(profile.activated) user_id = user.id user_token = get_random_hash() url = reverse("userprofile-activate", args=(user_id, user_token)) self.client.get(url) profile = Profile.objects.get(user=user) self.assertFalse(profile.activated)