本文整理汇总了PHP中common_check_user函数的典型用法代码示例。如果您正苦于以下问题:PHP common_check_user函数的具体用法?PHP common_check_user怎么用?PHP common_check_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了common_check_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
function login()
{
$this->showStylesheets();
$nickname = common_canonical_nickname($this->trimmed('nickname'));
$password = $this->arg('password');
$msg = null;
if ($nickname) {
if (common_check_user($nickname, $password)) {
$user = User::staticGet('nickname', $nickname);
if (!$user) {
$this->showLoginForm(_m("Server error: Couldn't get user!"));
}
$flink = DB_DataObject::factory('foreign_link');
$flink->user_id = $user->id;
$flink->foreign_id = $this->fbuid;
$flink->service = FACEBOOK_SERVICE;
$flink->created = common_sql_now();
$flink->set_flags(true, false, false, false);
$flink_id = $flink->insert();
// XXX: Do some error handling here
$this->setDefaults();
$this->getUpdatePermission();
return;
} else {
$msg = _m('Incorrect username or password.');
}
}
$this->showLoginForm($msg);
$this->showFooter();
}
示例2: checkLogin
function checkLogin($user_id = null, $token = null)
{
// XXX: login throttle
//database use nickname we change it into username for more
//easier to understand
$nickname = $this->trimmed('username');
if (empty($nickname)) {
$this->clientError(_('username empty'));
return;
}
try {
$nickname = Nickname::normalize($nickname);
} catch (NicknameException $e) {
$this->clientError(_('username error'));
return;
}
$password = $this->arg('password');
$user = common_check_user($nickname, $password);
if (!$user) {
// TRANS: Form validation error displayed when trying to log in with incorrect credentials.
$this->clientError(_('Incorrect username or password.'));
return;
}
// success!
if (!common_set_user($user)) {
// TRANS: Server error displayed when during login a server error occurs.
$this->serverError(_('Error setting user. You are probably not authorized.'));
return;
}
common_real_login(true);
$result = $this->twitterUserArray($user->getProfile(), false);
$this->initDocument('json');
$this->showJsonObjects($result);
$this->endDocument('json');
}
示例3: doPreparation
protected function doPreparation()
{
$this->limit = $this->int('limit');
if (empty($this->limit)) {
$this->limit = DEFAULT_RSS_LIMIT;
}
if (common_config('site', 'private')) {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
// This header makes basic auth go
header('WWW-Authenticate: Basic realm="GNU social RSS"');
// If the user hits cancel -- bam!
$this->show_basic_auth_error();
// the above calls 'exit'
} else {
$nickname = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
if (!common_check_user($nickname, $password)) {
// basic authentication failed
list($proxy, $ip) = common_client_ip();
common_log(LOG_WARNING, "Failed RSS auth attempt, nickname = {$nickname}, proxy = {$proxy}, ip = {$ip}.");
$this->show_basic_auth_error();
// the above calls 'exit'
}
}
}
$this->doStreamPreparation();
$this->notices = $this->getNotices($this->limit);
}
示例4: doPost
/**
* Check the login data
*
* Determines if the login data is valid. If so, logs the user
* in, and redirects to the 'with friends' page, or to the stored
* return-to URL.
*
* @return void
*/
protected function doPost()
{
// XXX: login throttle
$nickname = $this->trimmed('nickname');
$password = $this->arg('password');
$user = common_check_user($nickname, $password);
if (!$user instanceof User) {
// TRANS: Form validation error displayed when trying to log in with incorrect credentials.
throw new ServerException(_('Incorrect username or password.'));
}
// success!
if (!common_set_user($user)) {
// TRANS: Server error displayed when during login a server error occurs.
throw new ServerException(_('Error setting user. You are probably not authorized.'));
}
common_real_login(true);
$this->updateScopedProfile();
if ($this->boolean('rememberme')) {
common_rememberme($user);
}
$url = common_get_returnto();
if ($url) {
// We don't have to return to it again
common_set_returnto(null);
$url = common_inject_session($url);
} else {
$url = common_local_url('all', array('nickname' => $this->scoped->nickname));
}
common_redirect($url, 303);
}
示例5: onStartCheckPassword
function onStartCheckPassword($nickname, $password, &$authenticatedUser)
{
if (strpos($nickname, '@')) {
$user = User::staticGet('email', $nickname);
if ($user && isset($user->email)) {
if (common_check_user($user->nickname, $password)) {
$authenticatedUser = $user;
return false;
}
}
}
}
示例6: onStartCheckPassword
function onStartCheckPassword($nickname, $password, &$authenticatedUser)
{
if (!strpos($nickname, '@')) {
return true;
}
$user = User::getKV('email', $nickname);
if ($user instanceof User && $user->email === $nickname) {
if (common_check_user($user->nickname, $password)) {
$authenticatedUser = $user;
return false;
}
}
return true;
}
示例7: handle
/**
* Handle the request
*
* Check whether the credentials are valid and output the result
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
protected function handle()
{
parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(_('This method requires a POST.'), 400, $this->format);
return;
}
$user = common_check_user($this->arg('username'), $this->arg('password'));
if ($user) {
$user = true;
}
$this->initDocument('json');
$this->showJsonObjects($user);
$this->endDocument('json');
}
示例8: handle
function handle($args)
{
parent::handle($args);
$this->api_action = $this->arg('apiaction');
$method = $this->arg('method');
$argument = $this->arg('argument');
if (isset($argument)) {
$cmdext = explode('.', $argument);
$this->api_arg = $cmdext[0];
$this->api_method = $method;
$this->content_type = strtolower($cmdext[1]);
} else {
# Requested format / content-type will be an extension on the method
$cmdext = explode('.', $method);
$this->api_method = $cmdext[0];
$this->content_type = strtolower($cmdext[1]);
}
if ($this->requires_auth()) {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
# This header makes basic auth go
header('WWW-Authenticate: Basic realm="Laconica API"');
# If the user hits cancel -- bam!
$this->show_basic_auth_error();
} else {
$nickname = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
$user = common_check_user($nickname, $password);
if ($user) {
$this->user = $user;
$this->process_command();
} else {
# basic authentication failed
$this->show_basic_auth_error();
}
}
} else {
# Caller might give us a username even if not required
if (isset($_SERVER['PHP_AUTH_USER'])) {
$user = User::staticGet('nickname', $_SERVER['PHP_AUTH_USER']);
if ($user) {
$this->user = $user;
}
# Twitter doesn't throw an error if the user isn't found
}
$this->process_command();
}
}
示例9: handle
function handle($args)
{
parent::handle($args);
if (common_is_real_login()) {
// TRANS: Client error displayed when trying to log in while already logged on.
$this->clientError(_m('Already logged in.'));
} else {
global $casSettings;
phpCAS::client(CAS_VERSION_2_0, $casSettings['server'], $casSettings['port'], $casSettings['path'], false);
phpCAS::setNoCasServerValidation();
phpCAS::handleLogoutRequests();
phpCAS::forceAuthentication();
global $casTempPassword;
$casTempPassword = common_good_rand(16);
$user = common_check_user(phpCAS::getUser(), $casTempPassword);
if (!$user) {
// TRANS: Server error displayed when trying to log in with incorrect username or password.
$this->serverError(_m('Incorrect username or password.'));
return;
}
// success!
if (!common_set_user($user)) {
// TRANS: Server error displayed when login fails in CAS authentication plugin.
$this->serverError(_m('Error setting user. You are probably not authorized.'));
return;
}
common_real_login(true);
$url = common_get_returnto();
if ($url) {
// We don't have to return to it again
common_set_returnto(null);
} else {
if (common_config('site', 'private') && $casSettings['takeOverLogin']) {
//SSO users expect to just go to the URL they entered
//if we don't have a returnto set, the user entered the
//main StatusNet url, so send them there.
$url = common_local_url('public');
} else {
//With normal logins (regular form-based username/password),
//the user would expect to go to their home after logging in.
$url = common_local_url('public', array('nickname' => $user->nickname));
}
}
common_redirect($url, 303);
}
}
示例10: checkBasicAuthUser
/**
* Check for a user specified via HTTP basic auth. If there isn't
* one, try to get one by outputting the basic auth header.
*
* @return boolean true or false
*/
function checkBasicAuthUser($required = true)
{
$this->basicAuthProcessHeader();
$realm = common_config('api', 'realm');
if (empty($realm)) {
$realm = common_config('site', 'name') . ' API';
}
if (empty($this->auth_user_nickname) && $required) {
header('WWW-Authenticate: Basic realm="' . $realm . '"');
// show error if the user clicks 'cancel'
// TRANS: Client error thrown when authentication fails becaus a user clicked "Cancel".
$this->clientError(_('Could not authenticate you.'), 401, $this->format);
exit;
} else {
$user = common_check_user($this->auth_user_nickname, $this->auth_user_password);
if (Event::handle('StartSetApiUser', array(&$user))) {
if (!empty($user)) {
$this->auth_user = $user;
}
Event::handle('EndSetApiUser', array($user));
}
// By default, basic auth users have rw access
$this->access = self::READ_WRITE;
if (empty($this->auth_user) && ($required || isset($_SERVER['PHP_AUTH_USER']))) {
$msg = sprintf("basic auth nickname = %s", $this->auth_user_nickname);
$this->logAuthFailure($msg);
// TRANS: Client error thrown when authentication fails.
$this->clientError(_('Could not authenticate you.'), 401, $this->format);
exit;
}
}
}
示例11: handle
function handle($args)
{
parent::handle($args);
if (!isset($_SERVER['PHP_AUTH_USER'])) {
// not authenticated, show login form
header('WWW-Authenticate: Basic realm="StatusNet API"');
// cancelled the browser login form
$this->clientError(_('Authentication error!'), $code = 401);
} else {
$nick = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
// check username and password
$user = common_check_user($nick, $pass);
if ($user) {
// verify that user is admin
if (!($user->id == 1)) {
$this->clientError(_('Only User #1 can update the template.'), $code = 401);
}
// open the old template
$tpl_file = $this->templateFolder() . '/index.html';
$fp = fopen($tpl_file, 'w+');
// overwrite with the new template
fwrite($fp, $this->arg('template'));
fclose($fp);
header('HTTP/1.1 200 OK');
header('Content-type: text/plain');
print "Template Updated!";
} else {
// bad username and password
$this->clientError(_('Authentication error!'), $code = 401);
}
}
}
示例12: handlePost
function handlePost()
{
// check session token for CSRF protection.
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->showForm(_('There was a problem with your session token. Try again, please.'));
return;
}
// check creds
$user = null;
if (!common_logged_in()) {
// XXX Force credentials check?
// @fixme this should probably use a unified login form handler
$user = null;
if (Event::handle('StartOAuthLoginCheck', array($this, &$user))) {
$user = common_check_user($this->nickname, $this->password);
}
Event::handle('EndOAuthLoginCheck', array($this, &$user));
if (empty($user)) {
// TRANS: Form validation error given when an invalid username and/or password was passed to the OAuth API.
$this->showForm(_("Invalid nickname / password!"));
return;
}
} else {
$user = common_current_user();
}
// fetch the token
$this->reqToken = $this->store->getTokenByKey($this->oauthTokenParam);
assert(!empty($this->reqToken));
if ($this->arg('allow')) {
// mark the req token as authorized
try {
$this->store->authorize_token($this->oauthTokenParam);
} catch (Exception $e) {
$this->serverError($e->getMessage());
}
common_log(LOG_INFO, sprintf("API OAuth - User %d (%s) has authorized request token %s for OAuth application %d (%s).", $user->id, $user->nickname, $this->reqToken->tok, $this->app->id, $this->app->name));
// XXX: Make sure we have a oauth_token_association table. The table
// is now in the main schema, but because it is being added with
// a point release, it's unlikely to be there. This code can be
// removed as of 1.0.
$this->ensureOauthTokenAssociationTable();
$tokenAssoc = new Oauth_token_association();
$tokenAssoc->profile_id = $user->id;
$tokenAssoc->application_id = $this->app->id;
$tokenAssoc->token = $this->oauthTokenParam;
$tokenAssoc->created = common_sql_now();
$result = $tokenAssoc->insert();
if (!$result) {
common_log_db_error($tokenAssoc, 'INSERT', __FILE__);
// TRANS: Server error displayed when a database action fails.
$this->serverError(_('Database error inserting oauth_token_association.'));
}
$callback = $this->getCallback();
if (!empty($callback) && $this->reqToken->verified_callback != 'oob') {
$targetUrl = $this->buildCallbackUrl($callback, array('oauth_token' => $this->oauthTokenParam, 'oauth_verifier' => $this->reqToken->verifier));
common_log(LOG_INFO, "Redirecting to callback: {$targetUrl}");
// Redirect the user to the provided OAuth callback
common_redirect($targetUrl, 303);
} elseif ($this->app->type == 2) {
// Strangely, a web application seems to want to do the OOB
// workflow. Because no callback was specified anywhere.
common_log(LOG_WARNING, sprintf("API OAuth - No callback provided for OAuth web client ID %s (%s) " . "during authorization step. Falling back to OOB workflow.", $this->app->id, $this->app->name));
}
// Otherwise, inform the user that the rt was authorized
$this->showAuthorized();
} else {
if ($this->arg('cancel')) {
common_log(LOG_INFO, sprintf("API OAuth - User %d (%s) refused to authorize request token %s for OAuth application %d (%s).", $user->id, $user->nickname, $this->reqToken->tok, $this->app->id, $this->app->name));
try {
$this->store->revoke_token($this->oauthTokenParam, 0);
} catch (Exception $e) {
$this->ServerError($e->getMessage());
}
$callback = $this->getCallback();
// If there's a callback available, inform the consumer the user
// has refused authorization
if (!empty($callback) && $this->reqToken->verified_callback != 'oob') {
$targetUrl = $this->buildCallbackUrl($callback, array('oauth_problem' => 'user_refused'));
common_log(LOG_INFO, "Redirecting to callback: {$targetUrl}");
// Redirect the user to the provided OAuth callback
common_redirect($targetUrl, 303);
}
// otherwise inform the user that authorization for the rt was declined
$this->showCanceled();
} else {
// TRANS: Client error given on when invalid data was passed through a form in the OAuth API.
$this->clientError(_('Unexpected form submission.'));
}
}
}
示例13: connectNewUser
function connectNewUser()
{
$nickname = $this->trimmed('nickname');
$password = $this->trimmed('password');
if (!common_check_user($nickname, $password)) {
// TRANS: Form validation error displayed when username/password combination is incorrect.
$this->showForm(_m('Invalid username or password.'));
return;
}
$user = User::staticGet('nickname', $nickname);
if (!empty($user)) {
common_debug(sprintf('Found a legit user to connect to Facebook: %s (%d)', $user->nickname, $user->id), __FILE__);
}
$this->tryLinkUser($user);
common_set_user($user);
common_real_login(true);
$this->goHome($user->nickname);
}
示例14: connectNewUser
function connectNewUser()
{
$nickname = $this->trimmed('nickname');
$password = $this->trimmed('password');
if (!common_check_user($nickname, $password)) {
// TRANS: Form validation error displayed when connecting an existing user to a Twitter user fails because
// TRANS: the provided username and/or password are incorrect.
$this->showForm(_m('Invalid username or password.'));
return;
}
$user = User::staticGet('nickname', $nickname);
if (!empty($user)) {
common_debug('TwitterBridge Plugin - ' . "Legit user to connect to Twitter: {$nickname}");
}
$result = $this->saveForeignLink($user->id, $this->twuid, $this->access_token);
save_twitter_user($this->twuid, $this->tw_fields['screen_name']);
if (!$result) {
// TRANS: Server error displayed connecting a user to a Twitter user has failed.
$this->serverError(_m('Error connecting user to Twitter.'));
return;
}
common_debug('TwitterBridge Plugin - ' . "Connected Twitter user {$this->twuid} to local user {$user->id}");
common_set_user($user);
common_real_login(true);
$this->goHome($user->nickname);
}
示例15: connectUser
function connectUser()
{
$nickname = $this->trimmed('nickname');
$password = $this->trimmed('password');
if (!common_check_user($nickname, $password)) {
// TRANS: OpenID plugin message.
$this->showForm(_m('Invalid username or password.'));
return;
}
# They're legit!
$user = User::staticGet('nickname', $nickname);
list($display, $canonical, $sreg) = $this->getSavedValues();
if (!$display || !$canonical) {
// TRANS: OpenID plugin server error. A stored OpenID cannot be found.
$this->serverError(_m('Stored OpenID not found.'));
return;
}
$result = oid_link_user($user->id, $canonical, $display);
if (!$result) {
// TRANS: OpenID plugin server error. The user or user profile could not be saved.
$this->serverError(_m('Error connecting user to OpenID.'));
return;
}
if (Event::handle('StartOpenIDUpdateUser', array($user, $canonical, &$sreg))) {
oid_update_user($user, $sreg);
}
Event::handle('EndOpenIDUpdateUser', array($user, $canonical, $sreg));
oid_set_last($display);
common_set_user($user);
common_real_login(true);
if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
common_rememberme($user);
}
unset($_SESSION['openid_rememberme']);
$this->goHome($user->nickname);
}