Esempio n. 1
0
        public ActionResult GetUserCodeExpireTime(UserResetPwdInfo info)
        {
            this._logger.LogDebug("GetUserCodeExpireTime");
            UserResetPwdInfo userResetPwdInfo = _oracleUserRepo.GetUserResetPwdInfo(info.UserName);

            return(Ok(userResetPwdInfo.VerifyCodeExpiredTime));
        }
Esempio n. 2
0
        public ActionResult GetUserEmail(UserResetPwdInfo info)
        {
            this._logger.LogDebug("GetUserEmail");
            UserResetPwdInfo userResetPwdInfo = _oracleUserRepo.GetUserResetPwdInfo(info.UserName);

            return(Ok(userResetPwdInfo.EmailAddr));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            _logger.LogInformation("Post from page");
            if (!ModelState.IsValid)
            {
                _logger.LogInformation("ModelState is not valid.");
                return(Page());
            }

            ApiResult result = new ApiResult();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Constants.API_BASE_URL);
                UserResetPwdInfo userResetPwdInfo = userResetPwdModel.ToInfo();
                _logger.LogInformation("Call DoResetPwd.");
                using (var response = await client.PostAsJsonAsync <UserResetPwdInfo>("DoResetPwd", userResetPwdInfo))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    result = JsonConvert.DeserializeObject <ApiResult>(apiResponse);
                    if (result.resultCode == ResultCode.SUCCESS)
                    {
                        HttpContext.Session.Set("_msg", Encoding.ASCII.GetBytes("Your Oracle Database Account Password has been changed!"));
                        HttpContext.Session.Set("_username", Encoding.ASCII.GetBytes(""));
                        return(RedirectToPage("./Result"));
                    }
                }
            }
            ViewData["Error"] = result.errMsg;
            return(Page());
        }
Esempio n. 4
0
        private ApiResult IsValidRequest(UserResetPwdInfo info)
        {
            ApiResult        result   = new ApiResult();
            UserResetPwdInfo infoInDB = _oracleUserRepo.GetUserResetPwdInfo(info.UserName);

            if (infoInDB.VerificationCode == info.VerificationCode)
            {
                DateTime now     = DateTime.Now;
                DateTime expired = DateTime.Parse(infoInDB.VerifyCodeExpiredTime);
                if (now < expired)
                {
                    result.resultCode = ResultCode.SUCCESS;
                    return(result);
                }
                else
                {
                    result.resultCode = ResultCode.VERIFICATION_CODE_EXPIRED;
                    result.errMsg     = "The entered verification code has already expired, please reset your oracle database password again.";
                    return(result);
                }
            }
            else
            {
                result.resultCode = ResultCode.INVALID_VERIFICATION_CODE;
                result.errMsg     = "The verification code is incorrect, please check your verification email and try again.";
            }
            return(result);
        }
        public async Task <IActionResult> OnGet()
        {
            userVerifyModel = new UserVerifyModel();
            byte[] bytes;
            HttpContext.Session.TryGetValue("_username", out bytes);
            if (bytes != null)
            {
                userVerifyModel.UserName = Encoding.ASCII.GetString(bytes);
            }
            else
            {
                HttpContext.Session.Set("_msg", Encoding.ASCII.GetBytes("You have to start with Password Reset Service Landing Page."));
                return(RedirectToPage("./Result"));
            }

            ApiResult result = new ApiResult();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Constants.API_BASE_URL);
                UserResetPwdInfo info = new UserResetPwdInfo();
                info.UserName = userVerifyModel.UserName;
                using (var response = await client.PostAsJsonAsync <UserResetPwdInfo>("GetUserEmail", info))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    userVerifyModel.EmailAddr = apiResponse;
                }
            }
            return(Page());
        }
Esempio n. 6
0
        public ActionResult VerifyCode(UserVerifyInfo vInfo)
        {
            this._logger.LogDebug("VerifyCode");
            UserResetPwdInfo info = new UserResetPwdInfo();

            info.UserName         = vInfo.UserName;
            info.EmailAddr        = vInfo.EmailAddr;
            info.VerificationCode = vInfo.VerifyCode;
            return(Ok(IsValidRequest(info)));
        }
Esempio n. 7
0
        public UserResetPwdInfo ToInfo()
        {
            UserResetPwdInfo urpi = new UserResetPwdInfo();

            urpi.UserName              = this.UserName;
            urpi.EmailAddr             = this.EmailAddr;
            urpi.OraclePassword        = this.OraclePassword;
            urpi.VerificationCode      = this.VerificationCode;
            urpi.VerifyCodeExpiredTime = this.VerifyCodeExpiredTimeStr;
            return(urpi);
        }
