Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
- private final String Puserid;
- private final String Ppassword;
- protected ProgressDialog progressDialog;
- UserLoginTask(String[] params) {
- Puserid = params[0];
- Ppassword = params[1];
- }
- @Override
- protected Boolean doInBackground(Void... params) {
- // TODO: attempt authentication against a network service.
- try {
- Thread.sleep(2000);
- String data = URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode(this.Puserid, "UTF-8") + "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(this.Ppassword, "UTF-8");
- URLConnection conn = new URL("http://....../login").openConnection();
- conn.setDoOutput(true);
- OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
- wr.write(data);
- wr.flush();
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line = rd.readLine();
- if (line == null) {
- wr.close();
- rd.close();
- return Boolean.valueOf(true);
- } else if (line.equals("fail")) {
- return Boolean.valueOf(false);
- } else {
- pmSessionManagement.createLoginSession(line);
- Log.d("user",line);
- //pmSessionManagement.createLoginSession(line);
- return Boolean.valueOf(true);
- }
- } catch (SocketTimeoutException e) {
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(getApplicationContext(), "Check internet connection and try again", 0).show();
- }
- });
- return Boolean.valueOf(false);
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- return null;
- }
- protected void onPreExecute() {
- super.onPreExecute();
- progressDialog = ProgressDialog.show(PMLoginActivity.this, "Please wait...", "Fetching data", true, false);
- mLoginFormView.setVisibility(View.GONE);
- }
- @Override
- protected void onPostExecute(final Boolean success) {
- mAuthTask = null;
- progressDialog.dismiss();
- if (success) {
- Intent intent = new Intent(PMLoginActivity.this, PMDashboardActivity.class);
- startActivity(intent);
- } else {
- openDialog();
- mLoginFormView.setVisibility(View.VISIBLE);
- }
- }
- public function login()
- {
- $returnArr = $this->resp_arr;
- if ($this->request->is('post')) {
- $data = (array)$this->request->input('json_decode');
- if($data['login_type'] == 'form'){
- $this->request->data['email'] = $data['email'];
- $this->request->data['password'] = $data['password'];
- $user = $this->Auth->identify();
- if ($user) {
- if(!$user['status']){
- $returnArr['status_message'] = "Your account has been deactivated please contact admin.";
- }
- else{
- $returnArr['auth_token'] = $user['uniq_id'];
- $user['mobile'] = $user['mobile'];
- $returnArr['user_details'] = $user;
- $returnArr['status_code'] = 200;
- $returnArr['status'] = "OK";
- $returnArr['status_message'] = "Login successful";
- $this->setDevice($data, $user['id']);
- }
- } else {
- $returnArr['status_message'] = "Invalid username or password, try again.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement