Current Path : /data/web/virtuals/51568/virtual/www/subdom/srps/src/models/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/srps/src/models/LoginForm.php |
<?php namespace app\models; use app\Model; use app\Application; class LoginForm extends Model { public $EMAIL= ''; public $PASSWORD = ''; public function rules(): array { return [ 'EMAIL' => [self::RULE_REQUIRED, self::RULE_EMAIL], 'PASSWORD' => [self::RULE_REQUIRED] ]; } public function labels(): array { return [ 'EMAIL' => 'Uživatelské jméno (=email)', 'PASSWORD' => 'Heslo' ]; } public function types(): array { return [ 'EMAIL' => self::FIELD_INPUT, 'PASSWORD' => self::FIELD_INPUT, ]; } public function login() { if (!trim($this->EMAIL)) { $this->addError('EMAIL', 'Email musíš vyplnit.'); return false; } if (!trim($this->PASSWORD)) { $this->addError('PASSWORD', 'Heslo musíš vyplnit.'); return false; } $user = Application::$app->db->fetchOne("SELECT * FROM `users` WHERE `email` = :email", $this->EMAIL); if (!$user) { $this->addError('EMAIL', 'Neexistuje uživatel s tímto emailem'); return false; } if ($user->aktivni_pm == '0') { $this->addError('EMAIL', 'Tento uživatel nemá povoleno se přihlásit.'); return false; } if (!password_verify($this->PASSWORD, $user->password)) { $this->addError('PASSWORD', 'Chybné heslo'); return false; } Application::$app->session->set('iduser', $user->id); Application::$app->session->set('spravce', $user->spravce === '1'); Application::$app->session->set('username', mb_substr($user->prijmeni, 0, 12) . ' ' . mb_substr($user->jmeno, 0, 1) . '.'); return true; } }