Proyectos de Subversion LeadersLinked - Services

Rev

Rev 255 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 255 Rev 345
Línea 1... Línea 1...
1
<?php
1
<?php
2
 
-
 
3
declare(strict_types=1);
2
declare(strict_types = 1);
4
 
-
 
5
namespace LeadersLinked\Authentication;
3
namespace LeadersLinked\Authentication;
Línea 6... Línea 4...
6
 
4
 
7
use Laminas\Authentication\Adapter\AdapterInterface as AuthAdapterInterface; 
5
use Laminas\Authentication\Adapter\AdapterInterface as AuthAdapterInterface;
8
use Laminas\Authentication\Result;
6
use Laminas\Authentication\Result;
9
use Laminas\Db\Adapter\AdapterInterface;
7
use Laminas\Db\Adapter\AdapterInterface;
10
use Laminas\Log\LoggerInterface;
8
use Laminas\Log\LoggerInterface;
11
use LeadersLinked\Model\User;
9
use LeadersLinked\Model\User;
12
use LeadersLinked\Mapper\UserMapper;
10
use LeadersLinked\Mapper\UserMapper;
Línea 13... Línea 11...
13
use LeadersLinked\Library\Functions;
11
use LeadersLinked\Library\Functions;
14
 
12
 
-
 
13
class AuthAdapter implements AuthAdapterInterface
15
class AuthAdapter implements AuthAdapterInterface
14
{
16
{
15
 
17
    /**
16
    /**
18
     *
17
     *
19
     * @var AdapterInterface
18
     * @var AdapterInterface
20
     */
19
     */
21
    private $adapter;
20
    private $adapter;
22
    
21
 
23
    /**
22
    /**
24
     * 
23
     *
25
     * @var string
24
     * @var string
26
     */
25
     */
27
    private $email;
26
    private $email;
28
    
27
 
29
    /**
28
    /**
30
     *
29
     *
31
     * @var string
30
     * @var string
32
     */
31
     */
33
    private $password;
32
    private $password;
34
    
33
 
35
    /**
34
    /**
36
     * 
35
     *
37
     * @var int
36
     * @var int
Línea 38... Línea -...
38
     */
-
 
39
    private $network_id;
37
     */
40
 
38
    private $network_id;
41
 
39
 
42
    /**
40
    /**
43
     * 
41
     *
44
     * @param AdapterInterface $adapter
42
     * @param AdapterInterface $adapter
45
     */
43
     */
46
    public function __construct(AdapterInterface $adapter)
44
    public function __construct(AdapterInterface $adapter)
Línea 47... Línea 45...
47
    {
45
    {
48
        $this->adapter = $adapter; 
46
        $this->adapter = $adapter;
49
    }
47
    }
50
 
48
 
51
    /**
49
    /**
52
     * 
50
     *
53
     * @param string $email
51
     * @param string $email
54
     * @param string $password
52
     * @param string $password
55
     * @param int $network_id
53
     * @param int $network_id
56
     */
54
     */
57
    public function setData($email, $password, $network_id)
55
    public function setData($email, $password, $network_id)
58
    {
-
 
59
        $this->email            = $email;
56
    {
60
        $this->password         = $password;
57
        $this->email = $email;
61
        $this->network_id       = $network_id;
58
        $this->password = $password;
62
 
59
        $this->network_id = $network_id;
63
    }
60
    }
64
    
61
 
65
    /**
62
    /**
66
     * 
63
     *
67
     * {@inheritDoc}
64
     * {@inheritdoc}
68
     * @see \Laminas\Authentication\Adapter\AdapterInterface::authenticate()
65
     * @see \Laminas\Authentication\Adapter\AdapterInterface::authenticate()
69
     */
66
     */
70
    public function authenticate()
67
    public function authenticate()
71
    {
68
    {
72
        $userMapper = UserMapper::getInstance($this->adapter);
69
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
70
        $user = $userMapper->fetchOneByEmailAndNetworkId($this->email, $this->network_id);
73
        $user = $userMapper->fetchOneByEmailAndNetworkId($this->email, $this->network_id);
71
 
74
        
72
        if (! $user) {
75
        if(!$user) {
-
 
76
            return new Result(Result::FAILURE_IDENTITY_NOT_FOUND, null, ['ERROR_USER_NOT_FOUND']);
73
            return new Result(Result::FAILURE_IDENTITY_NOT_FOUND, null, [
77
            
74
                'ERROR_USER_NOT_FOUND'
78
        }
75
            ]);
-
 
76
        }
-
 
77
 
79
        
78
        if (User::EMAIL_VERIFIED_NO == $user->email_verified) {
80
 
79
            return new Result(Result::FAILURE_UNCATEGORIZED, null, [
81
        if(User::EMAIL_VERIFIED_NO == $user->email_verified) {
80
                'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED'
-
 
81
            ]);
-
 
82
        }
82
            return new Result(Result::FAILURE_UNCATEGORIZED, null, ['ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED']);
83
        if (User::BLOCKED_YES == $user->blocked) {
83
        }
84
            return new Result(Result::FAILURE_UNCATEGORIZED, null, [
84
        if(User::BLOCKED_YES == $user->blocked) {
85
                'ERROR_USER_IS_BLOCKED'
85
            return new Result(Result::FAILURE_UNCATEGORIZED, null, ['ERROR_USER_IS_BLOCKED']);
86
            ]);
86
        }
-
 
87
        
-
 
88
        if(User::STATUS_INACTIVE == $user->status) {
87
        }
89
            return new Result(Result::FAILURE_UNCATEGORIZED, null, ['ERROR_USER_IS_INACTIVE']);
-
 
90
        } 
88
 
91
        
-
 
92
        if(User::REQUEST_ACCESS_PENDING == $user->request_access) {
-
 
93
            return new Result(Result::FAILURE_UNCATEGORIZED, null, ['ERROR_USER_REQUEST_ACCESS_IS_PENDING']);
-
 
94
        }
-
 
95
        
89
        if (User::STATUS_INACTIVE == $user->status) {
96
        
-
 
Línea 97... Línea 90...
97
        if(User::REQUEST_ACCESS_REJECTED == $user->request_access) {
90
            return new Result(Result::FAILURE_UNCATEGORIZED, null, [
-
 
91
                'ERROR_USER_IS_INACTIVE'
-
 
92
            ]);
-
 
93
        }
-
 
94
 
-
 
95
        if (User::REQUEST_ACCESS_PENDING == $user->request_access) {
-
 
96
            return new Result(Result::FAILURE_UNCATEGORIZED, null, [
-
 
97
                'ERROR_USER_REQUEST_ACCESS_IS_PENDING'
-
 
98
            ]);
-
 
99
        }
98
            return new Result(Result::FAILURE_UNCATEGORIZED, null, ['ERROR_USER_REQUEST_ACCESS_IS_REJECTED']);
100
 
-
 
101
        if (User::REQUEST_ACCESS_REJECTED == $user->request_access) {
-
 
102
            return new Result(Result::FAILURE_UNCATEGORIZED, null, [
99
        }
103
                'ERROR_USER_REQUEST_ACCESS_IS_REJECTED'
100
        
104
            ]);
101
 
105
        }
102
        if(!password_verify($this->password, $user->password) && !(md5($this->password) == $user->password)) 
106
 
103
        {
107
        if (! password_verify($this->password, $user->password) && ! (md5($this->password) == $user->password)) {
104
            $max_login_attempt = 3;
108
            $max_login_attempt = 3;
105
            $user->login_attempt++;
109
            $user->login_attempt ++;
106
            if($user->login_attempt >= $max_login_attempt) {
110
            if ($user->login_attempt >= $max_login_attempt) {
107
                $user->blocked = User::BLOCKED_YES;
111
                $user->blocked = User::BLOCKED_YES;
-
 
112
            }
-
 
113
            $user->password_xmpp = '';
108
            }
114
            $userMapper->update($user);
109
            $user->password_xmpp = '';
115
            if (User::BLOCKED_YES == $user->blocked) {
110
            $userMapper->update($user);
116
                return new Result(Result::FAILURE_CREDENTIAL_INVALID, null, [
-
 
117
                    'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED'
-
 
118
                ]);
111
            if(User::BLOCKED_YES == $user->blocked) {
119
            } else {
112
                return new Result(Result::FAILURE_CREDENTIAL_INVALID, null, ['ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED']);
120
                $available_attempts = $max_login_attempt - $user->login_attempt;
113
            } else {
121
                return new Result(Result::FAILURE_CREDENTIAL_INVALID, null, [
114
                $available_attempts = $max_login_attempt - $user->login_attempt;
122
                    'ERROR_ENTERED_PASS_INCORRECT_' . $available_attempts
115
                return new Result(Result::FAILURE_CREDENTIAL_INVALID, null, ['ERROR_ENTERED_PASS_INCORRECT_' . $available_attempts]);
123
                ]);
116
            }
-
 
117
        } else {
124
            }
118
            $user->login_attempt = 0;
125
        } else {
119
            $userMapper->update($user);
126
            $user->login_attempt = 0;
120
        }
127
            $userMapper->update($user);
121
        
128
        }
122
                        
129
 
123
        $data = [
130
        $data = [
124
            'user_id' => $user->id,
131
            'user_id' => $user->id,
125
            'device_id' => '',
132
            'device_id' => ''
126
        ];
133
        ];