<?php namespace myresto\models;use Yii;use yii\base\Model;use common\models\User;class ChangePasswordForm extends Model{public $current_password;public $new_password;public $new_password_repeat;public function rules(){return [ [['current_password','new_password','new_password_repeat'],'required'],[['current_password','new_password','new_password_repeat'],'string','min'=>6],['new_password_repeat','compare','compareAttribute'=>'new_password'],];}public function attributeLabels(){return [ 'current_password'=>'Password Lama','new_password'=>'Password Baru','new_password_repeat'=>'Ulangi Password Baru',];}public function changePassword(){if($this->validate()){$user=User::findIdentity(Yii::$app->user->identity->id);if(!$user->validatePassword($this->current_password)){$this->addError('current_password','Password tidak sesuai.');return false;}else{$user->setPassword($this->new_password);if($user->save())return true;else return false;}}}}