当前位置: 首页>>代码示例>>PHP>>正文


PHP User::model方法代码示例

本文整理汇总了PHP中Model\User::model方法的典型用法代码示例。如果您正苦于以下问题:PHP User::model方法的具体用法?PHP User::model怎么用?PHP User::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Model\User的用法示例。


在下文中一共展示了User::model方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionPost

 public function actionPost()
 {
     $data = $this->getData('user');
     if (!isset($data['username'])) {
         throw new BadRequest("USERNAME_REQUIRED");
     }
     if (!isset($data['password'])) {
         throw new BadRequest("PASSWORD_REQUIRED");
     }
     $username = $data['username'];
     $md5Password = md5($data['password']);
     $user = User::model($this->getManager()->getComponent('db'));
     $where = "`username`='{$username}' AND `password`='{$md5Password}'";
     $userinfo = $user->where($where)->find();
     if ($userinfo != null) {
         session_start();
         $roleId = $userinfo['role_id'];
         $role = Role::model($this->getManager()->getComponent('db'));
         $roleinfo = $role->where("`id`={$userinfo['role_id']}")->find();
         $_SESSION['userid'] = $userinfo['id'];
         $_SESSION['username'] = $userinfo['username'];
         $_SESSION['authtype'] = $userinfo['authtype'];
         $_SESSION['userrole'] = $roleinfo['name'];
         $_SESSION['permission'] = Json::toArray($roleinfo['permission']);
         return array('result' => array('success' => true, 'key' => base64_encode($username . ',' . $md5Password . ',' . session_id())));
     } else {
         throw new BadRequest('USERNAME_PASSWORD_INCORRECT');
     }
 }
开发者ID:johninchina,项目名称:restful-api,代码行数:29,代码来源:Keygen.php

示例2: validate

 public function validate()
 {
     // $except中指定的资源不需要认证
     $rName = $this->getManager()->getRequest()->getResource();
     if (!in_array($rName, $this->except)) {
         // 验证HTTP_KEY是否有效
         if (!isset($_SERVER['HTTP_KEY'])) {
             throw new Unauthorized();
         }
         $keygen = explode(',', base64_decode($_SERVER['HTTP_KEY']));
         list($username, $md5Password, $sessionId) = $keygen;
         $sessionPath = session_save_path() == '' ? '/SmartGrid/tmp' : session_save_path();
         $sessionFile = rtrim($sessionPath, '/') . '/sess_' . $sessionId;
         if (!file_exists($sessionFile)) {
             $user = User::model($this->getManager()->getComponent('db'));
             $where = "`username`='{$username}' AND `password`='{$md5Password}'";
             $userinfo = $user->where($where)->find();
             if ($userinfo == null) {
                 throw new Unauthorized();
             }
             session_id($sessionId);
             session_start();
             $_SESSION['userid'] = $userinfo['id'];
             $_SESSION['username'] = $userinfo['username'];
             $_SESSION['userrole'] = $userinfo['userrole'];
             $_SESSION['authtype'] = $userinfo['authtype'];
             $_SESSION['permission'] = json_decode($userinfo['permission']);
         }
         session_id($sessionId);
         session_start();
     }
 }
开发者ID:johninchina,项目名称:restful-api,代码行数:32,代码来源:Auth.php

示例3: action_addMessage

 public function action_addMessage()
 {
     if (Request::current()->is_ajax()) {
         $sender_id = \Registry::getCurrentUser()->id;
         $user = \Model\User::model()->findByPk($sender_id);
         $receiver_id = $this->request->post('receiver_id');
         $message = $this->request->post('message');
         $session = \Model\Chat::model()->findByAttributes(['session' => $receiver_id . "#" . $sender_id]);
         if ($session) {
             $sess_send = $receiver_id . "#" . $sender_id;
         } else {
             $sess_send = $sender_id . "#" . $receiver_id;
         }
         $user_send_message = new \Model\Chat();
         $user_send_message->sender_id = $sender_id;
         $user_send_message->receiver_id = $receiver_id;
         $user_send_message->message = $message;
         $user_send_message->session = $sess_send;
         $user_send_message->save();
         $tplObj = \smarty\View::factory('chat' . DS . 'message_ajax');
         $tplObj->assign(['item' => $user_send_message, 'session' => $sess_send, 'user' => $user]);
         $this->response->body($tplObj);
         return true;
     }
 }
开发者ID:astar3086,项目名称:studio_mn24,代码行数:25,代码来源:Chat.php

