def create(self, validated_data): is_valid_password = UserModel.validate_password_complexity( validated_data['password']) if not is_valid_password: raise WsRestNonFieldException( UserModel.INVALID_PASSWORD_COMPLEXITY_ERROR_MESSAGE) try: user = UserModel.objects.create( username=validated_data['username'], #Right now your username is your email, if this changes we need to change this email=validated_data['username'], first_name=validated_data['first_name'], last_name=validated_data['last_name']) user.set_password(validated_data['password']) user.email_registration_code = RandomHelper.get_cryptographic_uuid( ) user.save() #Send verification email send_emails_for_user_signup.delay(unicode(user.uuid)) return user except IntegrityError as ie: raise WsRestNonFieldException( 'A user with this username already exists!') except Exception as e: raise WsRestNonFieldException(e.message) return None
def setUp(self): """ Set up this test case so that user_1 has a forgot password token associated with their user. :return: None """ super(TestVerifyForgotPasswordView, self).setUp() user = self.get_user(user="******") user.forgot_password_code = RandomHelper.get_cryptographic_uuid() user.forgot_password_date = timezone.now() self._email_token = user.forgot_password_code user.save()
def validate(self, attrs): email_address = attrs.get('email_address') user = get_object_or_404(UserModel, email=email_address) # Start the forgot password reset process user.forgot_password_code = RandomHelper.get_cryptographic_uuid() user.forgot_password_date = timezone.now() user.save() # Send the forgot password email smtp_helper = SmtpEmailHelper.instance() smtp_helper.send_forgot_password_email(user.email, str(user.forgot_password_code), user.first_name, str(user.uuid)) return attrs
def validate(self, attrs): user_uuid = attrs['user_uuid'] user = UserModel.objects.filter(uuid=user_uuid).first() if user: #Reset the verification code user.email_registration_code = RandomHelper.get_cryptographic_uuid( ) user.save() # Send verification email send_emails_for_user_signup.delay(user_uuid=user_uuid) else: raise WsRestNonFieldException('No user with that uuid found.') return attrs