Exemplo n.º 1
0
        public async Task <IActionResult> Get(string id)
        {
            var getQuery = new GetUserQuery(_context);
            var user     = await getQuery.Execute(id);

            return(user == null
                ? new NotFoundResult() as ActionResult
                : new ObjectResult(user));
        }
Exemplo n.º 2
0
        public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            string idStr = context.Subject.GetSubjectId();
            var    id    = int.Parse(idStr);

            User user = await _getUserQuery.Execute(id);

            var claims = new List <Claim>
            {
                new Claim(JwtClaims.ClaimUserId, user.Id.ToString()),
                new Claim(JwtClaims.ClaimName, user.Name.ToString()),
                new Claim(JwtClaims.ClaimSurname, user.Surname.ToString()),
                new Claim(JwtClaims.ClaimEmail, user.Email.ToString()),
                new Claim(JwtClaims.IsAdmin, user.CandidateId == _config.AdminLogin ? "1" : "0")
            };

            context.IssuedClaims = claims;
        }
Exemplo n.º 3
0
        public async Task <UserModel> GetUser(string email)
        {
            using (var connection = DatabaseConnectionFactory.Create())
            {
                await connection.OpenAsync();

                var query = new GetUserQuery(connection);
                return(await query.Execute(email));
            }
        }
Exemplo n.º 4
0
        public async Task <GetUserResponse> GetUser(
            [FromQuery] GetUserRequest request,
            CancellationToken cancellationToken)
        {
            var getUsersQuery = new GetUserQuery(
                request.UserId,
                _repository);

            var result = await getUsersQuery.Execute(cancellationToken);

            return(result.ToApiResponse());
        }
        protected async Task <User> AuthenticateAdmin()
        {
            GetUserQuery query = HttpContext.RequestServices.Get <GetUserQuery>();
            User         user  = await query.Execute(ParseUserId());

            if (user.CandidateId == Get <BusinessConfiguration>().AdminLogin)
            {
                return(user);
            }
            else
            {
                throw new UnauthorizedAccessException();
            }
        }
Exemplo n.º 6
0
 public IActionResult Get(long id)
 {
     return(getOneQuery.Execute(id).Match(
                Succ: Ok,
                Fail: ex => StatusCode(500, ex)));
 }
        protected async Task <User> AuthenticateUser()
        {
            GetUserQuery query = HttpContext.RequestServices.Get <GetUserQuery>();

            return(await query.Execute(ParseUserId()));
        }