コード例 #1
0
 public IActionResult PerformUserLogin([FromBody] LoginModel login)
 {
     if (ModelState.IsValid)
     {
         userPlanner.SetUserStrategy(new UserStrategy(login.Username, login.Password));
         var userCredentials = userPlanner.GetUserCredential();
         if (userCredentials.UserID > 0)
         {
             userPlanner.SetUserStrategy(new UserStrategy(userCredentials.UserKey));
             if (!userPlanner.IsUserHasBeenBanned() || !userPlanner.IsUserHasBeenDeleted())
             {
                 var generatedToken = loginAuthHelper.GetUserToken(userCredentials);
                 userTokenPlanner.SetUserTokenPlanner(new UserTokenStrategy(userCredentials.UserLoginId, userCredentials.UserID, generatedToken));
                 if (userTokenPlanner.InsertUserToken())
                 {
                     return(Ok(new { token = generatedToken }));
                 }
             }
             return(Unauthorized(new { message = "Requested user has been disabled or deleted by the administrator." }));
         }
         return(NotFound(new { message = "Requested user was not found." }));
     }
     return(BadRequest(ModelState));
 }
コード例 #2
0
 public void GetUserCredentialByLoginTest()
 {
     userLoginPlanner.SetUserStrategy(new UserStrategy("ajqportal", "Alvin123!!!"));
     var userCredential = userLoginPlanner.GetUserCredential();
 }