コード例 #1
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (SessionPersiter.User == null)
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "User", action = "Index" }));
            }
            else
            {
                UserModel userMod = new UserModel();

                CustomPrincipal customPrinc = new CustomPrincipal(userMod.Find(SessionPersiter.User.Email));

                if (!customPrinc.IsInRole(UserRoles))
                {
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "AccessDenied", action = "Index" }));
                }

            }
        }
コード例 #2
0
        public ActionResult Register(User user)
        {

            UserModel userMod = new UserModel();
            if (userMod.Find(user.Email) != null)
            {
                ViewBag.UsernameError = "L'adresse courriel est déjà utilisée doit être unique";
            }

            if (!userMod.Insert(user))
            {
                return View("Register");
            }
            return RedirectToAction("List");
        }