public override async Task OnAuthorizationAsync (HttpActionContext actionContext,System.Threading.CancellationToken cancellationToken) { var allowAnonymous = actionContext.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any() || actionContext.ControllerContext.ControllerDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any(); var userId = actionContext.Request.GetHeader("userId").ToInt(); var token = actionContext.Request.GetHeader("token"); //check if this is annonymous action if(allowAnonymous) { return; } try { var usersBl = new UsersBL(); var result = await usersBl.Authenticate(userId,token); if(result.Status) { actionContext.ActionArguments.Add(User,result.Result); } else { var reason = "שם משתמש או סיסמה לא נכונים"; actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized) { ReasonPhrase = reason }; return; } } catch(Exception ex) { } }
public AccountController () { usersBl = new UsersBL(); }
public static void Init ( TestContext test ) { RepositoryUtils.SetDbContextType(); usersBL = new UsersBL(); }
public UsersController () { usersBl = new UsersBL(); }
public FilesController () { usersBl = new UsersBL(); }