public ActionResult Login(LoginViewModel loginModel, string returnUrl) { if (ModelState.IsValid) { var user = AuthBusiness.GetUser(loginModel.UserName, loginModel.Password); if (user != null) { // sign in user SignIn(user); // redirect if (Url.IsLocalUrl(returnUrl) && returnUrl != "/") { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { loginModel.ErrorMessage = "Invalid User Name or Password"; } } return(View(loginModel)); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var allowedOrigin = context.OwinContext.Get <string>("as:clientAllowedOrigin"); if (allowedOrigin == null) { allowedOrigin = "*"; } context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin }); UserTokenModel user; using (AuthBusiness bus = new AuthBusiness()) { user = bus.FindUser(context.UserName, context.Password); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } } var identity = new ClaimsIdentity(context.Options.AuthenticationType); //identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); //identity.AddClaim(new Claim(ClaimTypes.Role, "admin")); foreach (string item in user.Roles) { identity.AddClaim(new Claim(ClaimTypes.Role, item)); } var props = new AuthenticationProperties(new Dictionary <string, string> { { "as:client_id", (context.ClientId == null) ? string.Empty : context.ClientId }, { "userName", context.UserName } }); var ticket = new AuthenticationTicket(identity, props); context.Validated(ticket); }
public override void OnAuthorization(AuthorizationContext filterContext) { var authBll = new AuthBusiness(); if (filterContext.ActionDescriptor.IsDefined(typeof(ValidateAuthorizeAttribute), false)) { if (!authBll.CheckPlatformIsAuthorize()) { filterContext.Result = new RedirectResult("/Authorize/Register"); } } if (!filterContext.ActionDescriptor.IsDefined(typeof(SkipLogonValidatedAttribute), false) && !filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipLogonValidatedAttribute), false)) { if (!authBll.CheckIsLogin()) { filterContext.Result = new RedirectResult("/user/login"); } } }
public async Task <ActionResult> Index() { var bll = base.CreateBusiness <IUserBusiness>(); var authBll = new AuthBusiness(); var user_ = await bll.GetUserViewModelAsync(base.UserId); ViewBag.UserName = user_.UserName; ViewBag.RoleName = user_.RoleName; var userType = await authBll.GetUserTypeAsync(base.UserId); if (userType == Entities.Enums.UserType.Customer) { return(RedirectToAction("ValidateRecorder", "Video")); } else { return(View()); } }
public AuthController(SvenDbContext context) { _business = new AuthBusiness(_context = context); }
public AuthController() { _authBusiness = new AuthBusiness(); }
public AuthController(AuthBusiness authBusiness) { _authBusiness = authBusiness; }
public RegisterController(AuthBusiness authBusiness) { _authBusiness = authBusiness; }
public AuthController(MongoDb dbContext) { _authBusiness = new AuthBusiness(dbContext); }