facut pana la video 7

This commit is contained in:
Cerbu Andrei Mihnea
2023-05-10 00:47:48 +03:00
parent 1abdc313f4
commit 90f12ab916
40 changed files with 1644 additions and 41 deletions
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace app\models;
use app\core\DbModel;
class User extends DbModel{
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 1;
CONST STATUS_DELETED = 2;
public string $firstname = '';
public string $lastname = '';
public int $status = self::STATUS_INACTIVE;
public string $email = '';
public string $password = '';
public function save(){
$this->status = self::STATUS_INACTIVE;
$this->password = password_hash($this->password, PASSWORD_DEFAULT);
return parent::save();
}
public function tableName(): string{
return 'users';
}
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' => 15]]
];
}
public function primaryKey(): string{
return 'id';
}
public function labels():array {
return [
'firstname' => 'First name',
'lastname' => 'Last name',
'email' => 'Email',
'password' => 'Password'
];
}
public function attributes(): array{
return ['firstname', 'lastname', 'email', 'password', 'status'];
}
}