Login form PHP: <?php namespace app\models; use Yii; use yii\base\Model; class LoginForm extends Model { public $username; public $password; public $rememberMe = true; public $captcha; private $_user = false; public function rules(){ return [ // username and password are both required [['username', 'password'], 'required'], // rememberMe must be a boolean value ['rememberMe', 'boolean'], // password is validated by validatePassword() ['password', 'validatePassword'], ]; } public function attributeLabels(){ return [ 'username' => 'Email', 'password' => 'Password' ]; } public function validatePassword($attribute, $params){ if (!$this->hasErrors()) { $user = $this->getUser(); if (!$user || !$user->validatePassword($this->password)) { $this->addError($attribute, 'Incorrect username or password.'); } } } public function login() { if ($this->validate()) { return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0); } return false; } public function getUser() { if ($this->_user === false) { $this->_user = Users::findByUsername($this->username); } return $this->_user; } } Register form PHP: <?php namespace app\models; use Yii; use yii\base\Model; class RegisterForm extends \yii\base\Model { public $email; public $password; public $password2; public $phone; private $_identity; public $rememberMe; public function rules() { return array( array('password, email, phone, password2', 'required'), ); } public function attributeLabels(){ return array( 'password' => 'Password', 'password2' => 'Confirm password ', 'email' => 'Email' ); } } login form PHP: <?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\captcha\Captcha; $this->title = 'Login'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="site-login"> <h1><?= Html::encode($this->title) ?></h1> <p>Please fill out the following fields to login:</p> <a href="index.php?r=site%2Frecovery">recovery password</a> <?php if(isset($user->errors) && !empty($user->errors)):?> <?php foreach($user->errors as $errors):?> <?php foreach($errors as $error):?> <?php echo $error;?> <br> <?php endforeach;?> <?php endforeach;?> <?php endif;?> <?php $form = ActiveForm::begin([ 'id' => 'login-form', 'layout' => 'horizontal', 'fieldConfig' => [ 'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label'], ], ]); ?> <?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?> <?= $form->field($model, 'password')->passwordInput() ?> <?= $form->field($model, 'rememberMe')->checkbox([ 'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>", ]) ?> <div class="form-group"> <div class="col-lg-offset-1 col-lg-11"> <?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> </div> </div> <?php ActiveForm::end(); ?> <div class="col-lg-offset-1" style="color:#999;"> You may login with <strong>admin/admin</strong> or <strong>demo/demo</strong>.<br> To modify the username/password, please check out the code <code>app\models\User::$users</code>. </div> </div> register form PHP: <?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; $this->title = 'Register'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="site-login"> <h1><?= Html::encode($this->title) ?></h1> <p>Please fill out the following fields to register:</p> <?php if(isset($user->errors) && !empty($user->errors)):?> <?php foreach($user->errors as $errors):?> <?php foreach($errors as $error):?> <?php echo $error;?> <br> <?php endforeach;?> <?php endforeach;?> <?php endif;?> <?php $form = ActiveForm::begin([ 'id' => 'register-form', 'layout' => 'horizontal', 'fieldConfig' => [ 'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label'], ], ]); ?> <?= $form->field($model, 'email')->textInput(['autofocus' => true]) ?> <?= $form->field($model, 'phone')->textInput(['maxlength'=>11,'minlenght' => 11]) ?> <?= $form->field($model, 'password')->passwordInput() ?> <?= $form->field($model, 'password2')->passwordInput() ?> <div class="form-group"> <div class="col-lg-offset-1 col-lg-11"> <?= Html::submitButton('Register', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> </div> </div> <?php ActiveForm::end(); ?> <div class="col-lg-offset-1" style="color:#999;"> You may login with <strong>admin/admin</strong> or <strong>demo/demo</strong>.<br> To modify the username/password, please check out the code <code>app\models\User::$users</code>. </div> </div> reset password PHP: <?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; $this->title = 'Register'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="site-login"> <h1><?= Html::encode($this->title) ?></h1> <p>Please fill out the following fields to register:</p> <?php if(isset($user->errors) && !empty($user->errors)):?> <?php foreach($user->errors as $errors):?> <?php foreach($errors as $error):?> <?php echo $error;?> <br> <?php endforeach;?> <?php endforeach;?> <?php endif;?> <?php $form = ActiveForm::begin([ 'id' => 'register-form', 'layout' => 'horizontal', 'fieldConfig' => [ 'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label'], ], ]); ?> <?= $form->field($user, 'password')->passwordInput() ?> <?= $form->field($user, 'password2')->passwordInput() ?> <div class="form-group"> <div class="col-lg-offset-1 col-lg-11"> <?= Html::submitButton('Change password', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> </div> </div> <?php ActiveForm::end(); ?> <div class="col-lg-offset-1" style="color:#999;"> You may login with <strong>admin/admin</strong> or <strong>demo/demo</strong>.<br> To modify the username/password, please check out the code <code>app\models\User::$users</code>. </div> </div> recovery PHP: <?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; $this->title = 'Recovery password'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="site-login"> <h1><?= Html::encode($this->title) ?></h1> <p>Please fill out the following fields to login:</p> <?php $form = ActiveForm::begin([ 'id' => 'recovery-form', 'layout' => 'horizontal', 'fieldConfig' => [ 'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label'], ], ]); ?> <?= $form->field($model, 'email')->textInput(['autofocus' => true]) ?> <div class="form-group"> <div class="col-lg-offset-1 col-lg-11"> <?= Html::submitButton('Recovery password', ['class' => 'btn btn-primary', 'name' => 'recovery-button']) ?> </div> </div> <?php ActiveForm::end(); ?> </div> settings PHP: <?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; $this->title = 'Settings'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="site-login"> <h1><?= Html::encode($this->title) ?></h1> <p>Please fill out the following fields to change settings:</p> <?php if(isset($user->errors) && !empty($user->errors)):?> <?php foreach($user->errors as $errors):?> <?php foreach($errors as $error):?> <?php echo $error;?> <br> <?php endforeach;?> <?php endforeach;?> <?php endif;?> <?php $form = ActiveForm::begin([ 'id' => 'settings-form', 'layout' => 'horizontal', 'fieldConfig' => [ 'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label'], ], ]); ?> <?= $form->field($model, 'phone')->textInput(['maxlength' => 11,'minlenght' => 11]) ?> <?= $form->field($model, 'password')->passwordInput() ?> <?= $form->field($model, 'password2')->passwordInput() ?> <div class="form-group"> <div class="col-lg-offset-1 col-lg-11"> <?= Html::submitButton('Save', ['class' => 'btn btn-primary', 'name' => 'settings-button']) ?> </div> </div> <?php ActiveForm::end(); ?> <div class="col-lg-offset-1" style="color:#999;"> You may login with <strong>admin/admin</strong> or <strong>demo/demo</strong>.<br> To modify the username/password, please check out the code <code>app\models\User::$users</code>. </div> </div>