Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. public class Credentials {
  2. private int cred_id;
  3. private String cred_user_name;
  4. private String cred_password;
  5. private String cred_token;
  6.  
  7. public Credentials(int cred_id, String cred_user_name,
  8. String cred_password, String cred_token) {
  9. this.cred_id = cred_id;
  10. this.cred_user_name = cred_user_name;
  11. this.cred_password = cred_password;
  12. this.cred_token = cred_token;
  13. }
  14.  
  15. public int getCred_id() {
  16. return cred_id;
  17. }
  18.  
  19. public void setCred_id(int cred_id) {
  20. this.cred_id = cred_id;
  21. }
  22.  
  23. public String getCred_user_name() {
  24. return cred_user_name;
  25. }
  26.  
  27. public void setCred_user_name(String cred_user_name) {
  28. this.cred_user_name = cred_user_name;
  29. }
  30.  
  31. public String getCred_password() {
  32. return cred_password;
  33. }
  34.  
  35. public void setCred_password(String cred_password) {
  36. this.cred_password = cred_password;
  37. }
  38.  
  39. public String getCred_token() {
  40. return cred_token;
  41. }
  42.  
  43. public void setCred_token(String cred_token) {
  44. this.cred_token = cred_token;
  45. }
  46.  
  47. public class ValidateUser {
  48. @POST
  49. @Produces(MediaType.APPLICATION_JSON)
  50. @Consumes(MediaType.APPLICATION_JSON)
  51. public String validateUser(Credentials credentials) {
  52. System.out.println("Going to validate the user" + credentials);
  53. String username = credentials.getCred_user_name();
  54. String password = credentials.getCred_password();
  55. CredentialsAccessor ca = new CredentialsAccessor();
  56. long count = 0;
  57. count = ca.authenticateUser(username, password);
  58. if (count > 0) {
  59. JSONObject jObject = new JSONObject();
  60. try {
  61. jObject.put("valid", "true");
  62. return jObject.toString();
  63. } catch (JSONException e) {
  64. e.printStackTrace();
  65. return "{'valid':'error'}";
  66. }
  67. } else {
  68. JSONObject jObject = new JSONObject();
  69. try {
  70. jObject.put("valid", "false");
  71. return jObject.toString();
  72. } catch (JSONException e) {
  73. e.printStackTrace();
  74. return "{'valid':'error'}";
  75. }
  76. }
  77. }
  78.  
  79. [Please web.xml][3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement