provide auto admin registration as before, but allow the current admin to create other admins

This commit is contained in:
friendica 2012-10-04 23:05:45 -07:00
parent 4302134fdd
commit 7bee460df2
9 changed files with 46 additions and 15 deletions

View File

@ -9,6 +9,7 @@ require_once('include/language.php');
require_once('include/nav.php'); require_once('include/nav.php');
require_once('include/cache.php'); require_once('include/cache.php');
require_once('library/Mobile_Detect/Mobile_Detect.php'); require_once('library/Mobile_Detect/Mobile_Detect.php');
require_once('object/BaseObject.php');
define ( 'FRIENDICA_PLATFORM', 'Friendica Red'); define ( 'FRIENDICA_PLATFORM', 'Friendica Red');
define ( 'FRIENDICA_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'FRIENDICA_VERSION', trim(file_get_contents('version.inc')) . 'R');
@ -327,7 +328,8 @@ define ( 'ACCOUNT_ROLE_ADMIN', 0x1000 );
function startup() { function startup() {
error_reporting(E_ERROR | E_WARNING | E_PARSE); error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_time_limit(0);
@set_time_limit(0);
// This has to be quite large to deal with embedded private photos // This has to be quite large to deal with embedded private photos
ini_set('pcre.backtrack_limit', 500000); ini_set('pcre.backtrack_limit', 500000);
@ -367,16 +369,16 @@ function startup() {
if(! class_exists('App')) { if(! class_exists('App')) {
class App { class App {
public $account = null; public $account = null; // account record
private $channel = null; private $channel = null; // channel record
private $observer = null; private $observer = null; // xchan record
private $widgets = array(); private $widgets = array(); // widgets for this page
public $language; public $language;
public $module_loaded = false; public $module_loaded = false;
public $query_string; public $query_string;
public $config; public $config; // config cache
public $page; public $page;
public $profile; public $profile;
public $user; public $user;
@ -548,6 +550,8 @@ if(! class_exists('App')) {
$mobile_detect = new Mobile_Detect(); $mobile_detect = new Mobile_Detect();
$this->is_mobile = $mobile_detect->isMobile(); $this->is_mobile = $mobile_detect->isMobile();
$this->is_tablet = $mobile_detect->isTablet(); $this->is_tablet = $mobile_detect->isTablet();
BaseObject::set_app($this);
} }
function get_baseurl($ssl = false) { function get_baseurl($ssl = false) {
@ -606,6 +610,14 @@ if(! class_exists('App')) {
return $this->path; return $this->path;
} }
function set_account($aid) {
$this->account = $aid;
}
function get_account() {
return $this->account;
}
function set_channel($channel) { function set_channel($channel) {
$this->channel = $channel; $this->channel = $channel;
} }

View File

@ -37,7 +37,7 @@ $a->config['sitename'] = "Friendica Social Network";
$a->config['system']['register_policy'] = REGISTER_OPEN; $a->config['system']['register_policy'] = REGISTER_OPEN;
$a->config['register_text'] = ''; $a->config['register_text'] = '';
$a->config['admin_email'] = ''; $a->config[system']['admin_email'] = '';
// Maximum size of an imported message, 0 is unlimited // Maximum size of an imported message, 0 is unlimited

View File

@ -77,6 +77,15 @@ function check_account_invite($invite_code) {
} }
function check_account_admin($arr) {
if(is_site_admin())
return true;
$admin_mail = trim(get_config('system','admin_email'));
if(strlen($admin_email) && $admin_email === trim($arr['email']))
return true;
return false;
}
function create_account($arr) { function create_account($arr) {
@ -90,6 +99,7 @@ function create_account($arr) {
$password2 = ((x($arr,'password2')) ? trim($arr['password2']) : ''); $password2 = ((x($arr,'password2')) ? trim($arr['password2']) : '');
$parent = ((x($arr,'parent')) ? intval($arr['parent']) : 0 ); $parent = ((x($arr,'parent')) ? intval($arr['parent']) : 0 );
$flags = ((x($arr,'account_flags')) ? intval($arr['account_flags']) : ACCOUNT_OK); $flags = ((x($arr,'account_flags')) ? intval($arr['account_flags']) : ACCOUNT_OK);
$roles = ((x($arr,'account_roles')) ? intval($arr['account_roles']) : 0 );
$default_service_class = get_config('system','default_service_class'); $default_service_class = get_config('system','default_service_class');
if($default_service_class === false) if($default_service_class === false)
@ -100,6 +110,13 @@ function create_account($arr) {
return $result; return $result;
} }
if($roles & ACCOUNT_ROLE_ADMIN) {
$admin_result = check_account_admin($arr);
if(! $admin_result) {
$roles = 0;
}
}
$invite_result = check_account_invite($invite_code); $invite_result = check_account_invite($invite_code);
if($invite_result['error']) { if($invite_result['error']) {
$result['message'] = $invite_result['message']; $result['message'] = $invite_result['message'];
@ -134,7 +151,7 @@ function create_account($arr) {
dbesc(get_best_language()), dbesc(get_best_language()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($flags), dbesc($flags),
dbesc(0), dbesc($roles),
dbesc($expires), dbesc($expires),
dbesc($default_service_class) dbesc($default_service_class)

View File

@ -10,9 +10,9 @@ function authenticate_success($user_record, $login_initial = false, $interactive
// logger('authenticate_success: ' . print_r($_SESSION,true)); // logger('authenticate_success: ' . print_r($_SESSION,true));
if(x($user_record,'account_id')) { if(x($user_record,'account_id')) {
logger('authenticate_success: Red-style'); // logger('authenticate_success: Red-style');
$a->account = $user_record; $a->account = $user_record;
$_SESSION['account_id'] = $a->account['account_id']; $_SESSION['account_id'] = $user_record['account_id'];
$_SESSION['authenticated'] = 1; $_SESSION['authenticated'] = 1;
if($login_initial) { if($login_initial) {

View File

@ -13,10 +13,8 @@
*/ */
require_once('boot.php'); require_once('boot.php');
require_once('object/BaseObject.php');
$a = new App; $a = new App;
BaseObject::set_app($a);
/** /**
* *

View File

@ -6,7 +6,7 @@ $install_wizard_pass=1;
function install_init(&$a){ function install_init(&$a){
// $baseurl/install/testrwrite to test if rewite in .htaccess is working // $baseurl/install/testrwrite to test if rewite in .htaccess is working
if ($a->argc==2 && $a->argv[1]=="testrewrite") { if (argc() ==2 && argv(1)=="testrewrite") {
echo "ok"; echo "ok";
killme(); killme();
} }

View File

@ -22,6 +22,10 @@ require_once('include/items.php');
function item_post(&$a) { function item_post(&$a) {
// This will change. Figure out who the observer is and whether or not
// they have permission to post here. Else ignore the post.
if((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter'))) if((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter')))
return; return;

View File

@ -1 +1 @@
2012-10-03.96 2012-10-04.97

View File

@ -33,7 +33,7 @@ $a->config['sitename'] = "My Friend Network";
$a->config['register_policy'] = REGISTER_OPEN; $a->config['register_policy'] = REGISTER_OPEN;
$a->config['register_text'] = ''; $a->config['register_text'] = '';
$a->config['admin_email'] = '$adminmail'; $a->config['system']['admin_email'] = '$adminmail';
// Maximum size of an imported message, 0 is unlimited // Maximum size of an imported message, 0 is unlimited