Пример #1
0
        public ActionResult <UserProfileWithToken> Authenticate([FromBody] CredentialsDto credentials)
        {
            var token = securityService.GenerateJwtToken(credentials.UserName, credentials.Password);

            if (token == null)
            {
                return(Unauthorized());
            }

            var user = alohaDbContext.Users
                       .Include(u => u.Worker)
                       .ThenInclude(w => w.Photo)
                       .Single(u => u.UserName == credentials.UserName);

            var response = new UserProfileWithToken()
            {
                UserName = user.UserName,
                Token    = token,
                WorkerId = user.Worker?.Id,
                Name     = user.Worker?.Name,
                SurName  = user.Worker?.Surname,
                ImageId  = user.Worker?.Photo?.Id
            };

            return(new ActionResult <UserProfileWithToken>(response));
        }
Пример #2
0
        public UserProfileWithToken Info()
        {
            var userId = int.Parse(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value);
            var user   = alohaDbContext.Users
                         .Include(u => u.Worker)
                         .ThenInclude(w => w.Photo)
                         .Single(u => u.Id == userId);

            var response = new UserProfileWithToken()
            {
                UserName = user.UserName,
                WorkerId = user.Worker?.Id,
                Name     = user.Worker?.Name,
                SurName  = user.Worker?.Surname,
                ImageId  = user.Worker?.Photo?.Id
            };

            return(response);
        }