Beispiel #1
0
 public ActionResult ChangePassword(LocalPasswordModel.Password model)
 {
     WLogMembershipProvider provider = new WLogMembershipProvider();
     if (!provider.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
     {
         UserProfileContext.Current.Refresh();
         ModelState.AddModelError("", "Error");
         RedirectToAction("Manage");
     }
     else
     {
         return RedirectToAction("Index", "Private");
     }
     return View(new LocalPasswordModel());
 }
Beispiel #2
0
        public ActionResult NewUser(NewUser user)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    MembershipCreateStatus status;
                    WLogMembershipProvider provider = new WLogMembershipProvider();
                    provider.CreateUser(user.UserName, user.Password, user.Email, null, null, true, null, out status);
                    if (status == MembershipCreateStatus.Success)
                    {
                        UserEntity entity = UserHelper.GetByUsername(user.UserName);
                        entity.IsAdmin = user.IsAdmin;
                        UserHelper.UpdateUser(entity);
                        return RedirectToAction("EditUser", "Private", new { Id = entity.Id });
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorCodeToString(status));
                    }

                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // Se si arriva a questo punto, significa che si è verificato un errore, rivisualizzare il form
            return View(user);
        }
Beispiel #3
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            WLogMembershipProvider provider = new WLogMembershipProvider();
            if (provider.ValidateUser(model.UserName, model.Password))
            {
                FormsAuthentication.SetAuthCookie(model.UserName, true);
                if (returnUrl == null) returnUrl = "~/private";
                return RedirectToLocal(returnUrl);
            }

            // Se si arriva a questo punto, significa che si è verificato un errore, rivisualizzare il form
            ModelState.AddModelError("", "Il nome utente o la password fornita non è corretta.");
            return View(model);
        }