/// <summary>
        /// Получает ChangePasswordEmailModel
        /// </summary>
        /// <param name="Email"></param>
        /// <param name="NewPassword"></param>
        /// <returns></returns>
        public static RestorePasswordEmailModel GetRestorePasswordEmailModel(string Email, string NewPassword)
        {
            RestorePasswordEmailModel toReturn = new RestorePasswordEmailModel();

            toReturn.Caption = "Restore password";
            toReturn.MailTo.Add(Email);
            toReturn.Password = NewPassword;
            return(toReturn);
        }
Example #2
0
        /// <summary>
        /// Отсылает пользователю новый сгенерированный пароль по Email,
        /// если, конечно он зарегестрирован в системе
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ServiceResponce RestorePassword(RestorePasswordModel model)
        {
            IList <User> users = _userRep.FindAllByCredentails(model.Email, model.Phone);

            if (users == null)
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "user doesn't exist"));
            }

            /*       if (users.Count > 1)
             *     {
             *         return ServiceResponce
             *             .FromFailed()
             *             .Add("error", "user doesn't exist");
             *     } */

            User user = new User();

            if (users.Count == 1)
            {
                foreach (User u in users)
                {
                    user = u;
                }
            }

            string Password = PasswordService.GeneratePasswordString();

            user.Password = PasswordService.GeneratePasswordHash(Password);
            _userRep.Save(user);

            new Thread(send =>
            {
                RestorePasswordEmailModel RestorePasswordEmailModel = RestorePasswordEmailModelHelper.GetRestorePasswordEmailModel(user.UserName, Password);
                string RestoreText = _templateServ
                                     .Run("Emails/RestorePassword", typeof(RestorePasswordEmailModel), RestorePasswordEmailModel);
                if (!EmailService.SendMail(RestorePasswordEmailModel, RestoreText))
                {
                    user.UserStatuses.Description = "Restore password Email was not delivered";
                    user.UserStatuses.UpdateTime  = DateTime.Now;
                }
                else
                {
                    user.UserStatuses.Description = "Restore password Email was delivered at " + DateTime.Now;
                    user.UserStatuses.UpdateTime  = DateTime.Now;
                }
            }).Start();

            return(ServiceResponce.FromSuccess());
        }