Beispiel #1
0
  /**
   * Method to check whether the entered credential is valid
   *
   * @param uname
   * @param pwd
   * @return
   */
  private boolean checkCredentials(String uname, String pwd) {
    System.out.println("Inside checkCredentials");
    boolean result = false;
    if (Utility.isNotNull(uname) && Utility.isNotNull(pwd)) {
      try {
        result = DBConnection.checkLogin(uname, pwd);
        // System.out.println("Inside checkCredentials try "+result);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        // System.out.println("Inside checkCredentials catch");
        result = false;
      }
    } else {
      // System.out.println("Inside checkCredentials else");
      result = false;
    }

    return result;
  }
 // HTTP Get Method
 @GET
 // Path: http://localhost/<appln-folder-name>/enterGPA/doenterGPA
 @Path("/doenterGPA")
 // Produces JSON as response
 @Produces(MediaType.APPLICATION_JSON)
 private int enterGPA(String name, String GPA) {
   System.out.println("Inside EnterGPA");
   int result = 3;
   if (Utility.isNotNull(name) && Utility.isNotNull(GPA)) {
     try {
       if (DBConnection.insertGPAInfo(name, GPA)) {
         result = 0;
       }
     } catch (Exception e) {
       // TODO Auto-generated catch block
       System.out.println("Inside enterGPA catch" + e);
       result = 1;
     }
   }
   return result;
 }
 /**
  * Method gets triggered when Register button is clicked
  *
  * @param view
  */
 public void registerUser(View view) {
   // Get NAme ET control value
   String name = nameET.getText().toString();
   // Get Email ET control value
   String email = emailET.getText().toString();
   // Get Password ET control value
   String password = pwdET.getText().toString();
   // Instantiate Http Request Param Object
   RequestParams params = new RequestParams();
   // When Name Edit View, Email Edit View and Password Edit View have values other than Null
   if (Utility.isNotNull(name) && Utility.isNotNull(email) && Utility.isNotNull(password)) {
     // When Email entered is Valid
     if (Utility.validate(email)) {
       // Put Http parameter name with value of Name Edit View control
       params.put("name", name);
       // Put Http parameter username with value of Email Edit View control
       params.put("username", email);
       // Put Http parameter password with value of Password Edit View control
       params.put("password", password);
       // Invoke RESTful Web Service with Http parameters
       invokeWS(params);
     }
     // When Email is invalid
     else {
       Toast.makeText(getApplicationContext(), "Please enter valid email", Toast.LENGTH_LONG)
           .show();
     }
   }
   // When any of the Edit View control left blank
   else {
     Toast.makeText(
             getApplicationContext(),
             "Please fill the form, don't leave any field blank",
             Toast.LENGTH_LONG)
         .show();
   }
 }