Пример #1
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // Add debug log
                    LogService.Debug($"Getting the forgot password page (HTTP_POST). SessionId:{SessionId}");

                    // Check the incoming email address
                    var user = UserManager.FindByEmail(model.Email);

                    if (user == null)
                    {
                        model.HasErrors = true;
                        model.Result    = "Kayıtlı e-posta bulunamadı!";

                        // Add debug log
                        LogService.Debug($"Could not found the user. Email:{model.Email}; SessionId:{SessionId}");
                    }
                    else
                    {
                        // Add debug log
                        LogService.Debug($"Found the user.UserId:{user.Id}; Email:{user.Email}; SessionId:{SessionId}");

                        // Creat the password reset link
                        var token = UserManager.GeneratePasswordResetToken(user.Id);

                        // Create the reset password notification view model
                        var notificationViewModel = new ResetPasswordNotificationViewModel()
                        {
                            SiteRoot      = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, "/"),
                            User          = user,
                            ResetToken    = HttpUtility.UrlEncode(token),
                            SecurityStamp = user.SecurityStamp
                        };

                        #region [ Reset password email ]

                        //var notificationBody = ViewToString("~/Views/Templates/Email/PasswordReset.cshtml", notificationViewModel);
                        //var activationEmailResponse = _mailgunService.Send(new EmailMessage()
                        //{
                        //    ChannelId = "Mailgun",
                        //    FromName = "FreelanceFrom",
                        //    FromAddress = "*****@*****.**",
                        //    Subject = "Şifrenizi sıfırlayın",
                        //    Body = notificationBody,
                        //    IsHtml = true,
                        //    Deliveries = new List<Delivery>()
                        //{
                        //    new Delivery()
                        //    {
                        //        RecipientType = Common.RecipientType.Primary,
                        //        RecipientName = user.Firstname + " " + user.Lastname,
                        //        RecipientAddress = user.Email
                        //    }
                        //}
                        //});

                        //// Create the notification
                        //var notificationBody = ViewToString("~/Views/Templates/Email/PasswordReset.cshtml", notificationViewModel);

                        //// Send confirmation email
                        //var notificationResponse = notificationServiceClient.SendNotification(new NotificationCommand()
                        //{
                        //    appkey = ConfigurationManager.AppSettings["AppKey"],
                        //    env = ConfigurationManager.AppSettings["Environment"],
                        //    ut = UserToken,
                        //    sid = SessionId,
                        //    uid = UserId,
                        //    t = 1, // Email
                        //    fn = "Zippsi",
                        //    fa = "*****@*****.**",
                        //    s = "Şifre güncelleme",
                        //    b = notificationBody,
                        //    rt = 1,
                        //    rcp = new List<RecipientCommand>()
                        //    {
                        //        new RecipientCommand()
                        //        {
                        //            an = user.Firstname + " " + user.Lastname,
                        //            adr = user.Email
                        //        }
                        //    }
                        //});

                        //if (notificationResponse.Type != ServiceResponseTypes.Success)
                        //{
                        //    // Add debug log
                        //    LogService.Debug($"Could not sent password recovery mail sent.UserId:{user.Id}; Email:{user.Email}; SessionId:{SessionId}; Errors:{String.Join(",", notificationResponse.Errors)}");

                        //    model.HasErrors = true;
                        //    model.Result = "";
                        //}

                        //// Add debug log
                        //LogService.Debug($"Password recovery mail sent.UserId:{user.Id}; Email:{user.Email}; SessionId:{SessionId}");

                        #endregion

                        model.Result = "Şifre sıfırlama e-postası gönderildi!";
                    }
                }
            }

            catch (Exception ex)
            {
                LogService.Error("Error to change password", ex.Message, ex.InnerException);
            }
            return(View(model));
        }
Пример #2
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            LogService.Debug($"Getting the forgot password page (HTTP_POST). SessionId:{SessionId}");

            // Check the incoming email address
            var user = UserManager.FindByEmail(model.Email);

            if (user == null)
            {
                model.HasErrors = true;
                model.Result    = "Email not found!";

                // Add debug log
                LogService.Debug($"Could not found the user. Email:{model.Email}; SessionId:{SessionId}");
            }
            else
            {
                // Add debug log
                LogService.Debug($"Found the user.UserId:{user.Id}; Email:{user.Email}; SessionId:{SessionId}");

                // Creat the password reset link
                var token = UserManager.GeneratePasswordResetToken(user.Id);

                // Create the reset password notification view model
                var notificationViewModel = new ResetPasswordNotificationViewModel()
                {
                    SiteRoot      = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, "/"),
                    User          = user,
                    ResetToken    = HttpUtility.UrlEncode(token),
                    SecurityStamp = user.SecurityStamp
                };

                #region [ Reset password email ]

                //// Create the notification
                //var notificationBody = ViewToString("~/Views/Templates/Email/PasswordReset.cshtml", notificationViewModel);

                //// Send confirmation email
                //var notificationResponse = notificationServiceClient.SendNotification(new NotificationCommand()
                //{
                //    appkey = ConfigurationManager.AppSettings["AppKey"],
                //    env = ConfigurationManager.AppSettings["Environment"],
                //    ut = UserToken,
                //    sid = SessionId,
                //    uid = UserId,
                //    t = 1, // Email
                //    fn = "Zippsi",
                //    fa = "*****@*****.**",
                //    s = "Şifre güncelleme",
                //    b = notificationBody,
                //    rt = 1,
                //    rcp = new List<RecipientCommand>()
                //    {
                //        new RecipientCommand()
                //        {
                //            an = user.Firstname + " " + user.Lastname,
                //            adr = user.Email
                //        }
                //    }
                //});

                //if (notificationResponse.Type != ServiceResponseTypes.Success)
                //{
                //    // Add debug log
                //    LogService.Debug($"Could not sent password recovery mail sent.UserId:{user.Id}; Email:{user.Email}; SessionId:{SessionId}; Errors:{String.Join(",", notificationResponse.Errors)}");

                //    model.HasErrors = true;
                //    model.Result = "";
                //}

                //// Add debug log
                //LogService.Debug($"Password recovery mail sent.UserId:{user.Id}; Email:{user.Email}; SessionId:{SessionId}");

                #endregion

                model.Result = "Password recovery email sent!";
            }

            return(View(model));
        }