Guest User

Login.java

a guest
Jul 9th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. package com.prgguru.jersey;
  2.  
  3. import javax.ws.rs.GET;
  4. import javax.ws.rs.Path;
  5. import javax.ws.rs.Produces;
  6. import javax.ws.rs.QueryParam;
  7. import javax.ws.rs.core.MediaType;
  8. //Path: http://localhost/<appln-folder-name>/login
  9. @Path("/login")
  10.  
  11. public class Login {
  12.     // HTTP Get Method
  13.     @GET
  14.     // Path: http://localhost/<appln-folder-name>/login/dologin
  15.     @Path("/dologin")
  16.     // Produces JSON as response
  17.     @Produces(MediaType.APPLICATION_JSON)
  18.     // Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?email=abc&password=xyz
  19.     //http://localhost:8080/useraccount/login/[email protected]&password=827ccb0eea8a706c4c34a16891f84e7b
  20.     public String doLogin(@QueryParam("email") String uemail, @QueryParam("password") String pwd){
  21.         String response = "";
  22.         if(checkCredentials(uemail, pwd)){
  23.             response = Utility.constructJSON("login",true);
  24.         }else{
  25.             response = Utility.constructJSON("login", false, "Incorrect Email or Password");
  26.         }
  27.     return response;        
  28.     }
  29.  
  30.     /**
  31.      * Method to check whether the entered credential is valid
  32.      *
  33.      * @param uemail
  34.      * @param pwd
  35.      * @return
  36.      */
  37.     private boolean checkCredentials(String uemail, String pwd){
  38.         System.out.println("Inside checkCredentials");
  39.         boolean result = false;
  40.         if(Utility.isNotNull(uemail) && Utility.isNotNull(pwd)){
  41.             try {
  42.                 result = DBConnection.checkLogin(uemail, pwd);
  43.                 //System.out.println("Inside checkCredentials try "+result);
  44.             } catch (Exception e) {
  45.                 // TODO Auto-generated catch block
  46.                 //System.out.println("Inside checkCredentials catch");
  47.                 result = false;
  48.             }
  49.         }else{
  50.             //System.out.println("Inside checkCredentials else");
  51.             result = false;
  52.         }
  53.  
  54.         return result;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment