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)
            {

            }
        }
Ejemplo n.º 2
0
 public AccountController ()
 {
     usersBl = new UsersBL();
 }
Ejemplo n.º 3
0
        public static void Init ( TestContext test )
        {
            RepositoryUtils.SetDbContextType();
            usersBL = new UsersBL();

        }
Ejemplo n.º 4
0
 public UsersController ()
 {
     usersBl = new UsersBL();
 }
Ejemplo n.º 5
0
 public FilesController ()
 {
     usersBl = new UsersBL();
 }