PageRenderTime 37ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/Server/tomcat/WEB-INF/src/com/drhelper/android/service/LoginService.java

https://github.com/weiganyi/dr-helper
Java | 55 lines | 39 code | 10 blank | 6 comment | 6 complexity | 4b231e126e732c4cabc8b828b0397153 MD5 | raw file
  1. package com.drhelper.android.service;
  2. import javax.servlet.http.HttpSession;
  3. import com.alibaba.fastjson.JSON;
  4. import com.drhelper.android.bean.com.Login;
  5. import com.drhelper.common.db.DBManager;
  6. import com.drhelper.common.entity.User;
  7. public class LoginService extends Service {
  8. public String doAction(HttpSession session, String reqBody) {
  9. Login reqLogin = null;
  10. Login respLogin = null;
  11. String respBody = null;
  12. //parse the body
  13. try{
  14. reqLogin = JSON.parseObject(reqBody, Login.class);
  15. }catch (Exception e) {
  16. System.out.println("LoginService.doAction(): json parse body failure: " + e.getMessage());
  17. return respBody;
  18. }
  19. //check the input param
  20. String userName = reqLogin.getUserName();
  21. String userPasswd = reqLogin.getUserPasswd();
  22. if (userName.length() == 0 || userPasswd.length() == 0) {
  23. System.out.println("LoginService.doAction(): userName or userPasswd is null");
  24. return respBody;
  25. }
  26. respLogin = new Login();
  27. //check the user and passwd
  28. DBManager db = new DBManager();
  29. User user = db.getUser(userName, userPasswd);
  30. if (user == null) {
  31. respLogin.setResult(false);
  32. respBody = JSON.toJSONString(respLogin);
  33. return respBody;
  34. }
  35. //create the resp object
  36. respLogin.setUserName(user.getUser_name());
  37. respLogin.setUserPasswd(user.getUser_passwd());
  38. respLogin.setResult(true);
  39. //save the user name
  40. session.setAttribute("id", user.getUser_name());
  41. //serialize the object
  42. respBody = JSON.toJSONString(respLogin);
  43. return respBody;
  44. }
  45. }