backend-01

ref: master

app/services/AuthService.php


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

require_once __DIR__ . '/../daos/UserDAO.php';

class AuthService {
  private $userDAO;

  public function __construct() {
    $this->userDAO = new UserDAO();
  }

  public function login($email, $password) {
    $user = $this->userDAO->findByEmail($email);

    if ($user && $user->validatePassword($password)) {
      return $user;
    }

    return null;
  }

  public function register($userName, $email, $password) {
    $user = new User(null, $userName, $email, $password);

    return $this->userDAO->create($user);
  }
}