diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-10-09 15:46:38 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-10-09 15:46:38 -0400 |
commit | 4d2de268b75f08e6fa774063a277c2c50f603ef7 (patch) | |
tree | 8384dd7fce75b9ba7e31181c93da16923cb59235 /src | |
parent | 93b1163cba7edf1a0a7e7ae787e06434de119dad (diff) | |
parent | 2e769649abf4f9b3712287e24eb42c5a93a8035e (diff) |
Merge branch 'anon-userlist'
Diffstat (limited to 'src')
-rw-r--r-- | src/controllers/Config.class.php | 30 | ||||
-rw-r--r-- | src/controllers/Users.class.php | 90 | ||||
-rw-r--r-- | src/lib/DB.class.php | 43 | ||||
-rw-r--r-- | src/models/Auth.class.php | 1 | ||||
-rw-r--r-- | src/views/pages/users/index.html.php | 62 | ||||
-rw-r--r-- | src/views/pages/users/new.html.php | 10 |
6 files changed, 157 insertions, 79 deletions
diff --git a/src/controllers/Config.class.php b/src/controllers/Config.class.php new file mode 100644 index 0000000..37d1f09 --- /dev/null +++ b/src/controllers/Config.class.php @@ -0,0 +1,30 @@ +<?php +require_once('Auth.class.php'); + +Router::register('config', 'Config', 'index'); + +class Config extends Controller { + public function index($routed, $remainder) { + $uid = Login::isLoggedIn(); + if ($uid===false || !Auth::getObj($uid)->isAdmin()) { + $this->http401($routed, $remainder); + return; + } + + $method = $_SERVER['REQUEST_METHOD']; + switch ($method) { + case 'PUT': $_POST = $_PUT; + case 'POST': + // We're PUTing an updated configuration. + $this->update(); + break; + } + $this->show_index(); + } + private function show_index() { + + } + private function update() { + + } +} diff --git a/src/controllers/Users.class.php b/src/controllers/Users.class.php index 54e4675..dbd5120 100644 --- a/src/controllers/Users.class.php +++ b/src/controllers/Users.class.php @@ -72,8 +72,13 @@ class Users extends Controller { exit(); } if (!isset($vars['errors'])) $vars['errors'] = array(); - global $mm; $pm = $mm->pluginManager(); + + global $mm; + $pm = $mm->pluginManager(); + $db = $mm->database(); + $vars['antispam_html'] = $pm->callHook('antispam_html'); + $vars['userlist'] = $db->getSysConf('anon_userlist'); $this->showView('users/new', $vars); } @@ -273,49 +278,28 @@ class Users extends Controller { */ private function update_users() { $attribs = $this->getIndexAttribs(); + $form = new Form(null, null); foreach ($attribs as $attrib) { $key = $attrib['key']; if (isset($_POST[$key]) && is_array($_POST[$key])) { $old = $_POST['_old'][$key]; foreach ($_POST[$key] as $uid => $value) { - $doit = true; - $forked = false; - $have_old = isset($old[$uid]); - if ($have_old) { - @$value_base = $old[$uid]; - $we_changed_it = $value_base != $value; - if ($we_changed_it) { - $value_fork = DB::get('users', $uid, $key); - $value_fork = $value_fork['value']; - if ($value_fork===false) $value_fork = 'false'; - if ($value_fork===true) $value_fork = 'true'; - - $someone_else_changed_it = $value_fork != $value_base; - if ($someone_else_changed_it) { - if ($value == $value_fork) { - // we might as well not have - $we_changed_it = false; - } else { - $forked = true; - } - } - } - if (!$we_changed_it) { - $doit = false;// nothing to do - } - } - if ($doit) { - DB::set('users', $uid, $key, $value); - } - if ($forked) { + @$value_base = $old[$uid]; + $set = DB::set('users', $uid, $key, $value, $value_base); + if (is_string($set)) { echo "<pre>\n"; - echo "Error: Value changed elsewhere, and I don't have real handling for this yet.\n"; + echo "Error: Value changed elsewhere, ". + "and I don't have real handling ". + "for this yet.\n"; echo "UID: $uid\n"; echo "Name: ".$user->getName()."\n"; echo "Key: $key\n"; - echo "Value: Original : "; var_dump($value_base); - echo "Value: Other edit: "; var_dump($value_fork); - echo "Value: This edit : "; var_dump($value); + echo "Value: Original : "; + var_dump($value_base); + echo "Value: Other edit: "; + var_dump($value_fork); + echo "Value: This edit : "; + var_dump($value); echo "</pre>"; } } @@ -330,7 +314,8 @@ class Users extends Controller { global $mm; $db = $mm->database(); $logged_in_user = Auth::getObj(Login::isLoggedIn()); - if (!$logged_in_user->isUser()) { + $anon_userlist = $db->getSysConf('anon_userlist')=='true'; + if (!$anon_userlist && !$logged_in_user->isUser()) { $this->http401($routed, $remainder); exit(); } @@ -349,23 +334,30 @@ class Users extends Controller { } $this->showView('users/index', $vars); } - - function attrib($key, $name) { - return array('key'=>$key, 'name'=>$name); + + function attrib($key, $name, $type='string') { + return array('key'=>$key, 'name'=>$name, 'type'=>$type); } private function getIndexAttribs() { + $user = Auth::getObj(Login::isLoggedIn()); + $attribs = array(); - $attribs[] = $this->attrib('auth_user', 'Active'); - if (Auth::getObj(Login::isLoggedIn())->isAdmin()) { - $attribs[] = $this->attrib('auth_admin', 'Admin'); - $attribs[] = $this->attrib('auth_delete', 'Delete'); + if ($user->isUser()) { + $attribs[] = $this->attrib('auth_uid', 'UID'); + $attribs[] = $this->attrib('auth_user', 'Active', 'bool'); + if ($user->isAdmin()) { + $attribs[] = $this->attrib('auth_admin', 'Admin', 'bool'); + $attribs[] = $this->attrib('auth_delete', 'Delete', 'bool'); + } + $attribs[] = $this->attrib('lastname','Last'); + $attribs[] = $this->attrib('firstname','First'); + $attribs[] = $this->attrib('hsclass','Class of'); + $attribs[] = $this->attrib('phone','Phone number'); + $attribs[] = $this->attrib('email','Email'); + } else { + $attribs[] = $this->attrib('auth_uid', 'UID'); + $attribs[] = $this->attrib('auth_name', 'Username'); } - $attribs[] = $this->attrib('lastname','Last'); - $attribs[] = $this->attrib('firstname','First'); - $attribs[] = $this->attrib('hsclass','Class of'); - $attribs[] = $this->attrib('phone','Phone number'); - $attribs[] = $this->attrib('email','Email'); - $attribs[] = $this->attrib('auth_name', 'Username'); return $attribs; } diff --git a/src/lib/DB.class.php b/src/lib/DB.class.php index 9f14161..5954726 100644 --- a/src/lib/DB.class.php +++ b/src/lib/DB.class.php @@ -4,6 +4,39 @@ require_once('Auth.class.php'); require_once('Login.class.php'); class DB { + public static function set($table, $unit, $key, $value, $orig_value) { + $value_base = $orig_value; + + $doit = true; + $forked = false; + $have_old = ($value_base!==null); + if ($have_old) { + $we_changed_it = $value_base != $value; + if ($we_changed_it) { + $value_fork = $this->getConfString($key); + $someone_else_changed_it = + $value_fork != $value_base; + if ($someone_else_changed_it) { + if ($value == $value_fork) { + // we might as well not have + $we_changed_it = false; + } else { + $forked = true; + } + } + } + if (!$we_changed_it) { + $doit = false;// nothing to do + } + } + if ($doit) { + return $this->setConf($key, $value); + } + if ($forked) { + return $value_fork; + } + } + public static function get($table, $unit, $key) { switch ($table) { case 'conf': @@ -17,7 +50,7 @@ class DB { return false; } } - public static function set($table, $unit, $key, $value) { + public static function raw_set($table, $unit, $key, $value) { switch ($table) { case 'conf': case 'plugins': @@ -49,15 +82,15 @@ class DB { break; case 'auth_user': $editable = $editable && $logged_in_user->isAdmin(); - $value = $user->isUser(); + $value = $user->isUser()?'true':'false'; break; case 'auth_admin': $editable = $editable && $logged_in_user->isAdmin(); - $value = $user->isAdmin(); + $value = $user->isAdmin()?'true':'false'; break; case 'auth_delete': $editable = $editable && $logged_in_user->isAdmin(); - $value = false; + $value = 'false'; break; default: $value = $user->getConf($key); @@ -128,4 +161,4 @@ class DB { return $db->setPluginConf($plugin, $key, $value); } } -}
\ No newline at end of file +} diff --git a/src/models/Auth.class.php b/src/models/Auth.class.php index b51aef9..031ee26 100644 --- a/src/models/Auth.class.php +++ b/src/models/Auth.class.php @@ -113,7 +113,6 @@ class Auth { // [user|group]name //////////////////////////////////////////////////// public function getName() { - if (!$this->canRead()) return false; return $this->db->getUsername($this->uid); } public function setName($new_name) { diff --git a/src/views/pages/users/index.html.php b/src/views/pages/users/index.html.php index 2650c5a..159ff76 100644 --- a/src/views/pages/users/index.html.php +++ b/src/views/pages/users/index.html.php @@ -2,6 +2,7 @@ $t = $VARS['template']; $attribs = $VARS['attribs']; $users = $VARS['users']; +require_once('Login.class.php'); $t->header('Users'); @@ -10,27 +11,34 @@ $t->paragraph($t->link($t->url('users.csv'), "Download this as a spreadsheet.", $t->openTag('form', array('action'=>$t->url('users/index'), 'method'=>'post')); -$t->tag('input', array('type'=>'submit', - 'value'=>'Save/Update')); +if (Login::isLoggedIn()) { + $t->tag('input', array('type'=>'submit', + 'value'=>'Save/Update')); +} $t->openTag('table', array('class'=>'sortable', 'id'=>'bar')); -$t->openTag('thead'); -$t->openTag('tr'); -foreach ($attribs as $attrib) { - $t->tag('th', array(), $attrib['name']); +function table_head($attribs, $t) { + $t->openTag('tr'); + foreach ($attribs as $attrib) { + switch ($attrib['type']) { + case 'bool': $class = 'small'; break; + default: $class = ''; break; + } + $t->tag('th', array('class'=>$class), $attrib['name']); + } + if (Login::isLoggedIn()) { + $t->tag('th', array(), '-'); + } + $t->closeTag('tr'); } -$t->tag('th', array(), '-'); -$t->closeTag('tr'); + +$t->openTag('thead'); +table_head($attribs, $t); $t->closeTag('thead'); $t->openTag('tfoot'); -$t->openTag('tr'); -foreach ($attribs as $attrib) { - $t->tag('th', array(), $attrib['name']); -} -$t->tag('th', array(), '-'); -$t->closeTag('tr'); +table_head($attribs, $t); $t->closeTag('tfoot'); $t->openTag('tbody'); @@ -42,11 +50,15 @@ foreach ($users as $user) { $t->openTag('td'); $props = $user[$attrib['key']]; - - $value = $props['value']; + + $bool = $attrib['type']=='bool'; + if ($bool) { + $value = $props['value']=='true'; + } else { + $value = $props['value']; + } $editable = $props['editable']; $post_key = $props['post_key']; - $bool = is_bool($value); $arr = array('name'=>$post_key); if (!$editable) { @@ -73,18 +85,20 @@ foreach ($users as $user) { $t->closeTag('td'); } - $t->openTag('td'); - $t->link($t->url('users/'.$user['auth_name']['value']), 'More'); - $t->closeTag('td'); - + if (Login::isLoggedIn()) { + $t->openTag('td'); + $t->link($t->url('users/'.$user['auth_name']['value']), 'More'); + $t->closeTag('td'); + } $t->closeTag('tr'); } $t->closeTag('tbody'); $t->closeTag('table'); -$t->tag('input', array('type'=>'submit', - 'value'=>'Save/Update')); -$t->closeTag('form'); +if (Login::isLoggedIn()) { + $t->tag('input', array('type'=>'submit', + 'value'=>'Save/Update')); +} $t->footer(); diff --git a/src/views/pages/users/new.html.php b/src/views/pages/users/new.html.php index 8b6bdf8..9df376f 100644 --- a/src/views/pages/users/new.html.php +++ b/src/views/pages/users/new.html.php @@ -7,6 +7,16 @@ $t->openTag('form', array('method'=>'post', 'action'=>$t->url('users'))); $t->openFieldset("New User: Step 1"); + +if ($VARS['userlist']) { + $t->inputP("If you may have already created a username, please, ". + "<em>please</em> check the ". + $t->link($t->url('users/'), 'user-list', true). + " to find your old username, instead of creating a new ". + "user. If you don't like the name, you can log in and ". + "change it."); +} + if (in_array('illegal name', $VARS['errors'])) { $t->inputP("That is a forbidden username.", true); } |