コード例 #1
0
ファイル: AccountController.cs プロジェクト: tjm1138/Ludus
        public ActionResult Register(RegisterModel model)
        {
            Session["Permissions"] = new Ludus.Models.UserPermission();
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);

                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: tjm1138/Ludus
 public ActionResult Login(LoginModel model, string returnUrl)
 {
     Session["Permissions"] = new Ludus.Models.UserPermission();
     if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, false))
     {
         DataContext dc = new DataContext();
         int userId = (from u in dc.UserProfiles where u.UserName == model.UserName select u.UserId).FirstOrDefault();
         ((Ludus.Models.UserPermission)Session["Permissions"]).Fill (userId);
         return RedirectToLocal(returnUrl);
     }
     // If we got this far, something failed, redisplay form
     ModelState.AddModelError("", "The user name or password provided is incorrect.");
     return View(model);
 }