-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
437 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
// fill database name | ||
$connectString = 'mysql:host=localhost;dbname='; | ||
$username = 'root'; | ||
$password = ''; // fill your pswd | ||
?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
class UserController extends Controller | ||
{ | ||
private $_model; | ||
public function loadModel() | ||
{ | ||
if($this->_model===null) | ||
{ | ||
if(isset($_GET['id'])) | ||
{ | ||
$this->_model=User::model()->findByPk($_GET['id']); | ||
} | ||
if($this->_model===null) | ||
throw new CHttpException(404,'The requested page does not exist.'); | ||
} | ||
return $this->_model; | ||
} | ||
public function filters() | ||
{ | ||
return array( | ||
'accessControl', // perform access control for CRUD operations | ||
); | ||
} | ||
|
||
/** | ||
* Specifies the access control rules. | ||
* This method is used by the 'accessControl' filter. | ||
* @return array access control rules | ||
*/ | ||
public function accessRules() | ||
{ | ||
return array( | ||
array('allow', // allow authenticated users to access all actions | ||
'users'=>array('@'), | ||
), | ||
array('deny', // deny all users | ||
'users'=>array('*'), | ||
), | ||
); | ||
} | ||
public function actionChangePwd() | ||
{ | ||
$model=new FormUserChangePassword; | ||
|
||
if(isset($_POST['ajax']) && $_POST['ajax']==='change-pwd-form') | ||
{ | ||
echo CActiveForm::validate($model); | ||
Yii::app()->end(); | ||
} | ||
|
||
if(isset($_POST['FormUserChangePassword']) ) | ||
{ | ||
$model->attributes=$_POST['FormUserChangePassword']; | ||
$user = User::model()->findByPk(Yii::app()->user->id); | ||
$user->password = $user->hashPassword($model->newPassword, $user->salt); | ||
|
||
if ( $model->validate() && $user->update(array('password')) ) { | ||
Yii::app()->user->setFlash('success', "√ 修改已保存"); | ||
$this->redirect(array('user/view', 'id' => $user->id)); | ||
} | ||
} | ||
|
||
$this->render('changePwd', array( 'model'=>$model,)); | ||
} | ||
|
||
public function actionIndex() | ||
{ | ||
$this->render('index',array( | ||
)); | ||
} | ||
public function actionView() | ||
{ | ||
$model= $this->loadModel(); | ||
$this->render('view',array( | ||
'model'=>$model, | ||
)); | ||
} | ||
|
||
// Uncomment the following methods and override them if needed | ||
/* | ||
public function filters() | ||
{ | ||
// return the filter configuration for this controller, e.g.: | ||
return array( | ||
'inlineFilterName', | ||
array( | ||
'class'=>'path.to.FilterClass', | ||
'propertyName'=>'propertyValue', | ||
), | ||
); | ||
} | ||
public function actions() | ||
{ | ||
// return external action classes, e.g.: | ||
return array( | ||
'action1'=>'path.to.ActionClass', | ||
'action2'=>array( | ||
'class'=>'path.to.AnotherActionClass', | ||
'propertyName'=>'propertyValue', | ||
), | ||
); | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
class FormUserChangePassword extends CFormModel | ||
{ | ||
public $oldPassword; | ||
public $newPassword; | ||
public $newPasswordReinput; | ||
|
||
|
||
public function rules() | ||
{ | ||
return array( | ||
array('oldPassword, newPassword, newPasswordReinput', 'required'), | ||
array( 'oldPassword', 'authOldPassword'), | ||
array( 'newPasswordReinput', 'authNewPasswordReinput'), | ||
); | ||
} | ||
|
||
public function attributeLabels() | ||
{ | ||
return array( | ||
'oldPassword' => '原密码', | ||
'newPassword' => '新密码', | ||
'newPasswordReinput' => '再次输入新密码', | ||
); | ||
} | ||
|
||
public function authOldPassword($attribute,$params) | ||
{ | ||
$user = User::model()->findByPk(Yii::app()->user->id); | ||
if (!$user->validatePassword($this->oldPassword)) | ||
$this->addError('oldPassword','密码输入错误'); | ||
} | ||
|
||
public function authNewPasswordReinput($attribute,$params) | ||
{ | ||
$user = User::model()->findByPk(Yii::app()->user->id); | ||
if ($this->newPassword != $this->newPasswordReinput) | ||
$this->addError('newPasswordReinput','两次密码输入不一致'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.