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


PHP User::findFirst方法代码示例

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


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

示例1: check

 /**
  * Checking user existing in system
  *
  * @param  string  $email
  * @param  string  $password
  * @param  boolean $cookie
  * @param  boolean $log
  * @return boolean
  */
 public function check($email, $password, $cookie = false, $log = false)
 {
     $me = new \stdClass();
     $myUser = \Model\User::findFirst(['email = :femail: AND status = :status:', 'bind' => ['femail' => $email, 'status' => \Model\User::STATUS_ENABLE]]);
     if ($myUser) {
         if ($this->security->checkHash($password, $myUser->password)) {
             $me->id = $myUser->id;
             $me->email = $myUser->email;
             $me->name = $myUser->name;
             $me->role = $myUser->role;
             $me->roleName = $myUser->getRoleName();
             $me->avatar = $myUser->avatar;
             // create session for user
             $this->session->set('me', $me);
             // store cookie if chosen
             if ($cookie == true) {
                 $this->cookie->set('remember-me', $me->id, time() + 15 * 86400);
             }
             if ($log) {
                 // Store user logged in (LOG_IN::userId::userEmail::userAgent::ip)
                 $this->logger->name = 'LOGIN';
                 // Your own log name
                 $this->logger->info($myUser->id . '::' . $myUser->email . '::' . $this->request->getUserAgent() . '::' . $this->request->getClientAddress());
             }
             return true;
         } else {
             $this->flash->error('Wrong user information. Try again.');
         }
     } else {
         $this->flash->error('Wrong user information. Try again.');
     }
 }
开发者ID:aisuhua,项目名称:phalcon-jumpstart,代码行数:41,代码来源:Authentication.php

示例2: beforeExecuteRoute

 /**
  * @param Event $event
  * @param Dispatcher $dispatcher
  * @return bool
  */
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     $role = 'guest';
     if ($this->session->has('user_id')) {
         $userId = $this->session->get('user_id');
         if ($userId) {
             $user = User::findFirst($userId);
             if ($user instanceof User) {
                 $role = 'user';
                 $dispatcher->setParam('user', $user);
             }
         }
     }
     $controller = strtolower($dispatcher->getControllerName());
     $action = strtolower($dispatcher->getActionName());
     if (!$this->acl->isAllowed($role, $controller, $action)) {
         $this->session->set('__callback_url', $this->request->getServer('REQUEST_URI'));
         $dispatcher->forward(['controller' => 'auth', 'action' => 'signIn']);
         return false;
     }
     return true;
 }
开发者ID:tankist,项目名称:blog-mvc,代码行数:27,代码来源:Auth.php

示例3: deleteAction

 public function deleteAction()
 {
     $message = '';
     $id = (int) $this->dispatcher->getParam('id');
     $redirectUrl = (string) urldecode(base64_decode($this->dispatcher->getParam('redirect')));
     $myUser = \Model\User::findFirst(['id = :id:', 'bind' => ['id' => (int) $id]])->delete();
     if ($myUser) {
         $this->flash->success(str_replace('###id###', $id, $this->lang->get('message_delete_success')));
     } else {
         foreach ($myUser->getMessages() as $msg) {
             $message .= $msg->getMessage() . "</br>";
         }
         $this->flashSession->error($message);
     }
     return $this->response->redirect($redirectUrl);
 }
开发者ID:aisuhua,项目名称:phalcon-jumpstart,代码行数:16,代码来源:UserController.php


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