Qiang Xue
12 years ago
8 changed files with 91 additions and 9 deletions
@ -0,0 +1,37 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* @link http://www.yiiframework.com/ |
||||||
|
* @copyright Copyright (c) 2008 Yii Software LLC |
||||||
|
* @license http://www.yiiframework.com/license/ |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace app\models; |
||||||
|
|
||||||
|
use yii\base\Model; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Qiang Xue <qiang.xue@gmail.com> |
||||||
|
* @since 2.0 |
||||||
|
*/ |
||||||
|
class LoginForm extends Model |
||||||
|
{ |
||||||
|
public $username; |
||||||
|
public $password; |
||||||
|
|
||||||
|
public function rules() |
||||||
|
{ |
||||||
|
return array( |
||||||
|
array('username', 'required'), |
||||||
|
array('password', 'required'), |
||||||
|
array('password', 'validatePassword'), |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
public function validatePassword() |
||||||
|
{ |
||||||
|
$user = User::findByUsername($this->username); |
||||||
|
if (!$user && $user->validatePassword($this->password)) { |
||||||
|
$this->addError('password', 'Incorrect username or password.'); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
<h1>Login</h1> |
||||||
|
|
||||||
|
<p>Please fill out the following fields to login:</p> |
||||||
|
|
||||||
|
<?php $form = $this->beginWidget('yii\widgets\ActiveForm', array('method' => 'put')); ?> |
||||||
|
|
||||||
|
<?php $this->endWidget(); ?> |
Loading…
Reference in new issue