facut pana la video 7
This commit is contained in:
@@ -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'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user