Beispiel #1
0
 @DELETE
 public boolean deleteUser(
     @QueryParam("username") String username, @QueryParam("password") String password) {
   User user = userService.getUser(username, password);
   if (user == null) return false;
   return userService.deleteUser(user.getUid());
 }
Beispiel #2
0
 @GET
 public User getUser(
     @QueryParam("username") String username, @QueryParam("password") String password) {
   User user = userService.getUser(username, password);
   System.out.println(user.getDescription());
   return user;
 }
Beispiel #3
0
  public List<User> getData(String selectSql) {
    System.out.println(selectSql);
    List<User> list = null;
    Pool pool = null;
    Connection conn = null;
    Statement stmt = null;
    try {
      pool = Pool.getInstance();
      conn = pool.getConnection();
      stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery(selectSql);
      list = new ArrayList<User>();
      User user = null;

      while (rs.next()) {
        user = new User();
        user.setAddress(rs.getString("ADDRESS"));
        user.setAge(rs.getInt("AGE"));
        user.setGender(rs.getString("GENDER"));
        user.setID(rs.getString("ID"));
        user.setLoginname(rs.getString("LOGINNAME"));
        user.setPassword(rs.getString("PASSWORD"));
        user.setRepassword(rs.getString("REPASSWORD"));
        user.setTelephone(rs.getString("TELEPHONE"));
        user.setUsername(rs.getString("USERNAME"));
        list.add(user);
      }
      rs.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return list;
  }
Beispiel #4
0
 public CurrentUser(User user) {
   super(
       user.getEmail(),
       user.getPasswordHash(),
       AuthorityUtils.createAuthorityList(user.getRole().toString()));
   this.user = user;
 }
 /** 设置手机号,等待验证码(注册时可用,重置手机号往往应该先验证一下当前的(主动发送一次验证码到当前手机号)) */
 public void setMobile() {
   final String mobile = setMobilePhone.getText().toString();
   User user = AVUser.getCurrentUser(User.class);
   if (TextUtils.isEmpty(mobile)
       || mobile.length() != 11
       || user == null
       || !user.isAuthenticated()) return;
   showLoadingDialog("设置手机号...");
   user.setMobilePhoneNumber(mobile); // 先设置手机号
   user.saveInBackground(
       new SaveCallback() {
         @Override
         public void done(AVException e) {
           if (e == null) {
             AVUser.requestMobilePhoneVerifyInBackground(
                 mobile,
                 new RequestMobileCodeCallback() {
                   @Override
                   public void done(AVException e) {
                     if (e == null) {
                       Utils.showToast(UserActivity.this, "已发送验证码短信,请验证!");
                     } else {
                       textView.setText(e.getMessage());
                     }
                     cancelLoadingDialog();
                   }
                 });
           } else {
             textView.setText(e.getMessage());
             cancelLoadingDialog();
           }
         }
       });
 }
Beispiel #6
0
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof User) {
      User user = (User) obj;
      return user.getId() == id;
    }

    return false;
  }
Beispiel #7
0
  public User isValidLogin(String email, String password) {
    userDAO.beginTransaction();
    User user = userDAO.findUserByEmail(email);

    if (user == null || !user.getPassword().equals(password)) {
      return null;
    }

    return user;
  }
Beispiel #8
0
 public boolean addUser(User user) {
   boolean result =
       add(
           "INSERT INTO "
               + getTableName()
               + " VALUES('"
               + user.getLoginname()
               + "',"
               + "'"
               + user.getUsername()
               + "','"
               + user.getPassword()
               + "','"
               + user.getRepassword()
               + "',"
               + "'"
               + user.getAge()
               + "','"
               + user.getGender()
               + "','"
               + user.getID()
               + "',"
               + "'"
               + user.getAddress()
               + "','"
               + user.getTelephone()
               + "')");
   return result;
 }
Beispiel #9
0
 @PUT
 public boolean updateUser(
     @QueryParam("username") String username,
     @QueryParam("password") String password,
     @QueryParam("description") String description) {
   User user = new User();
   user.setUsername(username);
   user.setPassword(password);
   user.setDescription(description);
   return userService.updateUser(user);
 }
Beispiel #10
0
 public boolean updateUser(User user) {
   boolean result =
       update(
           "update "
               + getTableName()
               + " set PASSWORD = '******'"
               + "where LOGINNAME='"
               + user.getLoginname()
               + "'");
   return result;
 }