示例4: findImages

 public function findImages($search)
 {
     $user_id = \Registry::getCurrentUser()->iduser;
     $user = \Model\User::model()->findByPk($user_id);
     $criteria = new \DBCriteria(array('condition' => " description LIKE :match OR\n                             main_text LIKE :match OR\n                            title LIKE :match OR ", 'params' => array(':match' => "%{$search}%")));
     $criteria->limit = $this->limit;
     $data = \Model\Pages::model()->with('idpageType')->findAll($criteria);
     $this->template->assign(['results' => $data, 'count_find' => count($data)]);
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:9,代码来源:Search.php

示例5: action_Edit

 public function action_Edit()
 {
     if ($item_id = \Utils\Protect::Validate($this->request->param('id'), 'int')) {
         \Assets::js('sight', base_UI . 'js/admin/Payments/Edit.js');
         $this->addCKEditor();
         $this->addBootstrapModal();
         $this->addSelect2();
         //Alerts BootBox
         \Assets::js('BootBox', base_UI . 'libs/BootBox/bootbox.js');
         //Item Data
         $data = \Model\UserPayment::model()->with('iduser0', 'iduserCredit')->findByPk($item_id);
         $userCredit = \Model\UserCredit::model()->findAll();
         $users = \Model\User::model()->findAll();
         $this->template->assign(['data' => $data, 'userCredit' => $userCredit, 'users' => $users]);
         $this->response->body($this->template->fetch('admin/payments/edit.tpl'));
     }
 }
开发者ID:astar3086,项目名称:studio_mn24,代码行数:17,代码来源:Payments.php

示例6: action_delete

 public function action_delete()
 {
     if (\Request::current()->is_ajax()) {
         $user_id = \Registry::getCurrentUser()->id;
         $value = $this->request->post('value');
         $status = false;
         if ((int) $value == 1) {
             $User = \Model\User::model()->findByPk($user_id);
             if ($User->delete()) {
                 $status = true;
             }
             if ($status) {
                 $this->response->body(json_encode(['code' => 1]));
             } else {
                 $this->response->body(json_encode(['code' => 0]));
             }
         } else {
             $User = \Model\User::model()->findByPk($user_id);
             $User->access_level = 0;
             // Deleted
             if ($User->save()) {
                 $this->response->body(json_encode(['code' => 1]));
             } else {
                 $this->response->body(json_encode(['code' => 0]));
             }
         }
     }
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:28,代码来源:Portfolio.php

示例7: action_register

 public function action_register()
 {
     if (!\Request::current()->is_ajax()) {
         \Assets::js('register', base_UI . 'js/Auth/register.js');
         $this->response->body($this->template->fetch('Auth/register.tpl'));
     } else {
         $attrs = ['email', 'pass', 'pass2', 'first_name', 'bdate'];
         foreach ($attrs as $item) {
             if (!isset($_POST[$item])) {
                 $this->response->body(json_encode(['code' => -3]));
                 return;
             }
         }
         if ($userInfo = User::model()->findByAttributes(['email' => $_POST['email']])) {
             $this->response->body(json_encode(['code' => -4]));
             return;
         }
         if ($_POST['pass'] !== $_POST['pass2']) {
             $this->response->body(json_encode(['code' => -1]));
             return;
         }
         //Create new account
         $_POST['last_login'] = time();
         $user_id = \Auth\Base::create($_POST);
         if ($user_id == false) {
             $this->response->body(json_encode(['code' => -2]));
             return true;
         } else {
             $this->response->body(json_encode(['code' => true]));
             return true;
         }
     }
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:33,代码来源:Main.php

示例8: chatInit

 public function chatInit()
 {
     // Init Current Chat Session
     $sender_id = \Registry::getCurrentUser()->id;
     $receiver_id = $this->request->post('receiver_id');
     $user = \Model\User::model()->findByPk($sender_id);
     if (!$user) {
         $this->response->body(json_encode(['status' => -777, 'error' => 'Access Denied!']));
         return true;
     }
     if ($receiver_id) {
         if ($receiver_id > $sender_id) {
             $this->chat_session = $receiver_id . "#" . $sender_id;
         } else {
             $this->chat_session = $sender_id . "#" . $receiver_id;
         }
     }
 }
开发者ID:astar3086,项目名称:studio_mn24,代码行数:18,代码来源:Builder.php

示例9: action_GetJson

 public function action_GetJson()
 {
     $data = User::model()->findAll();
     $access = new \Auth\Access(\Registry::getCurrentUser()->access_level);
     if ($access->get(\Auth\Access::User_Is_Admin)) {
         $aoColumnsData = [];
         /** @var $item User */
         foreach ($data as $item) {
             $currentUserAccess = new \Auth\Access($item->access_level);
             $tmp = ['id' => $item->iduser, 'fio' => $item->first_name, 'email' => $item->email, 'Access' => $currentUserAccess->get(\Auth\Access::User_Login) ? 'Yes' : 'No'];
             $aoColumnsData[] = $tmp;
         }
         $this->response->body(json_encode(['aaData' => $aoColumnsData]));
     } else {
         throw new \HTTP_Exception_403('Admin Only');
     }
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:17,代码来源:Users.php

示例10: createSession

 /**
  * @param $mail
  * @param $pass
  * @return bool|int
  */
 public static function createSession($mail, $pass)
 {
     /** @var $userInfo User */
     if (!($userInfo = User::model()->findByAttributes(['email' => $mail]))) {
         return -1;
     }
     //$pass = Protect::Crypt($pass.\Cookie::$salt,$userInfo->salt);
     $pass = Protect::Crypt($pass . $userInfo->salt, $userInfo->salt);
     //Если пароли не совпадают
     if ($pass != $userInfo->pass) {
         return -2;
     }
     $access = new \Auth\Access($userInfo->access_level);
     $isAdmin = $access->get(\Auth\Access::User_Is_Admin);
     $isModerator = $access->get(\Auth\Access::User_Is_Moderator);
     //Если юзверю не разрешено логинится
     /*if( !$isAdmin && !$isModerator  )
     		{
     			return -3;
     		}*/
     return self::startSession($userInfo);
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:27,代码来源:Base.php

示例11: isGuest

 /**
  * @return bool|\Model\UserSession
  */
 public function isGuest()
 {
     $status = \Auth\Base::Check();
     if ($status == false) {
         return true;
     } else {
         $data = User::model()->findByPk($status->iduser);
         \Registry::setCurrentUser($data);
         return false;
     }
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:14,代码来源:User.php


注:本文中的Model\User::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。