public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordData data)
    {
        if (ModelState.IsValid == false)
        {
            return(BadRequest());
        }

        var user = await UserManager().FindByEmailAsync(data.Email);

        if (user == null || !(await UserManager().IsEmailConfirmedAsync(user)))
        {
            return(StatusCode(400));
        }

        await UserManager().UpdateSecurityStampAsync(user);

        var token = await UserManager().GeneratePasswordResetTokenAsync(user);

        // Send a email with the token
        var uri = Url.ActionContext.HttpContext.Request.Scheme + "://"
                  + Url.ActionContext.HttpContext.Request.Host.Value
                  + Url.Action("ResetPasswordPage", new { token = token, email = data.Email });
        var subject          = "Admin password reset request.";
        var to               = new EmailAddress(user.Email);
        var plainTextContent = $"Hello {user.Username} \n\nReset your password with the following link:\n{uri}\n";
        var htmlContent      = $"Hello {user.Username},<br /><br />Reset your password with the following linke:<br />{uri}<br />";
        var subsitutions     = new Dictionary <string, string>
        {
            { ":subject", subject }
        };

        await _mailService.SendEmailAsync(to, subject, plainTextContent, htmlContent, subsitutions);

        return(Ok());
    }
예제 #2
0
        public JsonResult GetForgotPassword(ForgotPasswordData forgotPasswordData)
        {
            JsonResponse response = new JsonResponse();
            LoginData    lData    = new LoginData();

            DAL.Common common = new DAL.Common();

            var dt = lData.ForgotPassword(forgotPasswordData).Tables[0];

            response.Message = LWT.Common.LWTSafeTypes.SafeString(dt.Rows[0]["ErrMsg"]);

            if (response.Message.Contains("Your password will send to your mobile."))
            {
                string[] value = response.Message.Split('|');
                response.Message = value[0];
                var sms = "Your Password: "******"PR-MARKA754822_4H5EX");
                if (ret.ToString() == "0")
                {
                    common.ChargeText(forgotPasswordData.MobileNumber);
                    response.Message = value[0];
                }
                else
                {
                    response.Message = "Error detected while password is sending on your mobile number.";
                }
            }
            else if (response.Message.Contains("OTP"))
            {
                string[] value = response.Message.Split('|');
                var      sms   = "Your Security Code: " + value[1];
                response.Remarks = "OTP";

                //send security code via sms
                var ret = itexmo(forgotPasswordData.MobileNumber, sms, "PR-MARKA754822_4H5EX");
                if (ret.ToString() == "0")
                {
                    common.ChargeText(forgotPasswordData.MobileNumber);
                    response.Message = "To verify your request, please enter the security code sent on your mobile number.";
                }
                else
                {
                    response.Message = "Error detected while sending security code on your mobile number. Please click [Change Password] button again.";
                }
            }

            return(Json(new { data = response }, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        public DataSet ResetPassword(ForgotPasswordData mForgotPasswordData)
        {
            try
            {
                DataSet dataResult = new DataSet();
                dbconn = new DatabaseConnection();
                dbconn.DatabaseConn("ForgotPassword");

                if (dbconn.sqlConn.State == ConnectionState.Open)
                {
                    dbconn.sqlConn.Close();
                }
                dbconn.sqlConn.Open();
                dbconn.sqlComm.Parameters.Clear();
                dbconn.sqlComm.Parameters.AddWithValue("@MobileNumber", mForgotPasswordData.MobileNumber);
                dbconn.sqlComm.Parameters.AddWithValue("@Password", mForgotPasswordData.Password);
                dbconn.sqlComm.Parameters.AddWithValue("@ActionType", mForgotPasswordData.ActionType);
                dbconn.sqlComm.Parameters.AddWithValue("@SecurityCode", mForgotPasswordData.SecurityCode);

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = dbconn.sqlComm;
                da.Fill(dataResult);
                dbconn.sqlConn.Close();
                return(dataResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbconn.sqlConn.Close();
                dbconn.sqlConn.Dispose();
                SqlConnection.ClearPool(dbconn.sqlConn);
            }
        }