Пример #1
0
        public ActionResult Register(RegisterModel registerModel)
        {
            bool userExists = userManager.UserExist(registerModel.Email);

            if (userExists)
            {
                ModelState.AddModelError("", "User name exists");
            }
            else
            {
                var user = userManager.Register(registerModel.Email, registerModel.UserPassword);

                if (ModelState.IsValid)
                {
                    if (user == null)
                    {
                        ModelState.AddModelError("", "User name and password do not match.");
                    }
                    else
                    {
                        Session["User"] = new TheLearningCenter.WebSite.Models.UserModel
                        {
                            UserId    = user.Id,
                            UserEmail = user.Name
                        };

                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(registerModel));
        }
Пример #2
0
        public ActionResult LogIn(LoginModel loginModel, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = userManager.LogIn(loginModel.UserName, loginModel.UserPassword);

                if (user == null)
                {
                    ModelState.AddModelError("", "User name and password do not match.");
                }
                else
                {
                    Session["User"] = new TheLearningCenter.WebSite.Models.UserModel
                    {
                        UserId    = user.Id,
                        UserEmail = user.Name
                    };

                    System.Web.Security.FormsAuthentication.SetAuthCookie(
                        loginModel.UserName, false);

                    return(Redirect(returnUrl ?? "~/"));
                }
            }

            return(View(loginModel));
        }
Пример #3
0
        public ActionResult Register(RegisterView registerView, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = userRepository.Register(registerView.Email, registerView.Password);

                if (user == null)
                {
                    ModelState.AddModelError("", "User name and password do not match.");
                }
                else
                {
                    Session["User"] = new TheLearningCenter.WebSite.Models.UserModel {
                        Id = user.Id, Email = user.Email
                    };

                    System.Web.Security.FormsAuthentication.SetAuthCookie(registerView.Email, false);

                    return(Redirect(returnUrl ?? "~/"));
                }
            }

            return(View(registerView));
        }