Merge branch 'master' of https://git.mcnd.ca/mcndave/ulmus-user
This commit is contained in:
		
						commit
						10ad77d607
					
				@ -22,7 +22,7 @@ class User {
 | 
				
			|||||||
    public ? string $lastName;
 | 
					    public ? string $lastName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @Field("size" => 150)
 | 
					     * @Field("size" => 255)
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public string $email;
 | 
					    public string $email;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -30,15 +30,13 @@ class Authenticate {
 | 
				
			|||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
        $this->session = $session;
 | 
					        $this->session = $session;
 | 
				
			||||||
        $this->cookie = $cookie;
 | 
					        $this->cookie = $cookie;
 | 
				
			||||||
        $this->authenticationEvent = $authenticationEvent ?: function(bool $authenticated, string $message, ? User $user, array $data = []) : bool {return false;} ;
 | 
					        $this->authenticationEvent = $authenticationEvent ?: function(bool $authenticated, string $message, ? User $user, array $data = []) : ? bool {return null;} ;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function rememberMe(\Ulmus\Repository $repository) : ? User
 | 
					    public function rememberMe(\Ulmus\Repository $repository) : ? User
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $logUser = function(int $id) use ($repository) {
 | 
					        $logUser = function(? int $id) use ($repository) {
 | 
				
			||||||
            if ( null === ( $user = $repository->loadFromPk($id) ) ) {
 | 
					            if ( $id === null || null === ( $user = $repository->loadFromPk($id) ) ) {
 | 
				
			||||||
                $this->logout();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                throw new \Exception("User not found.");
 | 
					                throw new \Exception("User not found.");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -63,7 +61,7 @@ class Authenticate {
 | 
				
			|||||||
        $this->session->destroy();
 | 
					        $this->session->destroy();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function authenticate(\Ulmus\Repository $repository, array $userLogin, ? string $password) : User
 | 
					    public function authenticate(\Ulmus\Repository $repository, array $userLogin, string $password) : User
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        foreach($userLogin as $field => $value) {
 | 
					        foreach($userLogin as $field => $value) {
 | 
				
			||||||
            $repository->or($field, $value);
 | 
					            $repository->or($field, $value);
 | 
				
			||||||
@ -78,23 +76,35 @@ class Authenticate {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ( $this->user->isLoaded() && ( call_user_func_array($this->authenticationEvent, [ false, 'verifyPassword', $this->user, [ 'password' => $password ] ]) || $this->user->verifyPassword($password) ) ) {
 | 
					        if ( ! $this->user->isLoaded() ) {
 | 
				
			||||||
            $this->user->logged = true;
 | 
					            call_user_func_array($this->authenticationEvent, [ false, 'userNotFound', $this->user, [ 'user_login' => $userLogin, 'password' => $password ] ]);
 | 
				
			||||||
 | 
					 | 
				
			||||||
            if ( $this->session ) {
 | 
					 | 
				
			||||||
                $this->session->set("user.id", $this->user->id);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if ( $this->cookie ) {
 | 
					 | 
				
			||||||
                $this->cookie->set("user.id", $this->user->id);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            call_user_func_array($this->authenticationEvent, [ true, 'success', $this->user ]);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            $this->user->logged = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            call_user_func_array($this->authenticationEvent, [ false, 'invalidPassword', $this->user ]);
 | 
					        if ($this->user->isLoaded()) {
 | 
				
			||||||
 | 
					            $response = call_user_func_array($this->authenticationEvent, [ false, 'verifyPassword', $this->user, [ 'password' => $password ] ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ( $response !== null ? $response : $this->user->verifyPassword($password) ) {
 | 
				
			||||||
 | 
					                $this->user->logged = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if ( $this->session ) {
 | 
				
			||||||
 | 
					                    $this->session->set("user.id", $this->user->id);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if ( $this->cookie ) {
 | 
				
			||||||
 | 
					                    $this->cookie->set("user.id", $this->user->id);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                call_user_func_array($this->authenticationEvent, [ true, 'success', $this->user ]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else {
 | 
				
			||||||
 | 
					                $this->user->logged = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                call_user_func_array($this->authenticationEvent, [ false, 'invalidPassword', $this->user ]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( ! $this->user->isLoaded() ) {
 | 
				
			||||||
 | 
					            call_user_func_array($this->authenticationEvent, [ false, 'authenticationFailed', $this->user, [ 'user_login' => $userLogin, 'password' => $password ] ]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        return $this->user;
 | 
					        return $this->user;
 | 
				
			||||||
@ -113,7 +123,7 @@ class Authenticate {
 | 
				
			|||||||
            $this->cookie->delete('user.id');
 | 
					            $this->cookie->delete('user.id');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->user && $this->user->logged = false;
 | 
					        $this->user->logged = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user