Example #1
0
        public ActionResult ForgetPassword([FromBody] ForgetPasswordRequest request)
        {
            var control  = userRepo.FirstOrDefaultBy(x => x.Username == request.Username && x.Email == request.Email);
            var response = new BaseResponse <bool>();

            if (control == null)
            {
                response.SetMessage("Sistemde kayıtlı böyle bir kullanıcı bulunamadı.");
                return(Ok(response));
            }

            Random rnd               = new Random();
            int    passwordKey       = rnd.Next(10000000, 99999999);
            string passwordKeyString = Convert.ToString(passwordKey);

            passwordKeyString = new Cryptography().EncryptString(passwordKeyString);

            var forgotPassword = new ForgatPassword();

            forgotPassword.UserID = control.Id;
            forgotPassword.Key    = passwordKeyString;
            forgatPasswordRepo.Add(forgotPassword);


            var resetLink = "http://localhost:5001/Login/RePassword?Code=" + HttpUtility.UrlEncode(passwordKeyString);


            MailManager.Send(resetLink, control.Email);

            return(Ok(response));
        }
Example #2
0
        public ActionResult ForgetPassword([FromBody] ForgetPasswordRequest request)
        {
            var    control = userRepo.FirstOrDefaultBy(x => x.Username == request.Username && x.Email == request.Email);
            string Email   = request.Email;

            var response = new BaseResponse <bool>();

            if (control == null)
            {
                response.SetMessage("Sistemde kayıtlı böyle bir kullanıcı bulunamadı.");
                return(Ok(response));
            }
            var forgotPassword = new ForgatPassword();

            forgotPassword.UserID = control.Id;
            forgotPassword.Key    = Cryptography.GenerateKey(32);
            forgatPasswordRepo.Add(forgotPassword);

            var Recipients = new Dictionary <string, string>();

            Recipients.Add("recipient.Email", Email);
            Recipients.Add("recipient.FullName", control.FirstName + " " + control.LastName);
            Recipients.Add("recipient.IPAddress", accessor.HttpContext.Connection.RemoteIpAddress.ToString());
            Recipients.Add("recipient.Date", DateTime.Now.ToString("dd MMM yyyy, dddd HH:mm"));
            Recipients.Add("recipient.Link", $"{accessor.HttpContext.Request.Scheme}://{accessor.HttpContext.Request.Host}/Login/RePassword?q=" + forgotPassword.Key);

            mailManager.Send("Şifrenizi Sıfırlayın", Email, "forgot-password-en.html", Recipients, null);

            response.Message = "Email Gönderildi";

            return(Ok(response));
        }