Current Path : /data/web/virtuals/51568/virtual/www/subdom/srps/src/models/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/srps/src/models/User.php |
<?php namespace app\models; use app\Application; use app\UserModel; class User extends UserModel { const STATUS_INACTIVE = 0; const STATUS_ACTIVE = 1; public $FIRSTNAME; public $LASTNAME; public $EMAIL; public $STATUS = self::STATUS_INACTIVE; public $PASSWORD; public $CONFIRMPASSWORD; public $ID; public $SHOWPASSWORD = false; public function tableName(): string { return "users"; } public function primaryKey(): string { return 'ID'; } public function save() { $this->STATUS = self::STATUS_INACTIVE; $this->PASSWORD = \password_hash($this->PASSWORD, PASSWORD_DEFAULT); return parent::save(); } public function rules(): array { return [ 'FIRSTNAME' => [self::RULE_REQUIRED], 'LASTNAME' => [self::RULE_REQUIRED], 'EMAIL' => [self::RULE_REQUIRED, self::RULE_EMAIL , [self::RULE_UNIQUE, 'class' => self::class]], 'PASSWORD' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 8], [self::RULE_MAX, 'max' => 24]], 'CONFIRMPASSWORD' => [self::RULE_REQUIRED, [self::RULE_MATCH, 'match' => 'PASSWORD']] ]; } public function types(): array { return [ 'FIRSTNAME' => self::FIELD_INPUT, 'LASTNAME' => self::FIELD_INPUT, 'EMAIL' => self::FIELD_INPUT, 'PASSWORD' => self::FIELD_INPUT, 'CONFIRMPASSWORD' => self::FIELD_INPUT, 'SHOWPASSWORD' => self::FIELD_CHECKBOX, ]; } public function attributes(): array { return ['FIRSTNAME', 'LASTNAME', 'EMAIL', 'PASSWORD', 'STATUS']; } public function labels(): array { return [ 'FIRSTNAME' => 'Jméno', 'LASTNAME' => 'Příjmení', 'EMAIL' => 'Email', 'PASSWORD' => 'Heslo', 'CONFIRMPASSWORD' => 'Potvrzení hesla', 'SHOWPASSWORD' => 'ukaž heslo', ]; } public function getDisplayName(): string { return $this->FIRSTNAME . ' ' . $this->LASTNAME; } public function getShowState() { return $this->SHOWPASSWORD; } public function passChange() { if (!trim($this->PASSWORD)) { $this->addError('PASSWORD', 'Heslo musíš vyplnit.'); return false; } if (!trim($this->CONFIRMPASSWORD)) { $this->addError('CONFIRMPASSWORD', 'Potvrzení hesla musíš vyplnit.'); return false; } if ($this->PASSWORD !== $this->CONFIRMPASSWORD) { $this->addError('CONFIRMPASSWORD', 'Heslo a jeho potvrzení se neshodují.'); return false; } $passHash = password_hash($this->PASSWORD, PASSWORD_DEFAULT); $id = Application::$app->session->get("iduser"); Application::$app->db->query("UPDATE `users` SET `password`=:pass WHERE `id`=:id", $passHash, $id); return true; } }