X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fauth.php;h=1f16b350479a9074da639249f35cb336eee229bc;hb=5b3f6459392ba6f417cfc5cb0d38094c009c6913;hp=d2bcb68dc8caf6557c68e968d26484a6d1fa921a;hpb=fd9b506c2f19750bdea532b63c6ff28424ec5a7b;p=friendica.git diff --git a/include/auth.php b/include/auth.php index d2bcb68dc8..1f16b35047 100644 --- a/include/auth.php +++ b/include/auth.php @@ -24,8 +24,17 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p // process logout request nuke_session(); - notice( t('Logged out.') . EOL); - goaway($a->get_baseurl()); + info( t('Logged out.') . EOL); + goaway(z_root()); + } + + if(x($_SESSION,'visitor_id') && (! x($_SESSION,'uid'))) { + $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", + intval($_SESSION['visitor_id']) + ); + if(count($r)) { + $a->contact = $r[0]; + } } if(x($_SESSION,'uid')) { @@ -36,16 +45,17 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p // extra paranoia - if the IP changed, log them out if($check && ($_SESSION['addr'] != $_SERVER['REMOTE_ADDR'])) { nuke_session(); - goaway($a->get_baseurl()); + goaway(z_root()); } - $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", + $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` + FROM `user` WHERE `uid` = %d AND `blocked` = 0 AND `account_expired` = 0 AND `verified` = 1 LIMIT 1", intval($_SESSION['uid']) ); if(! count($r)) { nuke_session(); - goaway($a->get_baseurl()); + goaway(z_root()); } // initialise user environment @@ -53,11 +63,27 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p $a->user = $r[0]; $_SESSION['theme'] = $a->user['theme']; $_SESSION['page_flags'] = $a->user['page-flags']; - if(strlen($a->user['timezone'])) + + $member_since = strtotime($a->user['register_date']); + if(time() < ($member_since + ( 60 * 60 * 24 * 14))) + $_SESSION['new_member'] = true; + else + $_SESSION['new_member'] = false; + + if(strlen($a->user['timezone'])) { date_default_timezone_set($a->user['timezone']); + $a->timezone = $a->user['timezone']; + } $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $a->user['nickname']; + $r = q("SELECT `uid`,`username` FROM `user` WHERE `password` = '%s' AND `email` = '%s'", + dbesc($a->user['password']), + dbesc($a->user['email']) + ); + if(count($r)) + $a->identities = $r; + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($_SESSION['uid'])); if(count($r)) { @@ -93,7 +119,7 @@ else { if(($noid) || (strpos($temp_string,'@')) || (! validate_url($temp_string))) { $a = get_app(); notice( t('Login failed.') . EOL); - goaway($a->get_baseurl()); + goaway(z_root()); // NOTREACHED } @@ -118,7 +144,7 @@ else { if($a->config['register_policy'] == REGISTER_CLOSED) { $a = get_app(); notice( t('Login failed.') . EOL); - goaway($a->get_baseurl()); + goaway(z_root()); // NOTREACHED } // new account @@ -158,8 +184,9 @@ else { // process normal login request - $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) - AND `password` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1", + $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` + FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) + AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `verified` = 1 LIMIT 1", dbesc(trim($_POST['openid_url'])), dbesc(trim($_POST['openid_url'])), dbesc($encrypted) @@ -171,7 +198,7 @@ else { if((! $record) || (! count($record))) { logger('authenticate: failed login attempt: ' . trim($_POST['openid_url'])); notice( t('Login failed.') . EOL ); - goaway($a->get_baseurl()); + goaway(z_root()); } $_SESSION['uid'] = $record['uid']; @@ -181,20 +208,50 @@ else { $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $record['nickname']; $_SESSION['addr'] = $_SERVER['REMOTE_ADDR']; - notice( t("Welcome back ") . $record['username'] . EOL); $a->user = $record; - if(strlen($a->user['timezone'])) + + if($a->user['login_date'] === '0000-00-00 00:00:00') { + $_SESSION['return_url'] = 'profile_photo/new'; + $a->module = 'profile_photo'; + info( t("Welcome ") . $a->user['username'] . EOL); + info( t('Please upload a profile photo.') . EOL); + } + else + info( t("Welcome back ") . $a->user['username'] . EOL); + + + $member_since = strtotime($a->user['register_date']); + if(time() < ($member_since + ( 60 * 60 * 24 * 14))) + $_SESSION['new_member'] = true; + else + $_SESSION['new_member'] = false; + + if(strlen($a->user['timezone'])) { date_default_timezone_set($a->user['timezone']); + $a->timezone = $a->user['timezone']; + } - $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1", + $r = q("SELECT `uid`,`username` FROM `user` WHERE `password` = '%s' AND `email` = '%s'", + dbesc($a->user['password']), + dbesc($a->user['email']) + ); + if(count($r)) + $a->identities = $r; + + + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($_SESSION['uid'])); if(count($r)) { $a->contact = $r[0]; $a->cid = $r[0]['id']; $_SESSION['cid'] = $a->cid; } - q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1", + + $l = get_language(); + + q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d LIMIT 1", dbesc(datetime_convert()), + dbesc($l), intval($_SESSION['uid']) );