Exemple #1
0
        public ActionResult LogIn(LoginModel loginModel, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = userRepository.LogIn(loginModel.Email, loginModel.Password);

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

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

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

            return(View(loginModel));
        }
Exemple #2
0
        public ActionResult Register(RegisterModel registerModel, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = userManager.Register(registerModel.Email, registerModel.Password);

                if (user == null)
                {
                    ModelState.AddModelError("", "User name already exists.");
                }
                else
                {
                    Session["User"] = new LearningCenter.Website.Models.UserModel {
                        Id = user.Id, Name = user.Name
                    };

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

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

            return(View(registerModel));
        }