コード例 #1
0
ファイル: Register.java プロジェクト: webplan/PlanServer
 // 定义处理用户请求的execute方法
 public String execute() {
   String ret = "";
   String avatagUrl = UploadPhoto.UploadPhoto(avatag, account);
   System.err.println(
       "Register:"
           + account
           + ","
           + password_md5
           + ","
           + nickname
           + ","
           + phone
           + ","
           + avatag
           + ","
           + avatagUrl);
   UserEntity user = new UserEntity();
   user.setAccount(account);
   user.setPassword(password_md5);
   user.setNickname(nickname);
   user.setAvatag(avatagUrl);
   user.setPhone(phone);
   FriendEntity fe = new FriendEntity();
   fe.setFriendAccount(account);
   fe.setUserAccount(account);
   JSONObject obj = new JSONObject();
   try {
     DataOperate dataop = new DataOperate();
     dataop.Save(user);
     dataop.Save(fe);
     obj.put("status", 1);
   } catch (Exception e) {
     try {
       System.err.println(e + "\nshfe");
       obj.put("status", 0);
     } catch (JSONException e1) {
       e1.printStackTrace();
     }
   }
   ret = obj.toString();
   PrintToHtml.PrintToHtml(response, ret);
   return null;
 }
コード例 #2
0
ファイル: Recommend.java プロジェクト: webplan/PlanServer
  // 定义处理用户请求的execute方法
  public String execute() {
    System.err.println("Recommend:" + account + "," + token + "," + phone_list);
    String ret = "";
    JSONObject obj = new JSONObject();
    JSONArray jsarray = new JSONArray();
    try {
      DataOperate dataop = new DataOperate();
      List it = dataop.SelectTb("from UserEntity");
      boolean istoken = Config.CheckToken(dataop, account, token);
      if (istoken) { // token正確
        // List<UserEntity> list = new ArrayList<>();
        for (int i = 0; i < it.size(); i++) {
          UserEntity user = (UserEntity) it.get(i);
          if (phone_list.contains("\"" + user.getPhone() + "\"")) {
            JSONObject jsob = new JSONObject();
            jsob.put("account", user.getAccount());
            jsob.put("nickname", user.getNickname());
            jsob.put("avatag", user.getAvatag());
            jsarray.put(jsob);
            // list.add(user);
          }
        }
        obj.put("status", 1);
        obj.put("person", jsarray);
      } else {
        obj.put("status", 2);
      }
    } catch (Exception e) {
      try {
        obj.put("status", 0);
      } catch (JSONException e1) {
        e1.printStackTrace();
      }
    }

    ret = obj.toString();
    PrintToHtml.PrintToHtml(response, ret);
    return null;
  }