Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- class ForgotPasswordForm(Form):
- username = CharField(required=True)
- email = EmailField(required=True)
- def clean_username(self):
- username = self.cleaned_data['username']
- if User.objects.filter(username=username).count() == 0:
- raise ValidationError('user_not_found')
- return username
- def clean_email(self):
- email = self.cleaned_data['email']
- username = self.cleaned_data['username']
- if User.objects.filter(username=username, email=email).count() == 0:
- raise ValidationError('email_not_found')
- return email
- def save(self):
- username = self.cleaned_data["username"]
- email = self.cleaned_data["email"]
- user = User.objects.filter(username=username)[0]
- generated_password = ''.join([choice(ascii_letters + digits) for n in xrange(6)])
- user.set_password(generated_password)
- send_message = '''
- Hello %(username)s,
- We've received a request to reset your forgotten password.
- Now you can enter with the following generated password into our site:
- %(password)s
- You can change this generated password in "Settings"
- (http://zqservice.tk/user/settings/).
- Best wishes.
- ZQ Service Team
- http://zqservice.tk
- ''' % {'username': username, 'password': generated_password}
- send_mail('ZQ | Forgot your password?', send_message, email, ['zqservice@yandex.ru'], fail_silently=False)
- user.save()
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement