<?php
/**
 * @link      http://www.u-bo.com
 * @copyright 南京友博网络科技有限公司 
 * @license   http://www.u-bo.com/license/
 */

namespace qcbase\controllers;

/**
 * 用户管理控制器
 * 
 * @author legendjw http://blog.u-bo.com
 * @since 0.1
 */
class UserController extends Controller
{
	public $model = '\common\models\User';

	public function actions() 
	{
		$actions = parent::actions();
		$actions['index']['with'] = ['dept'];
		$actions['create']['scenario'] = 'insert';
		$actions['view']['scenario'] = 'update';
		$actions['update']['scenario'] = 'update';
		return $actions;
	}
    
    public function actionInitPwd()
    {
        set_time_limit(0);
        $users = (new \yii\db\Query())->from('{{%user}}')->all();
        $conn = \Yii::$app->db;
        foreach ($users as $user) {
            if ($user['user_id'] == 1) {
                $conn->createCommand()->update('{{%user}}',[
                    'auth_key' => \Yii::$app->security->generateRandomString(),
                ], 'user_id = :user_id', [':user_id' => $user['user_id']])->execute();
            }
            else {
                $conn->createCommand()->update('{{%user}}',[
                    'password_hash' => \Yii::$app->security->generatePasswordHash('123456'),
                    'auth_key' => \Yii::$app->security->generateRandomString(),
                ], 'user_id = :user_id', [':user_id' => $user['user_id']])->execute();
            }
        }
        echo 'success';
    }


}
