Exemplo n.º 1
0
        public bool RecoverPassword(RecoverPasswordDTO recoverPassword)
        {
            if (!(recoverPassword.NewPassword == recoverPassword.ConfirmNewPassword))
            {
                return(false);
            }

            if (!ValidateToken(recoverPassword.Token))
            {
                return(false);
            }

            var user = FindByCondition(x => x.Token == recoverPassword.Token).First();

            user.Password        = _hashService.Hash(recoverPassword.NewPassword);
            user.Token           = null;
            user.TokenExpiration = null;
            user.UpdatedAt       = DateTime.Now;

            try
            {
                Save();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public IActionResult RecoverPassword(RecoverPasswordDTO recoverPassword)
        {
            _loggerManager.Info("POST RecoverPassword is requested");

            if (ModelState.IsValid)
            {
                if (_userRepository.RecoverPassword(recoverPassword))
                {
                    var result = new ResultVM
                    {
                        Title = sharedResource.authRecoverPasswordSuccessTitle,
                        Text  = sharedResource.authRecoverPasswordSuccessDeccription
                    };

                    _loggerManager.Info("Password recovered successfully");

                    return(View("Success", result));
                }
                else
                {
                    _loggerManager.Error("Password recovery failed");

                    ModelState.AddModelError(string.Empty, sharedResource.authRecoverPasswordNewPasswordPlaceholder);
                }
            }
            else
            {
                _loggerManager.Warn("Password recovery values are invalid");
            }

            return(View());;
        }
Exemplo n.º 3
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordDTO recoverPasswordDTO)
        {
            ResultHandler output     = new ResultHandler();
            var           requestUrl = $"{BaseUrl}{apiUri}/RecoverPassword";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(requestUrl);
                HttpResponseMessage response = await client.PostAsJsonAsync(requestUrl, recoverPasswordDTO);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var result = await response.Content.ReadAsAsync <ResultHandler>();

                    if (result.IsErrorOccured)
                    {
                        return(View(new RecoverPasswordDTO {
                            IsErrorOccured = result.IsErrorOccured, Message = result.Message
                        }));
                    }
                    int?value = 0;


                    var details = JsonConvert.DeserializeObject <PersonalDetails>(result.Result.ToString());

                    output = IsLoggedIn(details.PositionId, details.EmailAddress, details.RoleId);
                    if (output.Message.Equals("SESSION_SET"))
                    {
                        value = output.Result as int?;
                        //if the session has been set do nothing, just proceed to get sermons
                    }
                    else
                    {
                        if (output.Result == null)
                        {
                            return(RedirectToAction("Login", "Accounts"));
                        }
                        else
                        {
                            value = output.Result as int?;
                        }
                    }

                    bool isRoleSet = false;
                    if (isRoleSet)
                    {
                    }

                    return(RedirectToAction("ChangePassword", "PasswordRecover", details.EmailAddress));
                }
                else
                {
                    return(View(new RecoverPasswordDTO {
                        IsErrorOccured = true, Message = "Something went Wrong"
                    }));
                };
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> RecoverPassword()
        {
            RecoverPasswordDTO recoverPasswordDTO = new RecoverPasswordDTO
            {
                IsErrorOccured = false
            };

            return(View(recoverPasswordDTO));
        }
Exemplo n.º 5
0
        public async Task RecoverPasswordAsync(RecoverPasswordDTO recoverPasswordDto)
        {
            var user = await _unitOfWork.UserRepository.SingleOrDefaultAsync(u => u.Id == recoverPasswordDto.Id);

            if (user == null)
            {
                throw new ApiException(HttpStatusCode.NotFound, "User was not found.");
            }

            user.Password = _hasher.HashPassword(recoverPasswordDto.NewPassword);

            await _unitOfWork.Complete();
        }
Exemplo n.º 6
0
        public RecoverPasswordResultDTO RecoverPassword(RecoverPasswordDTO dto)
        {
            var result = new RecoverPasswordResultDTO();

            try
            {
                this.SendPasswordResetImpl(dto);
            }
            catch (Exception exc)
            {
                result.Exception = exc.Message;
                return(result);
            }

            result.Successfully = true;
            return(result);
        }
Exemplo n.º 7
0
        private void SendPasswordResetImpl(RecoverPasswordDTO dto, string templateCode = "ResetPassword")
        {
            var user = this.service.GetUserByName(dto.Email);

            if (user == null)
            {
                throw new InvalidOperationException("User with such email isn't registered");
            }
            //// Language should be the one preferred by user
            var language = (user.UserSettings == null || user.UserSettings.Language == null) ? ConfigurationManager.AppSettings[ConfigFallbackLanguage]
                : user.UserSettings.Language.Id;
            var ticket = this.securityService.CreateTicketForUser(user);

            if (ticket != null)
            {
                var url  = "resetpassword".CreateFullUrl(Request);
                var link = this.securityService.EncodeTicket(url, new Guid(ticket));
                this.SendResetPasswordNotification(user, language, link, templateCode);
            }
        }
Exemplo n.º 8
0
        public ActionResult RecoverPassword([FromBody] RecoverPasswordDTO recoverPasswordDTO)
        {
            User user = _eyadtakDbContext.Users.FirstOrDefault(s => s.UserEmail == recoverPasswordDTO.UserEmail);

            if (user == null)
            {
                return(Ok(new { message = "This Email does not Exsist", ErrorHappen = true }));
            }
            if (user.RecoveryCode != recoverPasswordDTO.RecoveryCode)
            {
                return(Ok(new { message = "This Code is not Correct", ErrorHappen = true }));
            }
            if (recoverPasswordDTO.NewPassword.Length < 5)
            {
                return(Ok(new { message = "Password Lenght can't be less than 5 char", ErrorHappen = true }));
            }
            user.Password     = Encription.Encrypt(recoverPasswordDTO.NewPassword, "SecretCode_hamed");
            user.RecoveryCode = -1;
            _eyadtakDbContext.Update(user);
            _eyadtakDbContext.SaveChanges();
            return(Ok(new { message = "Password Changed Successfully", ErrorHappen = false }));
        }
Exemplo n.º 9
0
 public void SendPasswordResetByAdmin(RecoverPasswordDTO dto)
 {
     this.SendPasswordResetImpl(dto, "ResetPasswordByAdmin");
 }
Exemplo n.º 10
0
        public IActionResult RecoverPassword([FromServices] IUserRepository repository, [FromBody] RecoverPasswordDTO newUser)
        {
            try
            {
                User user = repository.GetUser(newUser.Email);
                if (user == null)
                {
                    return(NotFound(new { message = "E-mail not found" }));
                }

                return(Ok(user.Password));
            }
            catch (Exception ex)
            {
                return(BadRequest(new
                {
                    message = "An error occurred while trying to recover data"
                }));
            }
        }
Exemplo n.º 11
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordDTO recoverPasswordDto)
        {
            await _userService.RecoverPasswordAsync(recoverPasswordDto);

            return(Ok());
        }