Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.65 KB | None | 0 0
  1.         function authenticate($credentials) {
  2.                 $active_collab_auth = parent::authenticate($credentials);
  3.                 if (is_error($active_collab_auth)) {
  4.                         $email = trim(array_var($credentials, 'email'));
  5.                         $password = array_var($credentials, 'password');
  6.                         $postfields['email'] = $email;
  7.                         $postfields['password'] = $password;
  8.                         $remoteurl = "<<REDACTED>>";
  9.                         $ch = curl_init();
  10.                         curl_setopt($ch, CURLOPT_URL, $remoteurl);
  11.                         curl_setopt($ch, CURLOPT_POST, 1);
  12.                         curl_setopt($ch, CURLOPT_TIMEOUT, 100);
  13.                         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  14.                         curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  15.                         $data = curl_exec($ch);
  16.                         curl_close($ch);
  17.                         if ($data == "success") {
  18.                                 $user = Users::findByEmail($email);
  19.                                 if (!instance_of($user, 'User')) {
  20.                                         $randpass = self::genrandpass();
  21.                                         $user = new User();
  22.                                         $user->setAttributes(array(
  23.                                                         'role_id', '1',
  24.                                                         'email' => $email,
  25.                                                         'password' => $randpass,
  26.                                                         'first_name' => 'test',
  27.                                                         'last_name' => 'test'
  28.                                                         ));
  29.                                         $user->setCompanyId(21);
  30.                                         $user->resetToken();
  31.                                         $save = $user->save();
  32.                                         if (is_error($save)) {
  33.                                                 return new Error('Failed to create an account. Reason: '.$save->getMessage());
  34.                                         }
  35.                                 }
  36.                                 return $this->logUserIn($user, array(
  37.                                         'remember' => 0,
  38.                                         'new_visit' => true,
  39.                                         ));
  40.                         }
  41.                         return new Error('User is not registered');
  42.                 } else {
  43.                         return $active_collab_auth;
  44.                 }
  45.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement