Exemple #1
0
        public async Task <IActionResult> LoginAsync([FromBody] LoginUser loginUser)
        {
            try
            {
                await _userService.LoginAsync(loginUser.Email, loginUser.Password);

                var user = await _userService.GetAsync(loginUser.Email);

                var token = await _jwtHandler.CreateTokenByUserObject(user);

                return(Json(token));
            }
            catch (Exception e)
            {
                _logger.LogError($"Returning exception: {e.Message}");
                return(Json(new ExceptionDto
                {
                    Error = e.Message
                }));
            }
        }
Exemple #2
0
        public IActionResult Login([FromBody] LoginRequest user)
        {
            var query       = new GetUserByIdentifiersQuery(user.Username);
            var queryResult = queryBus.Execute(query);

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


            var passHash = _encrypter.GetHash(user.Password, queryResult.User.Salt);

            if (passHash != queryResult.User.HashPassword)
            {
                return(Unauthorized());
            }

            var jwtToken = _jwtHandler.CreateTokenByUserObject(queryResult.User);

            return(Json(jwtToken));
        }