當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::findFirst方法代碼示例

本文整理匯總了PHP中User::findFirst方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::findFirst方法的具體用法?PHP User::findFirst怎麽用?PHP User::findFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在User的用法示例。


在下文中一共展示了User::findFirst方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: gpsAction

 /**
  * GPS安裝
  */
 public function gpsAction()
 {
     if ($this->isAjax()) {
         $data = $this->request->getPost();
         $uid = $data['uid'];
         !$uid and $this->error('參數錯誤');
         $data['gps'] = 1;
         $model = new LoanForm('gps');
         if ($result = $model->validate($data)) {
             if ($model->sign()) {
                 Log::add($uid, $this->getOperatorId(), \App\Config\Log::loanOperate('gps'));
                 $this->success('操作成功');
             } else {
                 $this->error('操作失敗');
             }
         } else {
             $this->error('驗證失敗');
         }
         exit;
     }
     $uid = $this->urlParam();
     empty($uid) and $this->pageError('param');
     $loan = Loan::findByUid($uid);
     $user = User::findFirst($uid)->toArray();
     $this->view->setVars(['loan' => $loan, 'user' => $user]);
     $this->view->pick('afterrc/detail');
 }
開發者ID:Crocodile26,項目名稱:php-1,代碼行數:30,代碼來源:GpsController.php

示例2: find_by_name

 public static function find_by_name($username)
 {
     $conditions = "username = :name:";
     $parameters = array("name" => $username);
     $user = User::findFirst(array($conditions, "bind" => $parameters));
     return $user;
 }
開發者ID:hyfjjjj,項目名稱:HHA-Web,代碼行數:7,代碼來源:Accout.php

示例3: indexAction

 public function indexAction()
 {
     if ($this->request->hasPost('up')) {
         $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     }
     if ($this->session->has('user_id')) {
         $id = $this->session->get('user_id');
         $user = User::findFirst($id);
         foreach ($user->offers as $offers) {
             $image = unserialize($offers->image);
             if (isset($image['image-big-1'])) {
                 $im = 1;
             } else {
                 $im = 0;
             }
             $off[$offers->id]['name'] = array($offers->name, $im, $offers->status, $offers->user->phone, $offers->categories->name);
             if (isset($offers->id)) {
                 foreach ($offers->dannoffers as $dan) {
                     $off[$offers->id][$dan->fieldtype->id] = $dan->dann;
                 }
             }
         }
     }
     //  $this->elements->var_print($off);
     $this->view->setVars(array("cn" => count($user->offers), "off" => $off = isset($off) ? $off : false));
 }
開發者ID:qtebest-dev,項目名稱:tractor,代碼行數:26,代碼來源:MyoffersController.php

示例4: loginAction

 /**
  * Login action, detect if is a valid or invalid user
  */
 public function loginAction()
 {
     $form = new LoginForm();
     if ($this->request->isPost()) {
         if ($form->isValid($this->request->getPost()) != false) {
             $password = $this->request->getPost('password');
             //Find the username and check if this is active into the application
             $user = User::findFirst(array("username = :username: AND active = 1", 'bind' => array('username' => strtolower($this->request->getPost('username', 'striptags')))));
             // successfully find
             if ($user && $this->security->checkHash($password, $user->password)) {
                 //Sent the user to set into the application
                 $this->auth->setAccess($user);
                 //Remember me: If is diferent to false assign a token to the user
                 if ($this->request->getPost('remember') != "false") {
                     $user->assign(array('token' => $this->request->getPost('remember')));
                     if (!$user->save()) {
                         $this->flash->error($user->getMessages());
                     }
                 }
                 return $this->response->redirect('dashboard');
             } else {
                 $form->addFormMessages('username', 'Username name is invalid or not has been activated');
                 $form->addFormMessages('password', 'information does not match');
             }
         }
     }
     $this->view->form = $form;
 }
開發者ID:Pablo251,項目名稱:Kangoo,代碼行數:31,代碼來源:SessionController.php

