/**
  * @param LoginBindingModel $model
  * @return string
  */
 function login(LoginBindingModel $model) : string
 {
     $db = SimpleDB::getInstance('conference_scheduler');
     $result = $db->prepare("SELECT\r\n                                id, username, password\r\n                                FROM users\r\n                                WHERE username = ?");
     $result->execute([$model->getPassword()]);
     if ($result->affectedRows() > 0) {
         $userRow = $result->fetch();
         if (password_verify($model->getPassword(), $userRow['password'])) {
             return $userRow['id'];
         }
     }
     throw new \Exception("Wrong username or password.");
 }
 /**
  * @NotLogged
  * @param LoginBindingModel $model
  * @throws \Exception
  */
 public function login(LoginBindingModel $model)
 {
     $this->db->prepare("SELECT id, username\n                                FROM users\n                                WHERE username = ? AND password = ?", array($model->getUsername(), $model->getPassword()));
     $response = $this->db->execute()->fetchRowAssoc();
     if (!$response) {
         throw new \Exception('No user matching provided username and password!', 400);
     }
     $id = $response['id'];
     $username = $response['username'];
     $this->session->_login = $id;
     $this->session->_username = $model->getUsername();
     $this->session->escapedUsername = $username;
     $this->redirect('/');
 }
 /**
  * @NotLogged
  * @param LoginBindingModel $model
  * @throws \Exception
  */
 public function login(LoginBindingModel $model)
 {
     $this->db->prepare("SELECT u.id as id, u.username as username, r.name as roleName\n                            FROM users u\n                            JOIN user_roles ur\n                            ON u.id = ur.user_id\n                            JOIN roles r\n                            ON ur.role_id = r.id\n                            WHERE username = ?", array($model->getUsername()));
     $response = $this->db->execute()->fetchRowAssoc();
     $id = $response['id'];
     $username = $response['username'];
     $role = $response['roleName'];
     $_SESSION['role'] = $role;
     $this->db->prepare("SELECT u.id as id, u.username as username, u.password as pass\n                            FROM users u\n                            WHERE username = ? AND password = ?", array($model->getUsername(), $model->getPassword()));
     $response = $this->db->execute()->fetchRowAssoc();
     if (!$response) {
         throw new \Exception('No user matching provided username or password!', 400);
     }
     $id = $response['id'];
     $username = $response['username'];
     $this->session->_login = $id;
     $this->session->_username = $model->getUsername();
     $this->session->escapedUsername = $username;
     $_SESSION['username'] = $response['username'];
     $_SESSION['role'] = $role;
     $this->redirect('/');
 }
 /**
  * @BindingModels LoginBindingModel
  */
 public function loginpost(LoginBindingModel $bindingModel)
 {
     if ($bindingModel) {
         $user = new User();
         $user->setUsername($bindingModel->getUsername());
         $user->setPassword($bindingModel->getPassword());
         $this->initLogin($user->getUsername(), $user->getPassword());
     }
 }