public Status<bool> ForgotPassword(EmailForgotPasswordModel model)
        {
            //create message
            var message = new MailMessage { Subject = "Your password has been reset" };
            message.To.Add(model.To);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "ForgotPassword");

            //send it
            return this.SendMessage(message);
        }
Exemple #2
0
        public Status <bool> ForgotPassword(EmailForgotPasswordModel model)
        {
            //create message
            var message = new MailMessage {
                Subject = "Your password has been reset"
            };

            message.To.Add(model.To);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "ForgotPassword");

            //send it
            return(this.SendMessage(message));
        }
 public Status<bool> ForgotPassword(EmailForgotPasswordModel model)
 {
     return SendMail(model, "account/forgotpassword");
 }
        /// <summary>
        /// Resets the password of the specified user
        /// </summary>
        /// <param name="email">user's email</param>
        /// <returns></returns>
        public Status<User> ResetPassword(string email)
        {
            using (var context = new RentlerContext())
            {
                try
                {
                    var user = (from u in context.Users
                                where !u.IsDeleted && u.Email == email
                                select u).FirstOrDefault();

                    if (user == null)
                        return Status.ValidationError<User>(null, "Email", "No user with this email exists");

                    // generate a random password 8 char long
                    string newPassword = FormsAuthentication
                        .HashPasswordForStoringInConfigFile(
                            DateTime.Now.ToString() + user.Username,
                            "SHA1")
                        .Substring(0, 8);

                    // hash the random password and update user with it
                    user.PasswordHash = FormsAuthentication
                        .HashPasswordForStoringInConfigFile(newPassword, "SHA1");
                    context.SaveChanges();

                    EmailForgotPasswordModel model = new EmailForgotPasswordModel()
                    {
                        To = user.Email,
                        Username = user.Username,
                        NewPassword = newPassword
                    };
                    mailer.ForgotPassword(model);

                    return Status.OK<User>(user);
                }
                catch (Exception ex)
                {
                    // TODO: log exception
                    return Status.Error<User>("System was unable to reset password", null);
                }
            }
        }
Exemple #5
0
 public Status <bool> ForgotPassword(EmailForgotPasswordModel model)
 {
     return(SendMail(model, "account/forgotpassword"));
 }