public override void OnAuthorization(AuthorizationContext filterContext) { if (String.IsNullOrEmpty(SessionPersister.Username)) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary (new { controller = "Account", action = "Index" })); } else { WCFAccountServiceClient accountServiceClient = new WCFAccountServiceClient(); CustomPrincipal customPrincipal = new CustomPrincipal (accountServiceClient.Find(SessionPersister.Username)); if (!customPrincipal.IsInRole(Roles)) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary(new { controller = "Error", action = "Index" })); } } }
public ActionResult Register(Account account, string Repassword) { string username = account.UserName; WCFAccountServiceClient accountServiceClient = new WCFAccountServiceClient(); if (ModelState.IsValid) { bool check = true; if (accountServiceClient.Find(username) != null) { check = false; ModelState.AddModelError("UserName", "Username is already existed"); } if (accountServiceClient.GetUserPhone(account.PhoneNumber) != null) { ModelState.AddModelError("PhoneNumber", "Phone number is already existed"); check = false; } if (!account.Password.Equals(Repassword)) { ModelState.AddModelError("Repassword", "Does not match with password"); check = false; } if (check) { if (accountServiceClient.Register(account)) { ViewBag.Message = "Register Successfully!"; return(View("~/Views/Login.cshtml")); } else { ViewBag.Message = "Server is currently not available!"; } } } return(View("~/Views/Register.cshtml", account)); }