Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public void Register(User model)
- {
- User u = new User();
- u.Register(model);
- Login(model, "~/Home");
- }
- [HttpPost]
- public ActionResult Login(User model, string returnUrl)
- {
- if (ModelState.IsValid)
- {
- var user = model.Login(model.EmailAddress);
- if (user != null)
- {
- FormsAuthentication.SetAuthCookie(user.Username, true);
- Session["userId"] = user.UserId;
- Session["userRole"] = user.Role;
- if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
- {
- return Redirect(returnUrl);
- }
- else
- {
- return RedirectToAction("Index", "Home");
- }
- }
- else
- {
- ModelState.AddModelError("", "Invalid email address or password.");
- }
- }
- // If execution got this far, something failed, redisplay form
- return View(model);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement