验证是否是注册用户,管理员是不是 这么写的? [ 新手入门 ]
UserIdentity.php
[attach]564[/attach] [attach]565[/attach]
共 8 条回复
-
-
啊,我没想到有这么缺点啊,接受批评
UserIdentity.php
<?php class UserIdentity extends CUserIdentity { private $_id; public function authenticate() { $_identity='guest'; $username=strtolower($this->username);//$this->username为用户输入的用户名 $user=Users::model()->find('LOWER(username)=?', array($username));//查库中是否有此用户 if($user===null)//没有,返回无此用户错 $this->errorCode=self::ERROR_USERNAME_INVALID; else if(!$user->validatePassword($this->password))//有,再验证密码 $this->errorCode=self::ERROR_PASSWORD_INVALID;//密码错误 else {//密码正确 $this->_id=$user->id; if ($user->identity==='admin') { $this->setState('identity', 'admin');//设置用户身份,管理员 }else { $this->setState('identity', 'user');//设置用户身份,普通用户 } $this->errorCode=self::ERROR_NONE; } return $this->errorCode===self::ERROR_NONE; } public function getId() { return $this->_id; } }
column3.php
<?php $this->beginContent('//layouts/main'); ?> <table style="margin-top:3px;width:1000px;border:0;"> <tr> <td style="width:5px;"> </td> <!-- 左边栏 开始 --> <td valign='top' style="width:210px;"> <!--左边栏的登录表单 开始--> <?php $identity=Yii::app()->user->getState('identity');//取用户身份 ?> <table style="border:0;" cellpadding=0 cellspacing=0> <tr> <td> <!--如果是普通用户登录--> <?php if ($identity==='user') {?> <div style='background:url(<?php echo Yii::app()->request->baseUrl; ?>/images/t_login.jpg) no-repeat;width:210px;height:70px;'></div> <div class='side_content'> <br /> <b><?php echo yii::app()->user->getName();?></b>,欢迎您回来! <?php echo CHtml::link('退出', array('site/logout'),array('style'=>'color:red;'));?><br /> <br /><br /> </div> <?php } ?> <!--如果是管理员登录了--> <?php if ($identity==='admin'): ?> <?php endif; ?> 您好,管理员
-
-
-
-
-
-
webyjh
注册时间:2011-12-12
最后登录:2016-10-06
在线时长:1小时45分
最后登录:2016-10-06
在线时长:1小时45分
- 粉丝2
- 金钱1090
- 威望0
- 积分1100