public function getUserInfo() { if (!$this->_userInfo) { $this->_userInfo = UserInfo::model()->findByAttributes(array('email' => $this->username)); } return $this->_userInfo; }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate($Oauth = false) { $user = User::model()->findByAttributes(array('email' => $this->username)); if (!$user) { $this->errorCode = self::ERROR_USERNAME_INVALID; } elseif (!$user->comparePassword($this->password) && !$Oauth) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->errorCode = self::ERROR_NONE; $userInfo = UserInfo::model()->findByAttributes(array('email' => $this->username)); $userInfo->upTime = time(); $userInfo->save(); if ($userInfo->status == 'frozened') { throw new CHttpException(404, '错误!你的账号已被冻结.'); Yii::app()->end(); } //动态设为超级用户 if ($userInfo->isAdmin) { Yii::app()->user->setIsSuperuser(true); } // elseif($userInfo->inRoles(array('superAdmin','admin'))) Yii::app()->user->setIsSuperuser(true); $this->_id = $userInfo->id; //用setState添加的变量会加入Yii::app()->user的属性中 $this->setState('displayName', $userInfo->name); } return !$this->errorCode; }
static function fioById($id) { $model = UserInfo::model()->findByAttributes(['user_id' => $id]); if ($model) { return $model->surname . ' ' . $model->name . ' ' . $model->otchestvo; } }
public static function getInfo($uid, $type) { if (!$uid || !$type) { return false; } $info = UserInfo::model()->find('uid=:uid AND `name`=:name', array(':uid' => $uid, ':name' => $type)); return $info['value']; }
/** * @return bool * 检查数据库中是否有相同的用户名 */ public function check() { $user = UserInfo::model()->findByAttributes(array('user_name' => $this->username)); if (empty($user)) { return true; } else { return false; } }
public static function userExtraInfo($uid, $type = '') { $dataProvider = UserInfo::model()->findAllByAttributes(array('uid' => $uid)); $settings = CHtml::listData($dataProvider, 'name', 'value'); if (!empty($type)) { return $settings[$type]; } else { return $settings; } }
/** * 用户更新资料方法 * @param int $userId 用户的ID */ public function actionUpdate($userId) { // 实例化userInfo表的操作模型,调用updateByPK方法,很好用 $result = UserInfo::model()->updateByPk($userId, $_POST); $arr = $_POST; $arr['userId'] = $userId; // 将更新的数据再次赋给session $_SESSION['userMsg'] = $arr; // 跳转 $this->redirect("index.php?r=reaction/index/act/update/rst/{$result}"); }
/** * 检查用户是否存在 */ public function checkUser() { parent::beforeSave(); $user = UserInfo::model()->find("name='{$_POST['People']['userName']}'"); if (!isset($user)) { Yii::app()->user->setFlash('error', Yii::t('app', '用户不存在')); Yii::app()->controller->redirect(array('create', 'userName' => $_POST['People']['userName'])); } else { $this->userId = $user->id; return true; } }
public function login($identity, $duration = 0) { $result = parent::login($identity, $duration); if (!$result) { return $result; } $session = Yii::app()->getSession(); $info = UserInfo::model()->findByAttributes(['user_id' => $identity->getId()]); $session['username'] = $info->name; $session['surname'] = $info->surname; $session['otchestvo'] = $info->otchestvo; return $result; }
public function actionHovercard() { $user = UserInfo::model()->findByPk(Yii::app()->user->id); if (count($user->noticesUnisChecked) > 0) { $dataProvider = new CArrayDataProvider($user->noticesUnisChecked, array('keyField' => 'id')); Notice::model()->updateAll(array('isChecked' => 1), 'userId=:userId and isChecked=0', array('userId' => Yii::app()->user->id)); } else { $dataProvider = new CActiveDataProvider('Notice', array('criteria' => array('condition' => 'userId=' . Yii::app()->user->id, 'order' => 'addTime DESC'), 'pagination' => array('pageSize' => 5))); } Yii::app()->clientScript->scriptMap['*.js'] = false; $this->renderPartial('hovercard', array('dataProvider' => $dataProvider), false, true); // $this->renderPartial('hovercard',null,false,true ); }
public function actionIndex() { $this->pageTitle = "论坛首页"; // 论坛公告 $notices = Notices::model()->find(); // 讨论区类别 $bbsType = BbsType::model()->findAll(); // 话题计数 $bbsCount = BbsInfo::model()->count(); // 回帖计数 $revCount = Reviews::model()->count(); // 用户计数 $userCount = UserInfo::model()->count(); // 绑定数据 $data = array('notices' => $notices, 'bbsType' => $bbsType, 'bbsCount' => $bbsCount, 'revCount' => $revCount, 'userCount' => $userCount); $this->render('index', $data); }
/** * */ private function getNoticeParam($user) { $mailData['userName'] = $user['name']; // 未读的私信 $mailData['messageDataProvider'] = new CArrayDataProvider(UserInfo::model()->findByPk($user['id'])->messagesReceived, array('keyField' => 'id', 'pagination' => array('pageSize' => 1))); // 未读的提醒 $mailData['noticeDataProvider'] = new CArrayDataProvider(UserInfo::model()->findByPk($user['id'])->notices, array('keyField' => 'id', 'pagination' => array('pageSize' => 3))); // 如果没有私信和提醒 if (!count($mailData['messageDataProvider']->getData()) && !count($mailData['noticeDataProvider']->getData())) { $param['nullMailData'] = 1; return $param; } $param['to'] = '*****@*****.**'; $param['subject'] = 'test title'; $param['html'] = $this->renderPartial('_mail_template', $mailData, true); return $param; }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionGotoPhpems() { //取得user $user = UserInfo::model()->findByPk(Yii::app()->user->id); //准备参数 $userid = $user->id; //用户ID $username = $user->name; //用户名,GET方式过来 $email = $user->email; //邮箱,GET方式过来 $ts = time(); $sign = md5($userid . $username . $email . $this->_sc . $ts); //跳转到phpems $this->redirect($this->_phpemsurl . '&userid=' . $userid . '&username='******'&useremail=' . $email . '&ts=' . $ts . '&sign=' . $sign); //$this->redirect($this->_phpemsurl,array('exam-api-login'=>'','userid'=>$userid,'username'=>$username,'useremail'=>$email,'ts'=>$ts,'sign'=>$sign)); }
/** * 登录类登录方法 */ public function actionLogin() { $userName = $_POST['userName']; $password = md5($_POST['password']); // 实例化userinfo表并调用find方法 $userInfo = UserInfo::model()->find("userName='******' AND password='******'"); // 登录失败跳转提醒 if ($userInfo == NULL) { $result = 0; $this->redirect("index.php?r=reaction/index/act/login/rst/{$result}"); } else { // 将从数据库中获取到的userinfo赋给变量,将session转化成一维数组 $array = array('userId' => $userInfo['userId'], 'userName' => $userInfo['userName'], 'password' => $userInfo['password'], 'mailBox' => $userInfo['mailBox'], 'sex' => $userInfo['sex'], 'address' => $userInfo['address'], 'qq' => $userInfo['qq'], 'tel' => $userInfo['tel'], 'headPic' => $userInfo['headPic'], 'signWord' => $userInfo['signWord']); $_SESSION['userMsg'] = $array; // 登录成功跳转 $this->redirect("index.php?r=reaction/index/act/login/rst/1"); } }
/** * 为帖子投票 * Enter description here ... * @param unknown_type $postid * @param unknown_type $value */ public function actionAnswer($answerid, $value = 0) { //$vote = new PostVote; $vote = AnswerVote::model()->findByAttributes(array('userId' => Yii::app()->user->id, 'answerid' => $answerid)); $answer = Answer::model()->with('question')->findByPk($answerid); if ($vote && $vote->value == $value) { //再点击赞同(反对),即取消第一次投的赞同(反对) $result = $vote->delete(); } else { //赞同(反对)被第一次点击 $vote or $vote = new AnswerVote(); $vote->answerid = $answerid; $vote->value = $value; $vote->userId = Yii::app()->user->id; $vote->addTime = time(); $result = $vote->save(); //发送系统通知给回答主人 if ($answer->userId != $vote->userId) { $notice = new Notice(); $notice->type = 'vote_answer'; $notice->setData(array('voteId' => $vote->getPrimaryKey())); $notice->userId = $answer->userId; $notice->save(); } } if ($result) { // $question = Question::model()->findByPk($answer->question) //修改答案投票次数统计 $answer->voteupNum = $answer->voteupCount; $answer->count_votedown = $answer->votedownCount; $answer->save(); //修改问题投票次数统计 $answer->question->updateVoteCount(); //修改用户被赞数量 $user = UserInfo::model()->findByPk($answer->userId); $user->answerVoteupNum = $user->getAnswerVoteupCount(); $user->save(); $score = $answer->voteupCount - $answer->votedownCount; $this->renderPartial('result', array('score' => $score, 'voteupers' => $answer->voteupers)); } }
/** * 更新人员信息页面和处理方法 * @param integer $id 人员ID */ public function actionUpdate($id) { $model = $this->loadModel($id)->with(array('user')); $model->categorys = Category::model()->findAll('type="teacher"'); if (isset($_POST['People'])) { $user = UserInfo::model()->find("name='{$_POST['People']['userName']}'"); // 用户是否存在 if (!isset($user)) { Yii::app()->user->setFlash('error', '用户不存在'); } else { $model->userId = $user->id; $model->attributes = $_POST['People']; if ($model->save()) { Yii::app()->user->setFlash('success', '操作成功'); $this->redirect(array('index')); } else { Yii::app()->user->setFlash('error', '操作失败'); } } } $this->render('update', array('model' => $model)); }
/** * 注册类注册方法 */ public function actionReg() { // 判断密码和确认密码是否一致,也可用javascript做表单验证 $password = $_POST['password']; $checkPwd = $_POST['checkPwd']; if ($password != $checkPwd) { // 确认密码不一致跳转 $this->redirect('index.php?r=reaction/index/act/check/rst/0'); } // 实例化useInfo表用于保存 $model = UserInfo::model(); $model->userName = $_POST['userName']; $model->password = md5($_POST['password']); $model->mailBox = $_POST['mailBox']; $model->sex = $_POST['sex']; $model->tel = $_POST['tel']; $model->address = $_POST['address']; $model->qq = $_POST['qq']; $model->signWord = $_POST['signWord']; $result = $model->save(); // 跳转 $this->redirect('index.php?r=reaction/index/act/reg/rst/' . $result); }
<?php /* @var $this NoticeController */ /* @var $data Notice */ $user = UserInfo::model()->findByPk($data['userId']); if (!$user) { return false; } ?> <?php echo CHtml::link($user->name, $user->pageUrl); ?> <?php echo Yii::t('app', '关注了你'); ?>
public function actionAddMember($id) { if (isset($_POST['CourseMember'])) { $model = new CourseMember(); $model->attributes = $_POST['CourseMember']; $model->arrRoles = $_POST['CourseMember']['arrRoles']; $user = UserInfo::model()->findByAttributes(array('name' => $_POST['userName'])); if (!$user) { Yii::app()->user->setFlash('error', Yii::t('app', '抱歉!该用户不存在!')); } else { $model->userId = $user->id; $model->startTime = time(); $model->courseId = $id; if (CourseMember::model()->findByAttributes(array('userId' => $user->id, 'courseId' => $model->courseId))) { Yii::app()->user->setFlash('error', Yii::t('app', '该名成员已经存在!')); } else { if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('app', '添加成功')); } else { Yii::app()->user->setFlash('error', Yii::t('app', '抱歉,添加失败')); } } } $this->redirect(array('members', 'id' => $id)); } }
public function actionRecruitmentSource() { $recruitment_type = $_POST['TalentInfo']['recruitment_type']; if ($recruitment_type == 3) { $model = UserInfo::model()->findAll(); $result = CHtml::listData($model, 'id', 'name'); } else { $source = RecruitmentSource::model()->findAllByAttributes(array('type' => $recruitment_type)); $result = CHtml::listData($source, 'id', 'source'); } $result = array_values($result); echo json_encode($result); }
public function getRecruitmentSource() { if ($this->recruitment_type == 3) { return UserInfo::model()->getUserNames(); } $model = RecruitmentSource::model()->findAllByAttributes(array('type' => $this->recruitment_type)); $result = CHtml::listData($model, 'id', 'source'); return array_values($result); }
<?php /** * Created by PhpStorm. * User: l7861 * Date: 2016/1/4 * Time: 11:29 */ $form = $this->beginWidget('booster.widgets.TbActiveForm', array('id' => 'info-form', 'enableClientValidation' => true, 'type' => 'inline', 'htmlOptions' => array('class' => 'row', 'style' => 'float:left;width:100%;'))); echo $form->hiddenField($model, 'talent_id', array('value' => $data->id)); echo $form->hiddenField($model, 'next_option_id', array('value' => $next_option->id)); if (in_array($next_option->id, [2, 4])) { echo $form->select2Group($model, 'middleman', array('groupOptions' => array('class' => '', 'style' => 'width:28%;margin-left:15px;'), 'wrapperHtmlOptions' => array('class' => ''), 'widgetOptions' => array('data' => UserInfo::model()->getUserNames(), 'htmlOptions' => array('style' => 'width:100%;min-width:0px;', 'id' => 's2id_TalentStatus_middleman' . $data->id), 'asDropDownList' => true, 'options' => array('maximumSelectionSize' => 1, 'placeholder' => '面试人')))); echo $form->datetimePickerGroup($model, 'setup_datetime', array('groupOptions' => array('class' => '', 'style' => 'width:40%;margin-left:15px;'), 'widgetOptions' => array('htmlOptions' => array('style' => 'min-width:0px;width: 100%;', 'id' => 'TalentStatus_setup_datetime' . $data->id), 'options' => array('language' => 'zh-CN', 'format' => 'yyyy-mm-dd hh:ii', 'startDate' => '-0d -2w', 'endDate' => '+1m', 'todayHighlight' => true, 'minuteStep' => 30, 'startView' => 2, 'minViewMode' => 1, 'autoclose' => true)))); } elseif (in_array($next_option->id, [5])) { echo $form->hiddenField($model, 'middleman', array('value' => '')); echo CHtml::tag('div', array('class' => 'form-group', 'style' => 'width:29%;margin-left:15px;'), ''); echo $form->datetimePickerGroup($model, 'setup_datetime', array('groupOptions' => array('class' => '', 'style' => 'width:40%;margin-left:15px;'), 'widgetOptions' => array('htmlOptions' => array('style' => 'min-width:0px;width: 100%;', 'id' => 'TalentStatus_setup_datetime' . $data->id), 'options' => array('language' => 'zh-CN', 'format' => 'yyyy-mm-dd hh:ii', 'startDate' => '-0d -2w', 'endDate' => '+1m', 'todayHighlight' => true, 'minuteStep' => 30, 'startView' => 2, 'minViewMode' => 1, 'autoclose' => true)))); } ?> <div class=" form-group" style="float:right;vertical-align: middle;padding:2px;"> <?php $this->widget('booster.widgets.TbButton', array('buttonType' => 'submit', 'context' => 'primary', 'label' => $next_option->opt, 'size' => 'small', 'htmlOptions' => array('style' => ''))); ?> </div> <?php $this->endWidget();
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return UserInfo the loaded model * @throws CHttpException */ public function loadModel($id) { $model = UserInfo::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionChat($id) { $model = UserInfo::model()->findByPk($id); $this->render('chat', ['model' => $model]); }
public function actionCollect() { $courseDataProvider = Course::model()->getCollectionDataProvider(Yii::app()->user->id, 12); $user = UserInfo::model()->findByPk(Yii::app()->user->id); $this->render("index", array('user' => $user, 'courseDataProvider' => $courseDataProvider)); }
<?php $user = UserInfo::model()->findByPk(Yii::app()->user->id); ?> <div style="border-right:1px solid #ccc;padding-bottom:20px;"> <div style="padding:20px;"> <div class="dxd-user-face center"> <?php echo CHtml::image(Yii::app()->baseUrl . "/" . $user->face, $user->name, array('class' => 'dxd-user-face-large center', 'style' => 'width:130px;height:130px;display:block;')); ?> <?php // echo CHtml::link('设置个人头像',array('me/setFace','id'=>$user->id),array('class'=>'dxd-set-user-face dxd-fancy-elem')); ?> </div> <div style="text-align: center;font-size:1.6em;padding-top:10px;;"><?php echo $user->name; ?> </div> </div> <?php $this->widget('booster.widgets.TbMenu', array('type' => 'list', 'items' => array(array('label' => Yii::t('app', '提醒'), 'icon' => 'bell', 'url' => array('notice/index')), array('label' => Yii::t('app', '私信'), 'icon' => 'envelope', 'url' => array('message/index')), array('label' => Yii::t('app', '设置'), 'icon' => 'cog', 'url' => array('me/setBasic'))))); ?> </div> <?php /* $this->widget('application.extensions.fancybox.EFancyBox', array( 'target'=>'.dxd-fancy-elem', 'config'=>array( 'type'=>'iframe', 'hideOnOverlayClick'=>false,
<?php /** * @var CActiveDataProvider $dataProvider */ $cr = new CDbCriteria(); $cr->compare('type', QuestionModel::TYPE_NEW); if (UserModel::model()->client()->findByPk(Yii::app()->user->id) !== null) { $cr->compare('user_id', Yii::app()->user->id); } $cr->compare('status', QuestionModel::STATUS_NEW); $this->widget('zii.widgets.grid.CGridView', array('dataProvider' => new CActiveDataProvider('QuestionModel', ['criteria' => $cr]), 'htmlOptions' => ['class' => 'grid-view question'], 'selectionChanged' => "function(id){window.location='" . $this->createUrl('answer', array('id' => '')) . "' + \$.fn.yiiGridView.getSelection(id);}", 'columns' => [['name' => 'id', 'visible' => false], ['name' => 'user_id', 'value' => function ($data) { $user = UserInfo::model()->findByAttributes(['user_id' => $data->user_id]); if ($user) { return $user->fio(); } }], 'title', 'text', 'city', ['class' => 'CButtonColumn', 'template' => '{view}', 'viewButtonOptions' => ['title' => 'Просмотреть Вопрос'], 'viewButtonUrl' => 'Yii::app()->controller->createUrl("answer",array("id"=>$data->id))']]));
/** * MyGroupDataProvider */ public function getMyGroupDataProvider() { $myGroupDataProvider = null; if (!Yii::app()->user->isGuest) { $user = UserInfo::model()->findByPk(Yii::app()->user->id); $myGroupDataProvider = new CActiveDataProvider('Group', array('criteria' => array('join' => 'inner join ew_member m on m.memberableEntityId=t.entityId', 'condition' => 'm.userId=:userId', 'params' => array(':userId' => $user->id)), 'pagination' => array('pageSize' => 18))); } return $myGroupDataProvider; }
public function actionUserInfo() { $userid = Yii::app()->request->getQuery('userid'); $model = UserInfo::model()->find('userId=:userId', array(':userId' => $userid)); $this->render('view', array('model' => $model)); }
protected function connectSamebookUser($samebookUser) { $user = User::model()->findByAttributes(array('email' => $samebookUser['email'])); if (!$user) { $user = new User(); $user->email = $samebookUser['email']; $user->password = $samebookUser['pwd']; $user->salt = $samebookUser['salt']; if ($user->save()) { $userInfo = new UserInfo(); $userInfo->name = $samebookUser['username']; $userInfo->id = $user->getPrimaryKey(); $userInfo->email = $user->email; $userInfo->introduction = $samebookUser['bio']; $userInfo->addTime = time(); $userInfo->status = 'ok'; $userInfo->save(); } } $userInfo = UserInfo::model()->findByAttributes(array('email' => $samebookUser['email'])); //列入oauth表 if (empty($userInfo->oauth)) { $oauth = new Oauth(); $oauth->userId = $user->id; $oauth->save(); } $userInfo = UserInfo::model()->findByAttributes(array('email' => $samebookUser['email'])); //在oauth表中加sbid if (!$userInfo->oauth->sbid) { $userInfo->oauth->sbid = $samebookUser['userId']; $userInfo->oauth->save(); $userInfo = User::model()->findByAttributes(array('email' => $samebookUser['email'])); } }