1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- /**
- * FecShop file.
- *
- * @link http://www.fecshop.com/
- * @copyright Copyright (c) 2016 FecShop Software LLC
- * @license http://www.fecshop.com/license/
- */
- namespace fecadmin\models\AdminUser;
- use Yii;
- use fecadmin\models\AdminUser;
- use yii\base\Model;
- /**
- * @author Terry Zhao <2358269014@qq.com>
- * @since 1.0
- */
- class AdminUserResetPassword extends Model{
-
- public $username;
- public $old_password;
- public $new_password;
- public $password_repeat;
- private $_admin_user;
-
- public function rules()
- {
- return [
- [['old_password', 'new_password','password_repeat'], 'required'],
- // ['username', 'validateLogin'],
- ['new_password', 'validateNewPassword'],
- ['old_password', 'validateOldPassword'],
- ];
- }
-
- public function getAdminUser(){
- if($this->_admin_user === null){
- $this->_admin_user = Yii::$app->user->identity;
- }
- return $this->_admin_user;
- }
-
-
- public function updatePassword(){
- $AdminUser = $this->getAdminUser();
- $AdminUser->setPassword($this->new_password);
- $AdminUser->save();
- }
-
-
- public function validateNewPassword($attribute,$params){
-
- if (!$this->hasErrors()) {
-
- if($this->new_password != $this->password_repeat){
- $this->addError($attribute, 'Password and PasswordRepeat is Inconsistent!');
- return;
- }
-
- }
- }
-
- public function validateOldPassword($attribute,$params){
-
- if (!$this->hasErrors()) {
- $username = $this->getAdminUser()->username;
- $AdminUser = AdminUser::findByUsername($username);
- if($AdminUser->validatePassword($this->old_password)){
-
- }else{
- $this->addError($attribute, 'old password is not right!');
- }
- }
- }
-
- }
|