Esempio n. 1
0
        public bool ChangePassword(UserRequestChangePasswordViewModel user)
        {
            ValidationService.ValidEmail(user.Email);
            ValidationService.ValidPassword(user.Password, user.PasswordConfirm);

            User _user = repository.GetByEmailAndCode(user.Email, user.Code);

            if (_user == null)
            {
                throw new ApiException("Email/Code not found", HttpStatusCode.NotFound);
            }

            _user.Code     = string.Empty;
            _user.Password = UtilsService.EncryptPassword(user.Password);
            repository.Update(_user);

            emailSender.SendEmailAsync(new EmailViewModel(new string[] { _user.Email }, "Change Password - Template", "PASSWORD-CHANGED"), new string[] { _user.Name });

            return(true);
        }
Esempio n. 2
0
        public UserResponseAuthenticateViewModel Authenticate(UserRequestAuthenticateViewModel user)
        {
            User _user = repository.GetByEmailAndPassword(user.Email, UtilsService.EncryptPassword(user.Password));

            if (_user == null)
            {
                throw new ApiException("Email/Password not found", HttpStatusCode.NotFound);
            }

            if (!_user.IsAuthorised)
            {
                throw new ApiException("Your account is not activate yet.", HttpStatusCode.NotFound);
            }

            string token = tokenService.GenerateToken(mapper.Map <ContextUserViewModel>(_user));

            UserResponseAuthenticateViewModel _userResponse = mapper.Map <UserResponseAuthenticateViewModel>(_user);

            _userResponse.Token = token;

            return(_userResponse);
        }