示例#1
0
        public async Task <Response> Authenticate([FromBody] LoginViewModel userModel)
        {
            var user = await _userOperations.AuthenticateAsync(userModel.Username, userModel.Password);

            if (user == null)
            {
                return new Response
                       {
                           ErrorMessage = "Username or password is incorrect",
                           Status       = ResponseStatus.Error,
                       }
            }
            ;

            var userToken = GenerateUserToken(user);

            return(new Response
            {
                Result = new UserAuthenticationModel
                {
                    Id = user.Id,
                    Username = user.Username,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Token = userToken
                },
                Status = ResponseStatus.Ok,
            });
        }