Example #1
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                // todo: remove this query - remember id in the same way as name
                var message = new GetUserDetailsByEmailAddressQuery { EmailAddress = User.Identity.Name };
                var user = _queryExecutor.Execute<GetUserDetailsByEmailAddressQuery, UserDto>(message).First();

                var command = new ChangePasswordForUserCommand
                                  {
                                      UserId = user.UserId,
                                      OldPassword = model.OldPassword,
                                      NewPassword = model.NewPassword
                                  };
                _commandExecutor.Execute(command);

                return RedirectToAction("ChangePasswordSuccess");
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = Membership.Provider.MinRequiredPasswordLength;
            return View(model);
        }
Example #2
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var message = new GetUserDetailsByEmailAddressQuery { EmailAddress = model.EmailAddress };
                var userDetails  = _queryExecutor.Execute<GetUserDetailsByEmailAddressQuery, UserDto>(message).FirstOrDefault();

                if(userDetails != null)
                {
                    if(userDetails.Password.Equals(model.Password.Trim()))
                    {
                        FormsAuthentication.SetAuthCookie(model.EmailAddress, model.RememberMe);

                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return Redirect(returnUrl);
                        }
                        return RedirectToAction("Index", "Home");
                    }

                    ModelState.AddModelError("", "The user name or password provided is incorrect.");

                }
            }

            return View(model);
        }