Example #1
0
        public async Task <ActionResult> LoginUser([FromBody] DtoUserLogin model)
        {
            IdentityUser user = await _userManager.FindByNameAsync(model.Username);

            if (user != null)
            {
                var signInRes = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);

                if (signInRes.Succeeded)
                {
                    var roles = await _userManager.GetRolesAsync(user);

                    var strToken = _tokenGenerator.AccessJWToken(user, roles[0]).ToString();

                    return(Ok(new UserResponse
                    {
                        Message = "Successfully logged",
                        IsSuccess = true,
                        JwtResponseToken = strToken
                    }));
                }
                return(BadRequest(new UserResponse {
                    Message = "Insufficient information", IsSuccess = false
                }));
            }
            return(BadRequest(new UserResponse {
                Message = "Failed login, wrong username or password", IsSuccess = false
            }));
        }