コード例 #1
0
        public async Task <IActionResult> ResetPassword([FromBody] ResetPassword objModel, string recoveryToken)
        {
            DBResponse  objResponse    = null;
            UserDetails objUserDetails = new UserDetails();
            TokenBucket objTokenBucket = new TokenBucket();
            UserInfo    objUserEntity  = new UserInfo();

            try
            {
                if (!string.IsNullOrEmpty(objModel.Password))
                {
                    objTokenBucket = objUserDetails.GetToken(recoveryToken);
                    UserInfo obj = objUserDetails.GetUserInfo(new UserInfo {
                        Username = objTokenBucket.Username
                    });
                    if (objTokenBucket.ValidFrom <= DateTime.Now && objTokenBucket.ValidTo >= DateTime.Now && (!objTokenBucket.IsUsed) && (objTokenBucket.IsActive))
                    {
                        objUserEntity.Email    = obj.Email;
                        objUserEntity.Username = obj.Username;
                        objUserEntity.Password = Constants.GetMD5Hash(objModel.Password);// objModel.PasswordMD5;
                        objResponse            = objUserDetails.UpdateUserPassword(objUserEntity);
                        if (objResponse.Result)
                        {
                            objUserDetails.ExpireToken(recoveryToken);
                            objResponse.Message = "Your password reset successfully.";
                        }
                        else
                        {
                            objResponse.Message = "Your password should not be same as last 3 password.";
                        }
                    }
                    else
                    {
                        objResponse.Message = "Token request is expired!.";
                    }
                }
                else
                {
                    objResponse.Message = "some error occurred.";
                }
            }
            catch (Exception ex)
            {
                objResponse.Message = ex.Message;
                CLogger.WriteLog(ProjectSource.WebApi, ELogLevel.ERROR, "ERROR ocurred in  Account Controller  while calling ResetPassword Action, Ex.: " + ex.Message);
            }
            return(Ok(new { Response = objResponse }));
        }