Exemplo n.º 1
0
        private void SetUser(string token, HttpContext httpContext)
        {
            try
            {
                UserModel user;

                lock (this)
                {
                    user = safeAccountService.GetUserByToken(token.Substring(6).Replace(" ", "")).Result;

                    if (user == null)
                    {
                        httpContext.Response.StatusCode = 400;
                        return;
                    }

                    httpContext.User = new GenericPrincipal(new UserIndentity(new ApplicaitonUser {
                        UserName = user.Login
                    }),
                                                            (safeAccountService.GetUserRoles(user.Login).Result).ToArray());
                }
            }
            catch
            {
                httpContext.Response.StatusCode = 401;
            }
        }
 public async Task <IEnumerable <string> > GetUserRoles(string name)
 {
     return(await safeAccountService.GetUserRoles(name));
 }