Ejemplo n.º 1
0
 public ActionResult RequestPassword(String email)
 {
     UserProfile userProfile = _repo.Find<UserProfile>(x => x.Email.Equals(email)).FirstOrDefault();
     MessageModel messageModel = new MessageModel();
     if (userProfile != null)
     {
         String token = WebSecurity.GeneratePasswordResetToken(userProfile.Name);
         IDictionary<string, string> data = new Dictionary<string, string>();
         data.Add("name", userProfile.Name);
         data.Add("token", token);
         String subject = String.Format("\"{0}\" - SPC VMS-Tufman Reconciliation - Reset password", userProfile.Name);
         String body = new TemplatingService().GetTemplatedDocument("ResetPasswordEmail.vm", data);
         new EmailServices().SendEmail(subject, body, email);
         messageModel.Body = "An email has been sent with a link to reset your password";
         return View("Message", messageModel);
     }
     messageModel.Title = "Unknown Email";
     messageModel.Body = String.Format("User with email {0} is not registered in the application", email);
     return View("Message", messageModel);
 }
Ejemplo n.º 2
0
        public ActionResult ResetPassword(String token)
        {
            String password = Membership.GeneratePassword(10, 3);
            int userId = WebSecurity.GetUserIdFromPasswordResetToken(token);
            UserProfile userProfile = _repo.Get<UserProfile>(userId);
            MessageModel messageModel = new MessageModel();
            if (WebSecurity.ResetPassword(token, password))
            {
                IDictionary<string, string> data = new Dictionary<string, string>();
                data.Add("name", userProfile.Name);
                data.Add("password", password);
                String subject = String.Format("\"{0}\" - SPC VMS-Tufman Reconciliation - Reset password", userProfile.Name);
                String body = new TemplatingService().GetTemplatedDocument("NewPasswordEmail.vm", data);
                new EmailServices().SendEmail(subject, body, userProfile.Email);
            }
            else
            {
                messageModel.Title = "Error";
                messageModel.Body = "Your password could not be reseted. It may be because the link you used has already been used.";

                return View("Message",messageModel);
            }
            messageModel.Body = "An email has been sent with your new password";
            return View("Message", messageModel);
        }
Ejemplo n.º 3
0
        public ActionResult Register(RegisterModel model)
        {
            if(WebSecurity.UserExists(model.UserName))
                ModelState.AddModelError("Name", "This User name is already registered");
            if(model.SelectedRole.Equals(RoleList.Country) && String.IsNullOrEmpty(model.SelectedCountry))
                ModelState.AddModelError("SelectedCountry", "Select a country for this user");

            if (ModelState.IsValid)
            {
                try
                {
                    String password = Membership.GeneratePassword(10,0);
                    WebSecurity.CreateUserAndAccount(model.UserName, password, new { Country = model.SelectedCountry, Email = model.Email });
                    Roles.AddUserToRole(model.UserName, model.SelectedRole);
                    IDictionary<string, string> data = new Dictionary<string, string>();
                    data.Add("name",model.UserName);
                    data.Add("password", password);
                    String subject = String.Format("\"{0}\" - You can now connect to SPC VMS-Tufman Reconciliation ", model.UserName);
                    String body = new TemplatingService().GetTemplatedDocument("NewUserEmail.vm", data);
                    new EmailServices().SendEmail(subject, body, model.Email);
                    MessageModel messageModel = new MessageModel();
                    messageModel.Body = "An email has been sent to this user with its credentials";
                    return View("Message", messageModel);
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }
            // If we got this far, something failed, redisplay form
            model.Roles = Roles.GetAllRoles().Select(c => new SelectListItem { Value = c, Text = c }).ToList();
            model.Countries = _repo.GetAll<TufmanCountry>().Select(c => new SelectListItem { Value = c.Code, Text = c.Label }).ToList();
            return View(model);
        }