Ejemplo n.º 1
0
        public async Task <ActionResult <AuthenticateUserResult> > Login([FromBody] AuthenticateUserRequest model)
        {
            var result = await authenticateService.AuthenticateUser(model);

            if (result.IsSuccessful)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.Error));
            }
        }
Ejemplo n.º 2
0
        public IActionResult Token([FromBody] AuthenticateRequestViewModel request)
        {
            var user = AuthService.AuthenticateUser(request.Username, request.Password);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            var tokenString = AuthService.GetAccessToken(user);

            return(Ok(new { token = tokenString }));
        }
Ejemplo n.º 3
0
 public IActionResult UserLogIn([FromBody] ApiUserLoginModel request)
 {
     try
     {
         var user = authService.AuthenticateUser(request, out string token);
         if (user != null && user.Technical != null)
         {
             user.Password = null;
             var model = new
             {
                 user.Id,
                 Name = user.ArabicName,
                 user.Location,
                 ServiceName = user.Technical?.Service?.ArabicName,
                 user.UserName,
                 user.Mobile,
                 user.Technical.Pocket,
                 user.CityId,
                 user.DistrictId,
                 token
             };
             return(Ok(new ApiResponseModel
             {
                 Status = EN_ResponseStatus.Success,
                 Message = "Logged in successflly",
                 Data = model,
                 Errors = null
             }));
         }
         return(Ok(new ApiResponseModel
         {
             Status = EN_ResponseStatus.Faild,
             Message = "Invalid mobile or password",
             Data = null,
             Errors = new string[] { "Invalid mobile or password" }
         }));
     }
     catch (Exception ex)
     {
         return(Ok(new ApiResponseModel
         {
             Status = EN_ResponseStatus.Faild,
             Message = "Error: " + ex.Message,
             Data = null,
             Errors = new string[] { "Error: " + ex.Message }
         }));
     }
 }
Ejemplo n.º 4
0
        public IActionResult RequestToken(TokenRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = authenticateService.AuthenticateUser(request, out string token);

            if (user != null)
            {
                return(Ok(user));
            }

            return(BadRequest("Invalid Request"));
        }
Ejemplo n.º 5
0
 public bool AuthenticateUser()
 {
     return(_AuthenticateService.AuthenticateUser(_UserName.Value, _Password.Value));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 验证当前用户,并登入系统
 /// </summary>
 /// <param name="userName"></param>
 /// <param name="password"></param>
 public static bool Authenticate(string userName, string password)
 {
     return(_authenticateService.AuthenticateUser(userName, password));
 }