示例5: LoginAction

 /**
  * @Route("/login", methods = {"POST", "OPTIONS"})
  */
 public function LoginAction()
 {
     //Post傳過來的是一個無名的json數據,所以隻能getRawBody
     $info = $this->request->getJsonRawBody();
     if (!isset($info->username) || !isset($info->password)) {
         $this->response->setJsonContent(['message' => 'No Data!']);
         $this->response->send();
         return;
     }
     $username = $info->username;
     $password = $info->password;
     $user = User::findFirst(['conditions' => 'name=?1', 'bind' => [1 => $username]]);
     if ($user == null) {
         $this->response->setJsonContent(['message' => '用戶不存在']);
     } elseif ($user->password != $password) {
         $this->response->setJsonContent(['message' => '密碼錯誤']);
     } else {
         //            $this->session->set('user_id', $user_array['id']);
         //            $this->session->set('user_name', $user_array['name']);
         //            $this->session->set('user_role', $user_array['role']);
         $this->response->setJsonContent(['user_id' => $user->id, 'user_name' => $user->name, 'user_role' => $user->role]);
     }
     $this->response->send();
     return;
 }
開發者ID:sify21,項目名稱:pmail,代碼行數:28,代碼來源:AuthController.php

示例6: confirmAction

 public function confirmAction()
 {
     $this->view->disable();
     $mail = $this->dispatcher->getParam('mail');
     $user = User::findFirst(array('conditions' => 'mail = ?1', 'bind' => array(1 => $mail)));
     if ($user) {
         $conf = Confirmation::findFirst(array('conditions' => 'user = ?1', 'bind' => array(1 => $user->id)));
         if ($conf) {
             if ($conf->code == $this->dispatcher->getParam('code')) {
                 $user->confirmed = 1;
                 if ($user->save()) {
                     $this->_login($user);
                     $conf->delete();
                     message($this, "s", "Аккаунт подтвержден. Добро пожаловать, " . $user->name);
                     return $this->response->redirect();
                 } else {
                     message($this, "d", "Ошибка активации. Попробуйте позже");
                     return $this->response->redirect();
                 }
             } else {
                 message($this, "d", "Код подтверждения не подходит");
                 return $this->response->redirect();
             }
         } else {
             message($this, "w", "Пользователь уже подтвержден");
             return $this->response->redirect();
         }
     } else {
         message($this, "d", "Пользователя " . $mail . " не существует");
         return $this->response->redirect();
     }
 }
開發者ID:Flerki,項目名稱:CarRepairTotal,代碼行數:32,代碼來源:IndexController.php

示例7: indexAction

 public function indexAction()
 {
     $this->view->products = Product::find();
     if ($this->session->get("auth")) {
         $this->view->user = User::findFirst($this->session->get("auth")['id']);
     }
 }
開發者ID:KarimTaha,項目名稱:AdvancedLab,代碼行數:7,代碼來源:IndexController.php

示例8: mapAction

 public function mapAction($idVisit)
 {
     $visit = Visit::findFirst(array("conditions" => "idVisit = ?1", "bind" => array(1 => $idVisit)));
     if (!$visit) {
         $this->flashSession->error("Ocurrio un error procesando su solicitud, por favor intentelo nuevamente.");
         return $this->response->redirect('index');
     }
     $user = User::findFirst(array("conditions" => "idUser = ?1 AND idAccount = ?2", "bind" => array(1 => $visit->idUser, 2 => $this->user->idAccount)));
     if (!$user) {
         $this->flashSession->error("Ocurrio un error procesando su solicitud, por favor intentelo nuevamente.");
         return $this->response->redirect('visit/index');
     }
     try {
         $sql_rows = "SELECT v.idVisit AS idUser, v.start AS date, u.name AS name, u.lastName AS lastname, vt.name AS visit, c.name AS client, v.battery AS battery, v.latitude AS latitude, v.longitude AS longitude, v.location AS location " . "FROM Visit AS v " . " JOIN User AS u ON (u.idUser = v.idUser) " . " JOIN Visittype AS vt ON (vt.idVisittype = v.idVisittype) " . " JOIN Client AS c ON (c.idClient = v.idClient) " . " WHERE v.idVisit = {$idVisit}";
         //            $this->logger->log($sql_rows);
         $modelsManager = \Phalcon\DI::getDefault()->get('modelsManager');
         $rows = $modelsManager->executeQuery($sql_rows);
         $this->view->setVar('visit', $rows->getFirst());
         $this->view->setVar('user', $user);
     } catch (Exception $e) {
         $this->flashSession->error($e->getMessage());
         $this->trace("fail", $e->getMessage());
         return $this->response->redirect('visit/index');
     }
 }
