// these build the collections to return to the servlets, controlles
 private void loadUser(User user, ResultSet resultSet, int index) throws SQLException {
   user.setUserID(resultSet.getInt(index++));
   user.setUsername(resultSet.getString(index++));
   user.setPassword(resultSet.getString(index++));
   user.setEmail(resultSet.getString(index++));
   user.setAccountType(resultSet.getString(index++));
   user.setFname(resultSet.getString(index++));
   user.setLname(resultSet.getString(index++));
 }
示例#2
0
文件: Tui.java 项目: NichlasH/server
  public static User createUser() {

    // TODO: This should work! - DONE
    User usr = new User();
    usr.setFirstName(enterFirstName());
    usr.setLastName(enterLastName());
    usr.setEmail(enterEmail());
    usr.setUsername(enterUsername());
    usr.setPassword(enterPassword());
    usr.setType(enterUserType());

    return usr;
  }
示例#3
0
  @GET
  @Path("/feed")
  @Produces("application/json")
  public String getFeed(@QueryParam("user") String username) {
    User usr = new User();
    usr.setUsername(username);
    List<LogViewModel> lvm = new ArrayList<LogViewModel>();
    List<Log> original = LogDB.listUserFeed(usr);

    for (Log log : original) {
      log.setBody(log.getBody().replaceAll("(.{60})", "$1\n"));
      lvm.add(new LogViewModel(log));
    }
    String json = null;
    if (lvm.size() > 0) {
      Gson gson = new Gson();
      json = gson.toJson(lvm, ArrayList.class);
    }
    return json;
  }
  // Method that makes it possible for the user to log in
  public User Login(ScreenFrame frame, ServerConnection server, User currentUser, Parsers parser) {

    // Sets variables username and password equal to the typed values in the LoginScreen panel
    String username = frame.getLoginScreen().getTfUsername().getText();
    String password = frame.getLoginScreen().getTfPassword().getText();

    // Try/catch for error handling through exceptions
    try {
      // If-statement for checking the typed values.
      // If the typed values aren't equal to "" (empty textfields) the method will be executed
      if (!username.equals("") & !password.equals("")) {

        User user = new User();

        // Sets the username and password for the logged in user equal to the typed values
        user.setUsername(username);
        user.setPassword(password);

        // Sends
        String json = new Gson().toJson(user);

        // Sends
        String message = parser.loginParser((server.post(json, "login/")), user);

        // Checks whether the received message is equal to the wanted one
        if (message.equals("Login successful")) {

          currentUser = user;

          // Uses the userParser method to get ..
          parser.userParser(server.get("users/" + currentUser.getId() + "/"), currentUser);

          // Leads the user to the usermenu
          frame.show(frame.USERSCREEN);

          // Returns the value/variable/object currentUser to define who's logged in
          return currentUser;

          // If the server can't fit the typed values
          // Responds following received message with a JOptionPane that will warn the user
        } else if (message.equals("Wrong username or password")) {

          JOptionPane.showMessageDialog(
              frame,
              "Wrong username or password. Please try again",
              "Error",
              JOptionPane.ERROR_MESSAGE);

          // If the error is elsewhere than in the typed values
          // Responds following received message with a JOptionPane that will warn the user
        } else if (message.equals("Error in JSON")) {

          JOptionPane.showMessageDialog(frame, "Error", "Error", JOptionPane.ERROR_MESSAGE);
        }
      }

      // Prints a stacktrace when catching an unforeseen error
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }