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
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace app\models;
use app\core\Application;
use app\core\Model;
class LoginForm extends Model{
public string $email = '';
public string $password = '';
public function rules(): array{
return [
'email' => [self::RULE_REQUIRED, self::RULE_EMAIL],
'password' => [self::RULE_REQUIRED]
];
}
public function labels():array {
return [
'email' => 'Email',
'password' => 'Password'
];
}
public function login(){
$user = new User();
$user = $user->findOne(['email' => $this->email]);
if(!$user){
$this->addError('email', 'User does not exist with this email');
return false;
}
if(!password_verify($this->password, $user->password)){
$this->addError('password', 'Incorrect password');
return false;
}
return Application::$app->login($user);
}
}