Esempio n. 8
0
        public bool AddVerificationInfo(UserResetPwdInfo userResetPwdInfo)
        {
            try
            {
                var dbConnection = this.GetConnection();
                if (dbConnection.State == System.Data.ConnectionState.Closed)
                {
                    dbConnection.Open();
                    _logger.LogInformation("oracle connection opened.");
                }
                if (dbConnection.State == System.Data.ConnectionState.Open)
                {
                    using (OracleCommand cmd = dbConnection.CreateCommand())
                    {
                        try
                        {
                            cmd.CommandText = @" UPDATE oracle_pwd_reset_users 
                                                 SET RECOVERYCODE = :recoveryCode,
                                                     EXPIRETIME = :expiryTime
                                                 WHERE USERNAME = :username
                              ";

                            OracleParameter[] parameters = new OracleParameter[] {
                                new OracleParameter("recoveryCode", userResetPwdInfo.VerificationCode),
                                new OracleParameter("expiryTime", userResetPwdInfo.VerifyCodeExpiredTime),
                                new OracleParameter("username", userResetPwdInfo.UserName)
                            };

                            cmd.Parameters.AddRange(parameters);
                            int r = cmd.ExecuteNonQuery();
                            dbConnection.Close();
                            _logger.LogInformation("oracle connection closed.");
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError(ex, ex.Message, null);
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message, null);
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
        private bool SendVerifyCode(UserEmailInfo usernameEmail)
        {
            string   verifyCode  = RandomString.GenerateRandomString(8);
            DateTime expiredTime = DateTime.Now.AddMinutes(Constants.VERIFY_CODE_VALID_MINS);
            bool     result      = SendEmail(usernameEmail, verifyCode, expiredTime.ToString());

            if (result)
            {
                UserResetPwdInfo urpi = new UserResetPwdInfo();
                urpi.UserName              = usernameEmail.UserName;
                urpi.EmailAddr             = usernameEmail.EmailAddr;
                urpi.VerificationCode      = verifyCode;
                urpi.VerifyCodeExpiredTime = expiredTime.ToString();
                _oracleUserRepo.AddVerificationInfo(urpi);
            }
            return(result);
        }
Esempio n. 10
0
        public UserResetPwdInfo GetUserResetPwdInfo(string username)
        {
            UserResetPwdInfo userResetPwdInfo = new UserResetPwdInfo();

            try
            {
                var dbConnection = this.GetConnection();

                if (dbConnection.State == System.Data.ConnectionState.Closed)
                {
                    dbConnection.Open();
                    _logger.LogInformation("oracle connection opened.");
                }
                if (dbConnection.State == System.Data.ConnectionState.Open)
                {
                    using (OracleCommand cmd = dbConnection.CreateCommand())
                    {
                        cmd.CommandText = "SELECT * FROM " + "oracle_pwd_reset_users WHERE username="******"'" + username + "'";
                        OracleDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            userResetPwdInfo.UserName              = reader.IsDBNull(1)? "": reader.GetString(1);
                            userResetPwdInfo.EmailAddr             = reader.GetString(2);
                            userResetPwdInfo.VerificationCode      = reader.IsDBNull(3) ? "": reader.GetString(3);
                            userResetPwdInfo.VerifyCodeExpiredTime = reader.IsDBNull(4)? "": reader.GetString(4);
                            break;
                        }
                        reader.Dispose();
                        dbConnection.Close();
                        _logger.LogInformation("oracle connection closed.");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message, null);
                return(null);
            }
            return(userResetPwdInfo);
        }
Esempio n. 11
0
        public ActionResult DoResetPwd(UserResetPwdInfo info)
        {
            this._logger.LogDebug("DoResetPwd");
            ApiResult result = new ApiResult();

            //result = IsValidRequest(info);
            if (result.resultCode == ResultCode.SUCCESS)
            {
                if (_oracleUserRepo.ChangeOracleUserPassword(info.UserName, info.OraclePassword))
                {
                    result.resultCode = ResultCode.SUCCESS;
                    result.errMsg     = "success";
                }
                else
                {
                    result.resultCode = ResultCode.SET_USER_PASSWORD_FAILED;
                    result.errMsg     = "Set user password failed";
                }
            }
            AddInfoToAudit(info.UserName, result, ACTION.RESET_PASSWORD.ToString());
            return(Ok(result));
        }