Example #1
0
        public ActionResult Index(AccountViewModel input)
        {
            var person = DbSession.GetPersonByLogin(input.Username);

            if (person == null || !person.IsThePassword(input.Password))
            {
                ModelState.AddModelError("UserNotExistOrPasswordNotMatch",
                    "Username/Email and password do not match any known user.");
            }

            if (ModelState.IsValid)
            {
                var persist = input.Persist && input.Persist;
                FormsAuthentication.SetAuthCookie(person.Id, persist);
                return RedirectFromLoginPage();
            }

            return View(new AccountViewModel() { Username = input.Username });
        }
Example #2
0
        public ActionResult Register(AccountViewModel.Register model)
        {
            var email = DbSession.GetPersonByEmail(model.Email);
            var username = DbSession.GetPersonByUsername(model.Username);

            if (email != null)
            {
                ModelState.AddModelError("EmailAlreadyInUse",
                    "The email must be unique.");
            }

            if (username != null)
            {
                ModelState.AddModelError("UsernameAlreadyInUse",
                    "The username must be unique.");
            }

            if (ModelState.IsValid)
            {
                var person = Person.Forge(model.Email, model.Username, model.Password, model.Name);
                DbSession.Store(person);

                FormsAuthentication.SetAuthCookie(person.Id, false);
                return RedirectFromLoginPage();
            }
            return View(model);
        }