72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
||
namespace app\models\common;
|
||
use think\response\Redirect;
|
||
use Yii;
|
||
use yii\base\Model;
|
||
use yii\db\ActiveRecord;
|
||
class Authcode extends ActiveRecord{
|
||
public $username;
|
||
public $password;
|
||
public $rememberMe;
|
||
//重命名表名 %为前缀名
|
||
public static function tableName(){
|
||
return '{{%authcode}}';
|
||
}
|
||
|
||
|
||
|
||
public function attributeLabels(){
|
||
return [
|
||
'id' => 'ID',//id为数据表中的字段名,ID 为表单显示的描述
|
||
'auth_code' => '网站激活码',
|
||
'domain_url' => '域名地址',
|
||
'dt_operdate' => '绑定的时间',
|
||
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @return bool
|
||
* 设置登录方法
|
||
*/
|
||
public function login(){
|
||
$user=Users::find()->where(['username'=>$this->username])->asarray()->one();//判断用户名是否正确
|
||
if(is_null($user)) {
|
||
Yii::$app->session->setFlash('错误提示','用户名输入有误');
|
||
// echo $this->addError('username','用户名输入有误');
|
||
return false;
|
||
}else{
|
||
//判断密码是否正确
|
||
if(getPassword($this->password)==$user['password']){
|
||
$session = \Yii::$app->session;
|
||
if(!$session->get('we7_user')){
|
||
$session->set('we7_user',$user);
|
||
}
|
||
return true;
|
||
}else{
|
||
// Yii::$app->session->setFlash('错误提示','密码输入有误');
|
||
//// echo $this->addError('password','密码输入有误');
|
||
echo "<script>alert('用户密码错误');window.history.back(-1);</script>";die;
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//根据authcode返回用户的数据
|
||
public function getById($code){
|
||
$re=Authcode::find()->where(['auth_code'=>$code])->one();
|
||
return $re;
|
||
}
|
||
|
||
//根据authcode和域名返回用户的数据
|
||
public function getByName($code,$url){
|
||
$re=Authcode::find()->where(['auth_code'=>$code,'auth_code'=>$url]);
|
||
// 输出SQL语句
|
||
//echo $re->createCommand()->getRawSql();die;
|
||
$users = $re->asarray()->one();
|
||
// var_dump($users);die;
|
||
return $users;
|
||
}
|
||
|
||
} |