Advertisement
Guest User

Untitled

a guest
Jan 30th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
  2.  
  3. private final String Puserid;
  4. private final String Ppassword;
  5. protected ProgressDialog progressDialog;
  6.  
  7. UserLoginTask(String[] params) {
  8. Puserid = params[0];
  9. Ppassword = params[1];
  10. }
  11.  
  12. @Override
  13. protected Boolean doInBackground(Void... params) {
  14. // TODO: attempt authentication against a network service.
  15. try {
  16.  
  17. Thread.sleep(2000);
  18. String data = URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode(this.Puserid, "UTF-8") + "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(this.Ppassword, "UTF-8");
  19. URLConnection conn = new URL("http://....../login").openConnection();
  20. conn.setDoOutput(true);
  21. OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  22. wr.write(data);
  23. wr.flush();
  24. BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  25. String line = rd.readLine();
  26. if (line == null) {
  27. wr.close();
  28. rd.close();
  29. return Boolean.valueOf(true);
  30. } else if (line.equals("fail")) {
  31. return Boolean.valueOf(false);
  32. } else {
  33. pmSessionManagement.createLoginSession(line);
  34. Log.d("user",line);
  35. //pmSessionManagement.createLoginSession(line);
  36. return Boolean.valueOf(true);
  37. }
  38. } catch (SocketTimeoutException e) {
  39. runOnUiThread(new Runnable() {
  40. public void run() {
  41. Toast.makeText(getApplicationContext(), "Check internet connection and try again", 0).show();
  42. }
  43. });
  44. return Boolean.valueOf(false);
  45. } catch (Exception e2) {
  46. e2.printStackTrace();
  47. }
  48. return null;
  49. }
  50. protected void onPreExecute() {
  51. super.onPreExecute();
  52. progressDialog = ProgressDialog.show(PMLoginActivity.this, "Please wait...", "Fetching data", true, false);
  53. mLoginFormView.setVisibility(View.GONE);
  54.  
  55. }
  56.  
  57. @Override
  58. protected void onPostExecute(final Boolean success) {
  59. mAuthTask = null;
  60. progressDialog.dismiss();
  61.  
  62. if (success) {
  63. Intent intent = new Intent(PMLoginActivity.this, PMDashboardActivity.class);
  64. startActivity(intent);
  65. } else {
  66. openDialog();
  67. mLoginFormView.setVisibility(View.VISIBLE);
  68. }
  69. }
  70.  
  71. public function login()
  72. {
  73. $returnArr = $this->resp_arr;
  74. if ($this->request->is('post')) {
  75. $data = (array)$this->request->input('json_decode');
  76. if($data['login_type'] == 'form'){
  77. $this->request->data['email'] = $data['email'];
  78. $this->request->data['password'] = $data['password'];
  79. $user = $this->Auth->identify();
  80.  
  81. if ($user) {
  82. if(!$user['status']){
  83. $returnArr['status_message'] = "Your account has been deactivated please contact admin.";
  84. }
  85. else{
  86. $returnArr['auth_token'] = $user['uniq_id'];
  87. $user['mobile'] = $user['mobile'];
  88. $returnArr['user_details'] = $user;
  89. $returnArr['status_code'] = 200;
  90. $returnArr['status'] = "OK";
  91. $returnArr['status_message'] = "Login successful";
  92. $this->setDevice($data, $user['id']);
  93. }
  94.  
  95. } else {
  96. $returnArr['status_message'] = "Invalid username or password, try again.";
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement