Advertisement
LYSoft

Untitled

May 17th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1.         [HttpPost]
  2.         public void Register(User model)
  3.         {
  4.             User u = new User();
  5.             u.Register(model);
  6.  
  7.             Login(model, "~/Home");
  8.         }
  9.  
  10.         [HttpPost]
  11.         public ActionResult Login(User model, string returnUrl)
  12.         {
  13.             if (ModelState.IsValid)
  14.             {
  15.                 var user = model.Login(model.EmailAddress);
  16.                 if (user != null)
  17.                 {
  18.                     FormsAuthentication.SetAuthCookie(user.Username, true);
  19.                     Session["userId"] = user.UserId;
  20.                     Session["userRole"] = user.Role;
  21.                     if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
  22.                     {
  23.                         return Redirect(returnUrl);
  24.                     }
  25.                     else
  26.                     {
  27.                         return RedirectToAction("Index", "Home");
  28.                     }
  29.                 }
  30.                 else
  31.                 {
  32.                     ModelState.AddModelError("", "Invalid email address or password.");
  33.                 }
  34.             }
  35.  
  36.             // If execution got this far, something failed, redisplay form
  37.             return View(model);
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement