Example #1
0
        public async Task <IActionResult> GenerateTokenAsync()
        {
            var claimId = _claimsService.GetUserId(HttpContext.User.Identity as ClaimsIdentity);

            if (claimId == 0)
            {
                return(Unauthorized("You don't have permission to create a place"));
            }

            var t = _tokenGeneratorService.GenerateJwtToken(claimId);

            return(Ok(t));
        }
Example #2
0
        public async Task <IActionResult> Index([FromForm] LoginResource resource)
        {
            var user = await _userRepository.GetUserByEmailAsync(resource.Email);

            if (user is null)
            {
                return(NotFound("User doesn't exists"));
            }

            if (_hashService.VerifyPassword(resource.Password, user.Password))
            {
                var token = _tokenGeneratorService.GenerateJwtToken(user.UserId);

                return(Ok(token));
            }

            return(NotFound("Wrong password"));
        }