Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.prgguru.jersey;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.Produces;
- import javax.ws.rs.QueryParam;
- import javax.ws.rs.core.MediaType;
- //Path: http://localhost/<appln-folder-name>/login
- @Path("/login")
- public class Login {
- // HTTP Get Method
- @GET
- // Path: http://localhost/<appln-folder-name>/login/dologin
- @Path("/dologin")
- // Produces JSON as response
- @Produces(MediaType.APPLICATION_JSON)
- // Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?email=abc&password=xyz
- //http://localhost:8080/useraccount/login/[email protected]&password=827ccb0eea8a706c4c34a16891f84e7b
- public String doLogin(@QueryParam("email") String uemail, @QueryParam("password") String pwd){
- String response = "";
- if(checkCredentials(uemail, pwd)){
- response = Utility.constructJSON("login",true);
- }else{
- response = Utility.constructJSON("login", false, "Incorrect Email or Password");
- }
- return response;
- }
- /**
- * Method to check whether the entered credential is valid
- *
- * @param uemail
- * @param pwd
- * @return
- */
- private boolean checkCredentials(String uemail, String pwd){
- System.out.println("Inside checkCredentials");
- boolean result = false;
- if(Utility.isNotNull(uemail) && Utility.isNotNull(pwd)){
- try {
- result = DBConnection.checkLogin(uemail, 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment