]> git.mxchange.org Git - friendica.git/blobdiff - include/auth.php
mysql error report fix (no mysqli), suggested friends for new members settings
[friendica.git] / include / auth.php
index 4c7e85d86731bc004f3e18c0cf7aaed849970b37..45c71c66b3db7944312189b2c7186885f2598f80 100644 (file)
@@ -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
@@ -54,6 +64,12 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
                $_SESSION['theme'] = $a->user['theme'];
                $_SESSION['page_flags'] = $a->user['page-flags'];
 
+               $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'];
@@ -88,11 +104,12 @@ else {
        if((x($_POST,'password')) && strlen($_POST['password']))
                $encrypted = hash('whirlpool',trim($_POST['password']));
        else {
-               if((x($_POST,'openid_url')) && strlen($_POST['openid_url'])) {
+               if((x($_POST,'openid_url')) && strlen($_POST['openid_url']) ||
+                  (x($_POST,'username')) && strlen($_POST['username'])) {
 
                        $noid = get_config('system','no_openid');
 
-                       $openid_url = trim($_POST['openid_url']);
+                       $openid_url = trim(  (strlen($_POST['openid_url'])?$_POST['openid_url']:$_POST['username']) );
 
                        // validate_url alters the calling parameter
 
@@ -103,7 +120,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
                        }
 
@@ -128,7 +145,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
@@ -145,7 +162,7 @@ else {
                $record = null;
 
                $addon_auth = array(
-                       'username' => trim($_POST['openid_url']), 
+                       'username' => trim($_POST['username']), 
                        'password' => trim($_POST['password']),
                        'authenticated' => 0,
                        'user_record' => null
@@ -168,10 +185,11 @@ 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",
-                               dbesc(trim($_POST['openid_url'])),
-                               dbesc(trim($_POST['openid_url'])),
+                       $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['username'])),
+                               dbesc(trim($_POST['username'])),
                                dbesc($encrypted)
                        );
                        if(count($r))
@@ -179,9 +197,9 @@ else {
                }
 
                if((! $record) || (! count($record))) {
-                       logger('authenticate: failed login attempt: ' . trim($_POST['openid_url'])); 
+                       logger('authenticate: failed login attempt: ' . trim($_POST['username'])); 
                        notice( t('Login failed.') . EOL );
-                       goaway($a->get_baseurl());
+                       goaway(z_root());
                }
 
                $_SESSION['uid'] = $record['uid'];
@@ -196,11 +214,18 @@ else {
                if($a->user['login_date'] === '0000-00-00 00:00:00') {
                        $_SESSION['return_url'] = 'profile_photo/new';
                        $a->module = 'profile_photo';
-                       notice( t("Welcome ") . $a->user['username'] . EOL);
-                       notice( t('Please upload a profile photo.') . EOL);
+                       info( t("Welcome ") . $a->user['username'] . EOL);
+                       info( t('Please upload a profile photo.') . EOL);
                }
                else
-                       notice( t("Welcome back ") . $a->user['username'] . EOL);
+                       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']);
@@ -223,9 +248,11 @@ else {
                        $_SESSION['cid'] = $a->cid;
                }
 
+               $l = get_language();
 
-               q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
+               q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d LIMIT 1",
                        dbesc(datetime_convert()),
+                       dbesc($l),
                        intval($_SESSION['uid'])
                );