use Friendica\Database\DBA;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Database\DBA;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
- return self::form(self::getApp()->get_baseurl(), intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED);
+ return self::form(defaults($_SESSION, 'return_path', null), intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED);
self::passwordAuthentication(
trim($_POST['username']),
trim($_POST['password']),
self::passwordAuthentication(
trim($_POST['username']),
trim($_POST['password']),
// if it's an email address or doesn't resolve to a URL, fail.
if ($noid || strpos($openid_url, '@') || !Network::isUrlValid($openid_url)) {
notice(L10n::t('Login failed.') . EOL);
// if it's an email address or doesn't resolve to a URL, fail.
if ($noid || strpos($openid_url, '@') || !Network::isUrlValid($openid_url)) {
notice(L10n::t('Login failed.') . EOL);
$openid->identity = $openid_url;
$_SESSION['openid'] = $openid_url;
$_SESSION['remember'] = $remember;
$openid->identity = $openid_url;
$_SESSION['openid'] = $openid_url;
$_SESSION['remember'] = $remember;
- $openid->returnUrl = self::getApp()->get_baseurl(true) . '/openid';
- goaway($openid->authUrl());
+ $openid->returnUrl = $a->getBaseURL(true) . '/openid';
+ System::externalRedirect($openid->authUrl());
/*
* An addon indicates successful login by setting 'authenticated' to non-zero value and returning a user record
* Addons should never set 'authenticated' except to indicate success - as hooks may be chained
/*
* An addon indicates successful login by setting 'authenticated' to non-zero value and returning a user record
* Addons should never set 'authenticated' except to indicate success - as hooks may be chained
- logger('authenticate: failed login attempt: ' . notags($username) . ' from IP ' . $_SERVER['REMOTE_ADDR']);
- notice($e->getMessage() . EOL);
- goaway(self::getApp()->get_baseurl() . '/login');
+ Logger::log('authenticate: failed login attempt: ' . Strings::escapeTags($username) . ' from IP ' . $_SERVER['REMOTE_ADDR']);
+ info('Login failed. Please check your credentials.' . EOL);
+ $a->internalRedirect();
}
// if we haven't failed up this point, log them in.
$_SESSION['remember'] = $remember;
$_SESSION['last_login_date'] = DateTimeFormat::utcNow();
}
// if we haven't failed up this point, log them in.
$_SESSION['remember'] = $remember;
$_SESSION['last_login_date'] = DateTimeFormat::utcNow();
- if (x($_SESSION, 'return_url')) {
- $return_url = $_SESSION['return_url'];
- unset($_SESSION['return_url']);
+ if (!empty($_SESSION['return_path'])) {
+ $return_path = $_SESSION['return_path'];
+ unset($_SESSION['return_path']);
// When the "Friendica" cookie is set, take the value to authenticate and renew the cookie.
if (isset($_COOKIE["Friendica"])) {
$data = json_decode($_COOKIE["Friendica"]);
// When the "Friendica" cookie is set, take the value to authenticate and renew the cookie.
if (isset($_COOKIE["Friendica"])) {
$data = json_decode($_COOKIE["Friendica"]);
- if ($data->hash != cookie_hash($user)) {
- logger("Hash for user " . $data->uid . " doesn't fit.");
- nuke_session();
- goaway(self::getApp()->get_baseurl());
+ if ($data->hash != Authentication::getCookieHashForUser($user)) {
+ Logger::log("Hash for user " . $data->uid . " doesn't fit.");
+ Authentication::deleteSession();
+ $a->internalRedirect();
}
// Renew the cookie
// Expires after 7 days by default,
// can be set via system.auth_cookie_lifetime
$authcookiedays = Config::get('system', 'auth_cookie_lifetime', 7);
}
// Renew the cookie
// Expires after 7 days by default,
// can be set via system.auth_cookie_lifetime
$authcookiedays = Config::get('system', 'auth_cookie_lifetime', 7);
// Do the authentification if not done by now
if (!isset($_SESSION) || !isset($_SESSION['authenticated'])) {
// Do the authentification if not done by now
if (!isset($_SESSION) || !isset($_SESSION['authenticated'])) {
if (Config::get('system', 'paranoia')) {
$_SESSION['addr'] = $data->ip;
if (Config::get('system', 'paranoia')) {
$_SESSION['addr'] = $data->ip;
- if (isset($_SESSION) && x($_SESSION, 'authenticated')) {
- if (x($_SESSION, 'visitor_id') && !x($_SESSION, 'uid')) {
+ if (!empty($_SESSION['authenticated'])) {
+ if (!empty($_SESSION['visitor_id']) && empty($_SESSION['uid'])) {
$contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id']]);
if (DBA::isResult($contact)) {
self::getApp()->contact = $contact;
}
}
$contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id']]);
if (DBA::isResult($contact)) {
self::getApp()->contact = $contact;
}
}
// already logged in user returning
$check = Config::get('system', 'paranoia');
// extra paranoia - if the IP changed, log them out
if ($check && ($_SESSION['addr'] != $_SERVER['REMOTE_ADDR'])) {
// already logged in user returning
$check = Config::get('system', 'paranoia');
// extra paranoia - if the IP changed, log them out
if ($check && ($_SESSION['addr'] != $_SERVER['REMOTE_ADDR'])) {
- authenticate_success($user, false, false, $login_refresh);
+ Authentication::setAuthenticatedSessionForUser($user, false, false, $login_refresh);
* back to after login completes
* @param bool $register If $register == true provide a registration link.
* This will most always depend on the value of config.register_policy.
* back to after login completes
* @param bool $register If $register == true provide a registration link.
* This will most always depend on the value of config.register_policy.
- $a->page['htmlhead'] .= replace_macros(
- get_markup_template('login_head.tpl'),
+ $a->page['htmlhead'] .= Renderer::replaceMacros(
+ Renderer::getMarkupTemplate('login_head.tpl'),
'$logout' => L10n::t('Logout'),
'$login' => L10n::t('Login'),
'$logout' => L10n::t('Logout'),
'$login' => L10n::t('Login'),