Beispiel #11
0
  public void updateUser(User user) {

    User userToUpdate = getUser(user.getId());
    userToUpdate.setName(user.getName());
    userToUpdate.setAge(user.getAge());
    userToUpdate.setIsAdmin(user.getIsAdmin());
    getCurrentSession().update(userToUpdate);
  }
 private void changePassword() throws Exception {
   String name = (String) list_read.get(1);
   String pass1 = (String) list_read.get(2);
   String pass2 = (String) list_read.get(3);
   User.changePassword(name, pass1, pass2);
   reInput();
 }
Beispiel #13
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");
    boolean isAccessed = SessionFilter.sessionCheck(request, response);
    if (isAccessed == false) {
      response.sendRedirect(request.getContextPath() + "/login.jsp");
    }
    // 管理员
    boolean isAdmin = AdminUtils.adminCheck(request, response);
    if (isAdmin == false) {
      return;
    }
    System.out.println(request.getParameter("pageCode") + ",,,");
    Integer pageCode = Integer.parseInt(request.getParameter("pageCode"));
    if (pageCode == null) {
      return;
    }
    pageCode = (pageCode - 1) * UserDao.PAGESIZE;
    String jsonStr = "";
    PrintWriter out = null;

    // 依赖UserServlet
    UserService userService = new UserService();
    //		User user=(User)request.getSession().getAttribute("sessionUser");
    //		{"res":0或1,"user":[{"account":"","name":"","phone":"","email":""},{}]}
    //		if(user.getType() != AdminUtils.ADMINTYPE) {
    //			jsonStr =
    // "{\"res\":1,\"user\":[{\"account\":null,\"name\":null,\"phone\":null,\"email\":null}]}";
    //		} else {

    // json
    ArrayList<User> users = userService.findUsers(pageCode);
    if (users.size() == 0) {
      jsonStr =
          "{\"res\":-1,\"user\":[{\"account\":null,\"name\":null,\"phone\":null,\"email\":null}]}";
    } else {
      jsonStr = "{\"res\":0,\"user\":[";
      for (User user2 : users) {
        String str =
            "{\"acounnt\":\""
                + user2.getAccount()
                + "\",\"username\":\""
                + user2.getUsername()
                + "\",\"phone\":\""
                + user2.getPhone()
                + "\",\"email\":\""
                + user2.getEmail()
                + "\",\"type\":"
                + user2.getType()
                + "},";
        jsonStr += str;
      }
      jsonStr = jsonStr.substring(0, jsonStr.length() - 1);
      jsonStr += "]}";
    }
    //		}
    //			jsonStr = new String(jsonStr.getBytes("ISO-8859-1"), "utf-8");
    JsonUtils.writeJson(response, jsonStr);
  }
 /** 注册 */
 public void signUp() {
   String username = setUsername.getText().toString();
   String password = setPassword.getText().toString();
   String email = setEmail.getText().toString();
   final String displayName = setDisplayname.getText().toString();
   if (TextUtils.isEmpty(username)
       || TextUtils.isEmpty(password)
       || TextUtils.isEmpty(email)
       || TextUtils.isEmpty(displayName)) return;
   showLoadingDialog("正在注册用户...");
   User user = new User();
   user.setUsername(username); // 默认字段有getset方法
   user.setPassword(password);
   user.setEmail(email);
   user.setDisplayName(displayName);
   user.setMobilePhoneNumber(setMobilePhone.getText().toString());
   user.signUpInBackground(
       new SignUpCallback() { // 注册
         @Override
         public void done(AVException e) {
           if (e == null) {
             Utils.showToast(UserActivity.this, "注册成功");
             User user = AVUser.getCurrentUser(User.class); // 注册或登陆后会自动存入用户信息直到注销,否则下回自动登录
             if (user != null) {
               textView.setText(
                   "Username:"******"\n"
                       + "DisplayName:"
                       + user.getDisplayName()
                       + "\n");
             }
           } else { // 根据exception可以判断哪错了
             textView.setText(e.getMessage());
           }
           cancelLoadingDialog();
         }
       });
 }
Beispiel #15
0
 public Role getRole() {
   return user.getRole();
 }
Beispiel #16
0
 public Long getId() {
   return user.getId();
 }