113 lines
3.4 KiB
PHP
Executable File
113 lines
3.4 KiB
PHP
Executable File
<?php
|
|
namespace backend\models;
|
|
|
|
use Yii;
|
|
use backend\models\AuthAssignment;
|
|
|
|
class Adminer extends \yii\db\ActiveRecord
|
|
{
|
|
|
|
public $password;
|
|
|
|
const STATUS_DELETE = 0;
|
|
const STATUS_ACTIVE = 10;
|
|
|
|
public static $statusTexts = [
|
|
self::STATUS_DELETE => '禁用',
|
|
self::STATUS_ACTIVE => '启用',
|
|
];
|
|
|
|
public static $statusStyles = [
|
|
self::STATUS_DELETE => 'label-warning',
|
|
self::STATUS_ACTIVE => 'label-info',
|
|
];
|
|
|
|
public static function tableName() {
|
|
return '{{%c_adminer}}';
|
|
}
|
|
|
|
public function rules() {
|
|
return [
|
|
//[['username', 'email'], 'required'],
|
|
//[['username'], 'string', 'length' => [6, 15]],
|
|
//[['password'], 'required', 'on' => ['create']],
|
|
//[['reg_ip', 'last_login_time', 'last_login_ip'], 'integer'],
|
|
//[['auth_key'], 'string', 'length' => 32],
|
|
//[['username', 'email'], 'unique'],
|
|
//[['email'], 'email'],
|
|
//['status', 'default', 'value' => self::STATUS_ACTIVE],
|
|
//['status', 'in', 'range' => [
|
|
// self::STATUS_ACTIVE, self::STATUS_DELETE
|
|
//]],
|
|
|
|
[['username','email'], 'required'],
|
|
//[['role', 'status', 'created_at', 'updated_at'], 'integer'],
|
|
[['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
|
|
[['auth_key'], 'string', 'max' => 32],
|
|
|
|
];
|
|
}
|
|
|
|
public function attributeLabels() {
|
|
return [
|
|
'id' => 'ID',
|
|
'username' => Yii::t('common' ,'Username'),
|
|
'auth_key' => Yii::t('common' ,'Password'),
|
|
'auth_key' => Yii::t('common' ,'Password'),
|
|
'password_hash' => 'Password Hash',
|
|
'email' => Yii::t('common' ,'Email'),
|
|
'mobile' => Yii::t('common' ,'Mobile'),
|
|
'reg_ip' => 'Reg Ip',
|
|
'last_login_time' => '最后登录时间',
|
|
'last_login_ip' => '最后登录IP',
|
|
'status' => '状态',
|
|
'created_at' => 'Created At',
|
|
'updated_at' => 'Updated At',
|
|
'user_role' => '所属角色',
|
|
'role' => Yii::t('common' ,'Role'),
|
|
];
|
|
}
|
|
|
|
//获取所有用户
|
|
public function get_all_user(){
|
|
$user = Yii::$app->db->createCommand('select * from '. tableName())->queryAll();
|
|
return $user;
|
|
}
|
|
|
|
public function getUsergrouplist()
|
|
{
|
|
/**
|
|
* 第一个参数为要关联的字表模型类名称,
|
|
*第二个参数指定 通过子表的 customer_id 去关联主表的 id 字段
|
|
*/
|
|
return $this->hasMany(AuthAssignment::className(), ['user_id' => 'id']);
|
|
}
|
|
public function getUsergroup()
|
|
{
|
|
/**
|
|
* 第一个参数为要关联的字表模型类名称,
|
|
*第二个参数指定 通过子表的 customer_id 去关联主表的 id 字段
|
|
*/
|
|
return $this->hasOne(AuthAssignment::className(), ['user_id' => 'id']);
|
|
}
|
|
|
|
/**
|
|
* Generates password hash from password and sets it to the model
|
|
*
|
|
* @param string $password
|
|
*/
|
|
public function setPassword($password)
|
|
{
|
|
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
|
|
}
|
|
|
|
/**
|
|
* Generates "remember me" authentication key
|
|
*/
|
|
public function generateAuthKey()
|
|
{
|
|
$this->auth_key = Yii::$app->security->generateRandomString();
|
|
}
|
|
|
|
}
|