コード例 #1
0
  public List<String> account_setting(Map<String, String[]> parameterMap) {
    try {
      // Error messages
      List<String> error = new ArrayList<String>();
      boolean update_password = false;

      // current password
      String current_password = ((String[]) parameterMap.get("current_password"))[0];

      // password
      String password = ((String[]) parameterMap.get("password"))[0];
      String password1 = ((String[]) parameterMap.get("password"))[1];

      if (current_password.length() > 0 || password.length() > 0 || password1.length() > 0) {
        if (verifiyPassword(current_password)) {
          error.addAll(inputparser.parse_password(password, password1));
          if (error.isEmpty()) update_password = true;
        } else error.add("*Incorrect current password");
      }

      // email
      String email = ((String[]) parameterMap.get("email"))[0].trim();
      error.addAll(inputparser.parse_email(email));

      // phone number
      String phonenumber = ((String[]) parameterMap.get("phonenumber"))[0].trim();
      error.addAll(inputparser.parse_phonenumber(phonenumber));

      // update database
      if (error.isEmpty()) {
        global.openDBconnection();

        if (update_password) {
          global.update_user_set_password_where_id.setString(1, password);
          global.update_user_set_password_where_id.setInt(2, data.getUser_id());
          global.update_user_set_password_where_id.executeUpdate();
        }

        global.update_customer_where_id.setString(1, email);
        global.update_customer_where_id.setString(2, phonenumber);
        global.update_customer_where_id.setInt(3, data.getCustomer_id());
        global.update_customer_where_id.executeUpdate();
      }

      return error;
    } catch (Exception e) {
      System.err.println(e.getMessage());
      List<String> error = new ArrayList<String>();
      error.add("*Server error");
      return error;
    } finally {
      global.closeDBconnection();
    }
  }
コード例 #2
0
  public boolean verifiyPassword(String password) {
    try {
      global.openDBconnection();

      global.select_user_where_id_and_password.setInt(1, data.getUser_id());
      global.select_user_where_id_and_password.setString(2, password);
      ResultSet rs = global.select_user_where_id_and_password.executeQuery();
      if (!rs.next()) return false;

      return true;
    } catch (Exception e) {
      System.err.println(e.getMessage());
      return false;
    } finally {
      global.closeDBconnection();
    }
  }
コード例 #3
0
  public Customer get_customer() {
    try {
      global.openDBconnection();

      Customer customer = new Customer();
      int membership_id = 0;

      // set from user table
      customer.set_user(data.getUser_id(), data.getUsername());

      // set from customer table
      global.select_customer_where_id.setInt(1, data.getCustomer_id());
      ResultSet rs = global.select_customer_where_id.executeQuery();
      if (rs.next()) {
        customer.set_customer(
            data.getCustomer_id(),
            rs.getString("email"),
            new Date(rs.getTimestamp("registered").getTime()),
            rs.getBoolean("status"),
            rs.getString("phonenumber"),
            rs.getString("license_firstname"),
            rs.getString("license_middlename"),
            rs.getString("license_lastname"),
            rs.getDate("license_birthdate"),
            rs.getDate("license_expiration"),
            rs.getString("license_state"),
            rs.getString("license_no"),
            new Date(rs.getTimestamp("membership_exp").getTime()),
            rs.getDouble("balance"));

        membership_id = rs.getInt("membership_id");
      }

      // set from customer address table
      global.select_customer_address_where_customer_id.setInt(1, data.getCustomer_id());
      rs = global.select_customer_address_where_customer_id.executeQuery();
      if (rs.next()) {
        customer.set_customer_address(
            rs.getInt("id"),
            rs.getString("name"),
            rs.getString("street1"),
            rs.getString("street2"),
            rs.getString("city"),
            rs.getString("state"),
            rs.getString("zip"));
      }

      // set from customer creditcard table
      global.select_customer_creditcard_where_customer_id.setInt(1, data.getCustomer_id());
      rs = global.select_customer_creditcard_where_customer_id.executeQuery();
      if (rs.next()) {
        customer.set_customer_creditcard(
            rs.getInt("id"),
            rs.getString("no"),
            rs.getString("code"),
            rs.getDate("expires"),
            rs.getString("firstname"),
            rs.getString("lastname"),
            rs.getString("street1"),
            rs.getString("street2"),
            rs.getString("city"),
            rs.getString("state"),
            rs.getString("zip"));
      }

      // set from customer table
      if (membership_id == 0) {
        customer.set_membership(membership_id, "Free", "", 0.0, 0);
      } else {
        global.select_membership_where_id.setInt(1, membership_id);
        rs = global.select_membership_where_id.executeQuery();
        if (rs.next()) {
          customer.set_membership(
              membership_id,
              rs.getString("name"),
              rs.getString("description"),
              rs.getDouble("price"),
              rs.getInt("months"));
        }
      }

      return customer;
    } catch (Exception e) {
      System.err.println(e.getMessage());
      return new Customer();
    } finally {
      global.closeDBconnection();
    }
  }