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


PHP user::session_create方法代碼示例

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


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

示例1: submit

 /**
  * @param int  $user_id
  * @param bool $admin
  * @param bool $auto_login
  * @param bool $viewonline
  * @param string $class
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws http_exception
  */
 public function submit($user_id, $admin, $auto_login, $viewonline, $class)
 {
     $this->user->add_lang_ext('paul999/tfa', 'common');
     if (!check_form_key('tfa_login_page')) {
         throw new http_exception(403, 'FORM_INVALID');
     }
     if (empty($this->user->data['tfa_random']) || $user_id != $this->user->data['tfa_uid']) {
         throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG');
     }
     $random = $this->request->variable('random', '');
     if ($this->user->data['tfa_random'] !== $random || strlen($random) !== 40) {
         throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG');
     }
     $sql_ary = array('tfa_random' => '', 'tfa_uid' => 0);
     $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\tWHERE\n\t\t\t\tsession_id = '" . $this->db->sql_escape($this->user->data['session_id']) . "' AND\n\t\t\t\tsession_user_id = '" . (int) $this->user->data['user_id'];
     $this->db->sql_query($sql);
     if (empty($class)) {
         throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG');
     }
     $module = $this->session_helper->findModule($class);
     if ($module == null) {
         throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG');
     }
     $redirect = $this->request->variable('redirect', "{$this->root_path}/index.{$this->php_ext}");
     try {
         if (!$module->login($user_id)) {
             $this->template->assign_var('S_ERROR', $this->user->lang('TFA_INCORRECT_KEY'));
             $this->session_helper->generate_page($user_id, $admin, $auto_login, $viewonline, $redirect);
         }
     } catch (http_exception $ex) {
         if ($ex->getStatusCode() == 400) {
             $this->template->assign_var('S_ERROR', $ex->getMessage());
             $this->session_helper->generate_page($user_id, $admin, $auto_login, $viewonline, $redirect);
         }
     }
     $old_session_id = $this->user->session_id;
     if ($admin) {
         $cookie_expire = time() - 31536000;
         $this->user->set_cookie('u', '', $cookie_expire);
         $this->user->set_cookie('sid', '', $cookie_expire);
     }
     $result = $this->user->session_create($user_id, $admin, $auto_login, $viewonline);
     // Successful session creation
     if ($result === true) {
         // If admin re-authentication we remove the old session entry because a new one has been created...
         if ($admin) {
             // the login array is used because the user ids do not differ for re-authentication
             $sql = 'DELETE FROM ' . SESSIONS_TABLE . "\n\t\t\t\t\tWHERE session_id = '" . $this->db->sql_escape($old_session_id) . "'\n\t\t\t\t\tAND session_user_id = " . (int) $user_id;
             $this->db->sql_query($sql);
             redirect(append_sid("{$this->root_path}adm/index.{$this->php_ext}", false, true, $this->user->data['session_id']));
         }
         redirect(append_sid($redirect, false, true, $this->user->data['session_id']));
     }
     throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG');
 }
開發者ID:paul999,項目名稱:phpbb_2fa,代碼行數:64,代碼來源:main_controller.php


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