開發者ID:dorianlopez,項目名稱:track,代碼行數:25,代碼來源:VisitController.php

示例9: tryLogin

 public function tryLogin($data)
 {
     // Reject requests
     if ($this->isExceedingRateLimit(2)) {
         $this->response->setStatusCode(429, 'Too many requests');
         $this->flash->notice('Too many requests.');
         return false;
     }
     /** @var User $user */
     $user = User::findFirst(['email = :email:', 'bind' => ['email' => $data['user']]]);
     // Sleep for 1-500ms
     usleep(mt_rand(1000, 500000));
     if ($user && $user->validatePassword($data['password'])) {
         // Validate TOTP token
         // This needs to be done at this stage as the two factor auth key is
         // encrypted with the user's password.
         if ($otpKey = $user->getOtpKey($data['password'])) {
             $otp = new \Rych\OTP\TOTP($otpKey);
             if (!$otp->validate($data['token'])) {
                 $this->flash->error('Incorrect login details');
                 return false;
             }
         }
         $keyService = new \Stecman\Passnote\AccountKeyService();
         $keyService->unlockAccountKeyForSession($user, $data['password']);
         $this->session->set(Security::SESSION_USER_ID, $user->id);
         $this->session->set(Security::SESSION_KEY, $user->getSessionKey());
         session_regenerate_id();
         $this->response->redirect('');
     } else {
         // Keep timing
         $this->security->hash(openssl_random_pseudo_bytes(12));
         $this->flash->error('Incorrect login details');
     }
 }
開發者ID:stecman,項目名稱:passnote,代碼行數:35,代碼來源:AuthController.php

示例10: getUser

 protected function getUser()
 {
     static $user;
     if (!$user && ($auth = $this->getAuth()) && $auth['user_id']) {
         $user = User::findFirst(array('conditions' => 'id = ?1', 'bind' => array(1 => $auth['user_id'])));
     }
     return $user;
 }
開發者ID:Flerki,項目名稱:CarRepairTotal,代碼行數:8,代碼來源:ControllerBase.php

示例11: getCurrentUser

 /**
  * @return \User
  */
 public static function getCurrentUser()
 {
     $di = \Phalcon\DI::getDefault();
     $session = $di->get('session');
     if ($id = $session->get(self::SESSION_USER_ID)) {
         return User::findFirst($id);
     }
 }
開發者ID:stecman,項目名稱:passnote,代碼行數:11,代碼來源:Security.php

示例12: onConstruct

 public function onConstruct()
 {
     $userid = \User::check_token();
     $user = \User::findFirst([['userid' => $userid]]);
     if ($user) {
         $this->user = $user->attrs();
     }
 }
開發者ID:nisnaker,項目名稱:tu,代碼行數:8,代碼來源:BaseController.php

示例13: detailAction

 public function detailAction()
 {
     $uid = $this->urlParam();
     empty($uid) and $this->pageError('param');
     $loan = Loan::findByUid($uid);
     $user = User::findFirst($uid)->toArray();
     $this->view->setVars(['loan' => $loan, 'user' => $user]);
 }
開發者ID:Crocodile26,項目名稱:php-1,代碼行數:8,代碼來源:FinanceController.php

示例14: createAssocAction

 public function createAssocAction()
 {
     $user = User::findFirst();
     $project = new Project();
     $project->user = $user;
     $project->title = "Moon walker";
     $result = $project->save();
 }
開發者ID:BBK-PiJ-2014-83,項目名稱:learning-phalcon,代碼行數:8,代碼來源:UserController.php

示例15: principalAction

 public function principalAction()
 {
     $username = "pablo251";
     $token = "ly4b35jvokj7cik9541ug6weqgjsjor";
     $user = User::findFirst(array("username = :username: and token = :token: AND active = 1", 'bind' => array('username' => strtolower($username), 'token' => $token)));
     if ($user == null) {
         echo "Como tal";
     }
     print_r($user);
 }
開發者ID:Pablo251,項目名稱:Kangoo,代碼行數:10,代碼來源:IndexController.php


注:本文中的User::findFirst方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。