Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function authenticate($credentials) {
- $active_collab_auth = parent::authenticate($credentials);
- if (is_error($active_collab_auth)) {
- $email = trim(array_var($credentials, 'email'));
- $password = array_var($credentials, 'password');
- $postfields['email'] = $email;
- $postfields['password'] = $password;
- $remoteurl = "<<REDACTED>>";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $remoteurl);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 100);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
- $data = curl_exec($ch);
- curl_close($ch);
- if ($data == "success") {
- $user = Users::findByEmail($email);
- if (!instance_of($user, 'User')) {
- $randpass = self::genrandpass();
- $user = new User();
- $user->setAttributes(array(
- 'role_id', '1',
- 'email' => $email,
- 'password' => $randpass,
- 'first_name' => 'test',
- 'last_name' => 'test'
- ));
- $user->setCompanyId(21);
- $user->resetToken();
- $save = $user->save();
- if (is_error($save)) {
- return new Error('Failed to create an account. Reason: '.$save->getMessage());
- }
- }
- return $this->logUserIn($user, array(
- 'remember' => 0,
- 'new_visit' => true,
- ));
- }
- return new Error('User is not registered');
- } else {
- return $active_collab_auth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement