예제 #1
0
 @Override
 public WUser isAuthorized() throws IllegalArgumentException {
   Logger.getLogger(getClass()).debug("called isAuthorized()");
   if (Session.Instance().getValue(this, USER_TOKEN) != null) {
     final String authToken = Session.Instance().getValue(this, USER_TOKEN).toString();
     WUser user = new WUser();
     user.setToken(authToken);
     return user;
   }
   return null;
 }
예제 #2
0
 @Override
 public WUser login(WUser user) throws IllegalArgumentException {
   Logger.getLogger(getClass()).debug("called login()");
   JsonLoginRequest request = new JsonLoginRequest(user.getLogin(), user.getPassword(), serverUrl);
   JsonLoginResponse response = new JsonLoginResponse();
   response.parseJson(request.doRequest());
   if (response.getAuthString() == null) {
     return null;
   } else {
     WUser newUser = new WUser(user.getLogin(), user.getPassword());
     newUser.setToken(response.getAuthString());
     newUser.setStatus(Response.STATUS_SUCCES);
     Session.Instance().addValue(this, USER_TOKEN, newUser.getToken());
     return newUser;
   }
 }
예제 #3
0
 @Override
 public WUser addUser(WUser user) throws IllegalArgumentException {
   JsonAddUserRequest request =
       new JsonAddUserRequest(user.getEmail(), user.getLogin(), user.getPassword(), serverUrl);
   JsonAddUserResponse response = new JsonAddUserResponse();
   response.parseJson(request.doRequest());
   if (response.getAuthToken() == null) {
     return null;
   } else {
     WUser newUser = new WUser(user.getLogin(), user.getPassword());
     newUser.setEmail(user.getEmail());
     newUser.setPassword(user.getPassword());
     newUser.setToken(response.getAuthToken());
     return newUser;
   }
 }