From 7fad83cea4dd134df6dacf8248ef6947dca7f100 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 27 Aug 2012 21:17:46 -0700 Subject: Now logging in with Red zaccount/zentity instead of Friendica user. Yay. Most existing Friendica functionality is now stuffed since the Red structures are quite different. --- INSTALL.txt | 9 +-- database.sql | 2 +- include/account.php | 6 +- include/auth.php | 56 ++++++++------ include/js_strings.php | 1 + include/security.php | 192 ++++++++++++++++++++++++++++++------------------ mod/settings.php | 61 +++------------ mod/zentity.php | 6 +- mod/zregister.php | 13 +++- version.inc | 2 +- view/js/mod_settings.js | 21 ++++++ view/tpl/js_strings.tpl | 1 + view/tpl/settings.tpl | 3 - 13 files changed, 216 insertions(+), 157 deletions(-) create mode 100644 view/js/mod_settings.js diff --git a/INSTALL.txt b/INSTALL.txt index f6b97a890..e6adbba7d 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -32,15 +32,14 @@ link if your cert is self-signed). - Apache with mod-rewrite enabled and "Options All" so you can use a local .htaccess file - - PHP 5.3+. The later the better. PHP 5.3 is required for communications -with the Diaspora network and improved security. + - PHP 5.3+. The later the better. - - PHP *command line* access with register_argc_argv set to true in the + - PHP *command line* access with register_argc_argv set to true in the php.ini file [or see 'poormancron' in section 8] - - curl, gd (with at least jpeg support), mysql, mbstring, mcrypt, and openssl extensions + - curl, gd (with at least jpeg support), mysql, mbstring, mcrypt, and openssl extensions - - some form of email server or email gateway such that PHP mail() works + - some form of email server or email gateway such that PHP mail() works - Mysql 5.x diff --git a/database.sql b/database.sql index 15dbd0789..08832af11 100644 --- a/database.sql +++ b/database.sql @@ -227,7 +227,7 @@ CREATE TABLE IF NOT EXISTS `entity` ( `entity_name` char(255) NOT NULL DEFAULT '', `entity_address` char(255) NOT NULL DEFAULT '', `entity_global_id` char(255) NOT NULL DEFAULT '', - `entity_timezone` char(128) NOT NULL DEFAULT '', + `entity_timezone` char(128) NOT NULL DEFAULT 'UTC', `entity_location` char(255) NOT NULL DEFAULT '', `entity_theme` char(255) NOT NULL DEFAULT '', `entity_pubkey` text NOT NULL, diff --git a/include/account.php b/include/account.php index e08b129f3..fa56afe7d 100644 --- a/include/account.php +++ b/include/account.php @@ -91,6 +91,10 @@ function create_account($arr) { $parent = ((x($arr,'parent')) ? intval($arr['parent']) : 0 ); $flags = ((x($arr,'account_flags')) ? intval($arr['account_flags']) : ACCOUNT_OK); + $default_service_class = get_config('system','default_service_class'); + if($default_service_class === false) + $default_service_class = ''; + if((! x($email)) || (! x($password))) { $result['message'] = t('Please enter the required information.'); return $result; @@ -236,7 +240,7 @@ function send_reg_approval_email($arr) { function send_verification_email($email,$password) { $email_msg = replace_macros(get_intltext_template('register_open_eml.tpl'), array( - '$sitename' => $get_config('config','sitename'), + '$sitename' => get_config('config','sitename'), '$siteurl' => z_root(), '$email' => $email, '$password' => $password, diff --git a/include/auth.php b/include/auth.php index 4dfe74472..1e1df1808 100644 --- a/include/auth.php +++ b/include/auth.php @@ -5,6 +5,7 @@ require_once('include/security.php'); function nuke_session() { unset($_SESSION['authenticated']); + unset($_SESSION['account_id']); unset($_SESSION['uid']); unset($_SESSION['visitor_id']); unset($_SESSION['administrator']); @@ -70,7 +71,7 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p } } - if(x($_SESSION,'uid')) { + if(x($_SESSION,'uid') || x($_SESSION,'account_id')) { // already logged in user returning @@ -83,18 +84,27 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p goaway(z_root()); } - $r = q("select * from account where account_id = %d limit 1", - intval($_SESSION['account_id']) - ); - if(count($r) && (($r[0]['account_flags'] == ACCOUNT_OK) || ($r[0]['account_flags'] == ACCOUNT_UNVERIFIED))) - get_app()->account = $r[0]; - else - $_SESSION['account_id'] = 0; - - $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(x($_SESSION,'account_id')) { + $r = q("select * from account where account_id = %d limit 1", + intval($_SESSION['account_id']) + ); + if(count($r) && (($r[0]['account_flags'] == ACCOUNT_OK) || ($r[0]['account_flags'] == ACCOUNT_UNVERIFIED))) { + get_app()->account = $r[0]; + authenticate_success($r[0]); + } + else { + $_SESSION['account_id'] = 0; + nuke_session(); + goaway(z_root()); + } + } + else { + $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(); @@ -139,7 +149,7 @@ else { } else { - get_app()->account = account_verify_password($_POST['username'],$_POST['password']); + $record = get_app()->account = account_verify_password($_POST['username'],$_POST['password']); if(get_app()->account) { $_SESSION['account_id'] = get_app()->account['account_id']; @@ -153,15 +163,15 @@ else { // process normal login request - $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)) - $record = $r[0]; +// $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)) +// $record = $r[0]; } if((! $record) || (! count($record))) { diff --git a/include/js_strings.php b/include/js_strings.php index e9892ea72..60a3e1a86 100644 --- a/include/js_strings.php +++ b/include/js_strings.php @@ -8,6 +8,7 @@ function js_strings() { '$showfewer' => t('show fewer'), '$pwshort' => t("Password too short"), '$pwnomatch' => t("Passwords do not match"), + '$everybody' => t('everybody'), '$t01' => ((t('timeago.prefixAgo') != 'timeago.prefixAgo') ? t('timeago.prefixAgo') : 'null'), '$t02' => ((t('timeago.suffixAgo') != 'timeago.suffixAgo') ? t('timeago.suffixAgo') : 'null'), diff --git a/include/security.php b/include/security.php index af201d2af..51221837b 100644 --- a/include/security.php +++ b/include/security.php @@ -1,95 +1,147 @@ get_baseurl() . '/profile/' . $user_record['nickname']; - $_SESSION['my_address'] = $user_record['nickname'] . '@' . substr($a->get_baseurl(),strpos($a->get_baseurl(),'://')+3); $_SESSION['addr'] = $_SERVER['REMOTE_ADDR']; - $a->user = $user_record; +// logger('authenticate_success: ' . print_r($user_record,true)); +// logger('authenticate_success: ' . print_r($_SESSION,true)); + + if(x($user_record,'account_id')) { + logger('authenticate_success: Red-style'); + $a->account = $user_record; + $_SESSION['account_id'] = $a->account['account_id']; + $_SESSION['authenticated'] = 1; + + if($login_initial) { + q("update account set account_lastlog = '%s' where account_id = %d limit 1", + dbesc(datetime_convert()), + intval($_SESSION['account_id']) + ); + $a->account['account_lastlog'] = datetime_convert(); + call_hooks('logged_in', $a->account); - if($interactive) { - 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']; - } + $uid_to_load = (((x($_SESSION,'uid')) && (intval($_SESSION['uid']))) ? intval($_SESSION['uid']) : 0); + if(! $uid_to_load) + $uid_to_load = intval($a->account['account_default_entity']); - $master_record = $a->user; + if($uid_to_load) { + $r = q("select * from entity where entity_id = %d and entity_account_id = %d limit 1", + intval($uid_to_load), + intval($a->account['account_id']) + ); + if($r && count($r)) { + $_SESSION['uid'] = intval($r[0]['entity_id']); + $a->identity = $r[0]; + $_SESSION['theme'] = $a->identity['entity_theme']; + date_default_timezone_set($a->identity['entity_timezone']); + } + + } - if((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) { - $r = q("select * from user where uid = %d limit 1", - intval($_SESSION['submanage']) - ); - if(count($r)) - $master_record = $r[0]; - } - $r = q("SELECT `uid`,`username`,`nickname` FROM `user` WHERE `password` = '%s' AND `email` = '%s'", - dbesc($master_record['password']), - dbesc($master_record['email']) - ); - if($r && count($r)) - $a->identities = $r; - else - $a->identities = array(); - - $r = q("select `user`.`uid`, `user`.`username`, `user`.`nickname` - from manage left join user on manage.mid = user.uid - where `manage`.`uid` = %d", - intval($master_record['uid']) - ); - if($r && count($r)) - $a->identities = array_merge($a->identities,$r); - - if($login_initial) - logger('auth_identities: ' . print_r($a->identities,true), LOGGER_DEBUG); - - $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; } + else { + $_SESSION['uid'] = $user_record['uid']; + $_SESSION['theme'] = $user_record['theme']; + $_SESSION['authenticated'] = 1; + $_SESSION['page_flags'] = $user_record['page-flags']; + $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $user_record['nickname']; + $_SESSION['my_address'] = $user_record['nickname'] . '@' . substr($a->get_baseurl(),strpos($a->get_baseurl(),'://')+3); + + $a->user = $user_record; + + if($interactive) { + 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']; + } + + $master_record = $a->user; - header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"'); + if((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) { + $r = q("select * from user where uid = %d limit 1", + intval($_SESSION['submanage']) + ); + if(count($r)) + $master_record = $r[0]; + } - if($login_initial) { - $l = get_browser_language(); + $r = q("SELECT `uid`,`username`,`nickname` FROM `user` WHERE `password` = '%s' AND `email` = '%s'", + dbesc($master_record['password']), + dbesc($master_record['email']) + ); + if($r && count($r)) + $a->identities = $r; + else + $a->identities = array(); - q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d LIMIT 1", - dbesc(datetime_convert()), - dbesc($l), - intval($_SESSION['uid']) + $r = q("select `user`.`uid`, `user`.`username`, `user`.`nickname` + from manage left join user on manage.mid = user.uid + where `manage`.`uid` = %d", + intval($master_record['uid']) ); + if($r && count($r)) + $a->identities = array_merge($a->identities,$r); + + if($login_initial) + logger('auth_identities: ' . print_r($a->identities,true), LOGGER_DEBUG); + + $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; + } + + header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"'); + + if($login_initial) { + $l = get_browser_language(); + + q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d LIMIT 1", + dbesc(datetime_convert()), + dbesc($l), + intval($_SESSION['uid']) + ); - call_hooks('logged_in', $a->user); + call_hooks('logged_in', $a->user); - if(($a->module !== 'home') && isset($_SESSION['return_url'])) - goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); + } + } + + + if($return || $_SESSION['workflow']) { + unset($_SESSION['workflow']); + return; } + + + if(($a->module !== 'home') && isset($_SESSION['return_url'])) + goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); + + } diff --git a/mod/settings.php b/mod/settings.php index 38d0490bf..478158b68 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -16,35 +16,6 @@ function get_theme_config_file($theme){ function settings_init(&$a) { - // These lines provide the javascript needed by the acl selector - - $a->page['htmlhead'] .= " -EOT; - - - $tabs = array( array( 'label' => t('Account settings'), @@ -671,15 +642,17 @@ function settings_content(&$a) { if(count($p)) $profile = $p[0]; - $username = $a->user['username']; - $email = $a->user['email']; - $nickname = $a->user['nickname']; - $timezone = $a->user['timezone']; - $notify = $a->user['notify-flags']; - $defloc = $a->user['default-location']; - $openid = $a->user['openid']; - $maxreq = $a->user['maxreq']; - $expire = ((intval($a->user['expire'])) ? $a->user['expire'] : ''); + load_pconfig(local_user(),'expire'); + + $username = $a->identity['entity_name']; + $email = $a->account['account_email']; + $nickname = $a->identity['entity_address']; + $timezone = $a->identity['entity_timezone']; + $notify = $a->identity['entity_notifyflags']; + $defloc = $a->identity['entity_location']; + + $maxreq = $a->identity['entity_max_friend_req']; + $expire = get_pconfig(local_user(),'expire','content_expire_days'); $blockwall = $a->user['blockwall']; $blocktags = $a->user['blocktags']; $unkmail = $a->user['unkmail']; @@ -714,8 +687,7 @@ function settings_content(&$a) { $post_profilechange = (($post_profilechange===false)? '0': $post_profilechange); // default if not set: 0 - if(! strlen($a->user['timezone'])) - $timezone = date_default_timezone_get(); + $timezone = date_default_timezone_get(); @@ -744,15 +716,6 @@ function settings_content(&$a) { )); - $noid = get_config('system','no_openid'); - - if($noid) { - $openid_field = false; - } - else { - $openid_field = array('openid_url', t('OpenID:'),$openid, t("\x28Optional\x29 Allow this OpenID to login to this account.")); - } - $opt_tpl = get_markup_template("field_yesno.tpl"); if(get_config('system','publish_all')) { diff --git a/mod/zentity.php b/mod/zentity.php index 74403cfb5..9e90dd263 100644 --- a/mod/zentity.php +++ b/mod/zentity.php @@ -73,7 +73,11 @@ function zentity_post(&$a) { return; } - return; + if(! strlen($next_page = get_config('system','workflow_identity_next'))) + $next_page = 'settings'; + + goaway(z_root() . '/' . $next_page); + } diff --git a/mod/zregister.php b/mod/zregister.php index a9a622213..478921c3f 100644 --- a/mod/zregister.php +++ b/mod/zregister.php @@ -75,7 +75,6 @@ function zregister_post(&$a) { } require_once('include/security.php'); - authenticate_success($result['account'],true,true); $using_invites = intval(get_config('system','invitation_only')); $num_invites = intval(get_config('system','number_invites')); @@ -90,7 +89,6 @@ function zregister_post(&$a) { $res = send_verification_email($result['email'],$result['password']); if($res) { info( t('Registration successful. Please check your email for validation instructions.') . EOL ) ; - goaway(z_root()); } } elseif($policy == REGISTER_APPROVE) { @@ -103,7 +101,16 @@ function zregister_post(&$a) { } goaway(z_root()); } - return; + + authenticate_success($result['account'],true,false,true); + + if(! strlen($next_page = get_config('system','workflow_register_next'))) + $next_page = 'zentity'; + + $_SESSION['workflow'] = true; + + goaway(z_root() . '/' . $next_page); + } diff --git a/version.inc b/version.inc index e6bb6ffb5..35af6d29c 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2012-08-26.58 +2012-08-27.59 diff --git a/view/js/mod_settings.js b/view/js/mod_settings.js new file mode 100644 index 000000000..bcfa9b574 --- /dev/null +++ b/view/js/mod_settings.js @@ -0,0 +1,21 @@ + +var ispublic = aStr['everybody'] ; + +$(document).ready(function() { + + $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() { + var selstr; + $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() { + selstr = $(this).text(); + $('#jot-perms-icon').removeClass('unlock').addClass('lock'); + $('#jot-public').hide(); + }); + if(selstr == null) { + $('#jot-perms-icon').removeClass('lock').addClass('unlock'); + $('#jot-public').show(); + } + + }).trigger('change'); + +}); + diff --git a/view/tpl/js_strings.tpl b/view/tpl/js_strings.tpl index a5f50b33f..babb1b219 100644 --- a/view/tpl/js_strings.tpl +++ b/view/tpl/js_strings.tpl @@ -9,6 +9,7 @@ 'showfewer' : '$showfewer', 'pwshort' : '$pwshort', 'pwnomatch' : '$pwnomatch', + 'everybody' : '$everybody', 't01' : $t01, 't02' : $t02, diff --git a/view/tpl/settings.tpl b/view/tpl/settings.tpl index bebd0c12a..ce96fb8d2 100644 --- a/view/tpl/settings.tpl +++ b/view/tpl/settings.tpl @@ -10,9 +10,6 @@ $nickname_block {{inc field_password.tpl with $field=$password1 }}{{endinc}} {{inc field_password.tpl with $field=$password2 }}{{endinc}} -{{ if $oid_enable }} -{{inc field_input.tpl with $field=$openid }}{{endinc}} -{{ endif }}
-- cgit v1.2.3