Пример #1
0
 /**
  * @param $email
  * @param $password
  * @return User|null
  */
 public static function getUserByEmailAndPassword($email, $password)
 {
     $database = Application::getDatabase();
     $sth = $database->prepare("SELECT * FROM " . self::$tableName . " WHERE email = ? AND password = ? LIMIT 1");
     $sth->execute([$email, self::makePassword($password)]);
     $result = $sth->fetch(\PDO::FETCH_ASSOC);
     if (false !== $result) {
         return new User($result);
     }
 }
Пример #2
0
 public function login()
 {
     $user = new User(Application::getRequest()->all());
     $validateRules = ['email' => 'email', 'password' => 'required'];
     $errors = Validator::validate($user, $validateRules);
     if (empty($errors)) {
         $isSuccess = UserService::authorize($user->email, $user->password);
         $responseData = ['success' => $isSuccess];
         if ($isSuccess) {
             $responseData['redirect'] = '/';
         } else {
             $responseData['errors'] = [UserService::ERROR_USER_NOT_FOUND];
         }
         return Response::json($responseData);
     } else {
         return Response::json(['success' => false, 'errors' => $errors]);
     }
 }
Пример #3
0
<?php

$router = \Kernel\Application::getRouter();
$router->get('/', 'Controllers\\UserController@index');
$router->get('register', 'Controllers\\UserController@registerForm');
$router->post('register', 'Controllers\\UserController@register');
$router->get('register_done', 'Controllers\\UserController@registerDone');
$router->get('login', 'Controllers\\UserController@loginForm');
$router->post('login', 'Controllers\\UserController@login');
$router->get('logout', 'Controllers\\UserController@logout');
Пример #4
0
<?php

use Kernel\Application;
define("APP_DIR", dirname(__DIR__) . '/app/');
require dirname(APP_DIR) . "/kernel/autoload.php";
$app = Application::create();
$app->run();
Пример #5
0
 public function update()
 {
     $this->onBeforeUpdate();
     $allData = $this->getAllData();
     unset($allData['id']);
     $sets = [];
     foreach ($allData as $key => $value) {
         $sets[] = "{$key} = ?";
     }
     $query = "UPDATE {$this->tableName} SET " . join(', ', $sets) . " WHERE id = ?";
     $allData['id'] = $this->id;
     // add to end of list
     $sth = Application::getDatabase()->prepare($query);
     $sth->execute(array_values($allData));
     return 0 === intval($sth->errorCode());
 }