예제 #1
0
        public ActionResult <ForgotPasswordResponseModel> ForgotPassword([FromBody] ForgotPasswordMobileInputModel data)
        {
            try
            {
                ForgotPasswordBL forPasswordBL = new ForgotPasswordBL(DbContext);

                var url    = AppSettings.URLForgotPassword;
                var result = forPasswordBL.SendURL(data.UserName, url);

                if (result.Response)
                {
                    var    locationHtml = AppSettings.TemplatePath + "EmailResetPassword.html";
                    string content      = System.IO.File.ReadAllText(locationHtml);

                    content = content.Replace("$BASE_URL", AppSettings.BaseURL);
                    content = content.Replace("$ForgetPassword_URL", AppSettings.BaseURL + AppSettings.URLForgotPassword + result.data.ID);


                    MailMessage message = new MailMessage();

                    message.To.Add(result.data.UserName);
                    message.Body       = content;
                    message.Subject    = "Forgot Password";
                    message.From       = new MailAddress(AppSettings.EmailConfig.FromAddress);
                    message.IsBodyHtml = true;


                    EmailSenderEngine emailEngine  = new EmailSenderEngine();
                    string            configOnJSON = JsonConvert.SerializeObject(AppSettings.EmailConfig);

                    emailEngine.SendEmail(message, configOnJSON);
                }

                return(result);
            }
            catch (Exception ex)
            {
                ForgotPasswordResponseModel logres = new ForgotPasswordResponseModel();
                logres.Message  = ex.Message;
                logres.Response = false;

                return(logres);
            }
        }
예제 #2
0
        public ActionResult <ValidationForgotPasswodResponseModel> CheckValidIDForgotPassword([FromBody] ValidationForgotPasswordInputModel data)
        {
            try
            {
                ForgotPasswordBL forPasswordBL = new ForgotPasswordBL(DbContext);

                var url    = AppSettings.URLForgotPassword;
                var result = forPasswordBL.CheckValidate(data);

                if (result.IsStillUse)
                {
                    ValidationForgotPasswodResponseModel response = new ValidationForgotPasswodResponseModel();

                    response.data     = result;
                    response.Response = true;
                    response.Message  = "Valid";

                    return(response);
                }
                else
                {
                    ValidationForgotPasswodResponseModel response = new ValidationForgotPasswodResponseModel();

                    response.Response = false;
                    response.Message  = "Waktu anda meminta reset password sudah tidak berlaku, lakukan permintaan ulang";

                    return(response);
                }
            }
            catch (Exception ex)
            {
                ValidationForgotPasswodResponseModel logres = new ValidationForgotPasswodResponseModel();
                logres.Message  = ex.Message;
                logres.Response = false;

                return(logres);
            }
        }