本文整理汇总了PHP中Current_User::loadAuthorization方法的典型用法代码示例。如果您正苦于以下问题:PHP Current_User::loadAuthorization方法的具体用法?PHP Current_User::loadAuthorization怎么用?PHP Current_User::loadAuthorization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Current_User
的用法示例。
在下文中一共展示了Current_User::loadAuthorization方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PHPWS_User
<?php
/**
* @author Matthew McNaney <mcnaney at gmail dot com>
* @version $Id: runtime.php 7776 2010-06-11 13:52:58Z jtickle $
*/
if (!class_exists('PHPWS_User')) {
include '../../core/conf/404.html';
exit;
}
if (isset($_REQUEST['module']) && $_REQUEST['module'] == 'users' && (isset($_REQUEST['action']) && $_REQUEST['action'] == 'reset')) {
$_SESSION['User'] = new PHPWS_User();
} elseif (!isset($_SESSION['User'])) {
Current_User::init();
if (Current_User::allowRememberMe()) {
if (PHPWS_Settings::get('users', 'allow_remember')) {
Current_User::rememberLogin();
}
}
}
Current_User::loadAuthorization($_SESSION['User']);
Current_User::getLogin();
if (Current_User::isLogged() && PHPWS_Settings::get('users', 'session_warning')) {
$lifetime = ini_get('session.gc_maxlifetime');
$path = PHPWS_SOURCE_HTTP . 'mod/users/javascript/session_check/script.min.js';
$timeout = floor($lifetime / 60);
$warning_minutes = $timeout - 5;
javascript('jquery');
\Layout::addJSHeader("<script type='text/javascript'>var sess_expirationMinutes = {$timeout};var sess_warningMinutes = {$warning_minutes};</script>" . "<script type='text/javascript' src='{$path}'></script>");
}
示例2: loginUser
/**
* Logs in a user dependant on their authorization setting
*/
public static function loginUser($username, $password = null)
{
if (!Current_User::allowUsername($username)) {
return PHPWS_Error::get(USER_BAD_CHARACTERS, 'users', 'Current_User::loginUser');
}
// First check if they are currently a user
$user = new PHPWS_User();
$db = new PHPWS_DB('users');
$db->addWhere('username', strtolower($username));
$result = $db->loadObject($user);
if (PHPWS_Error::isError($result)) {
return $result;
}
if ($result == false) {
if (PHPWS_Error::logIfError($user->setUsername($username))) {
return false;
}
} else {
// This user is in the local database
if (!$user->approved) {
return PHPWS_Error::get(USER_NOT_APPROVED, 'users', 'Current_User::loginUser');
}
if (!$user->loadScript()) {
Layout::add(dgettext('users', 'Could not load authentication script. Please contact site administrator.'));
return false;
}
}
if (!Current_User::loadAuthorization($user)) {
Layout::add(dgettext('users', 'Could not load authentication script. Please contact site administrator.'));
return false;
}
$auth = Current_User::getAuthorization();
$auth->setPassword($password);
$result = $auth->authenticate();
if (PHPWS_Error::isError($result)) {
return $result;
}
if ($result == true) {
// If the user id is zero and the authorization wants a new
// user created
if (!$user->id && $auth->create_new_user) {
$user->setActive(true);
$user->setApproved(true);
$auth->createUser();
$user->save();
PHPWS_Core::initModClass('users', 'Action.php');
User_Action::assignDefaultGroup($user);
}
if (!$user->active) {
return PHPWS_Error::get(USER_DEACTIVATED, 'users', 'Current_User:loginUser', $user->username);
}
if ($auth->localUser()) {
$user->login();
}
unset($_SESSION['User']);
$_SESSION['User'] = $user;
return true;
} else {
return false;
}
}