Added Add Admin
This commit is contained in:
parent
80c8971a46
commit
43bd45d43e
5
application/classes/Controller/Admin.php
Normal file
5
application/classes/Controller/Admin.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php defined('SYSPATH') or die('No direct script access.');
|
||||||
|
|
||||||
|
class Controller_Admin extends Controller_TemplateDefault {
|
||||||
|
protected $auth_required = TRUE;
|
||||||
|
}
|
61
application/classes/Controller/User/Admin.php
Normal file
61
application/classes/Controller/User/Admin.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides User with a TSM node functions
|
||||||
|
*
|
||||||
|
* @package TSM Access Management
|
||||||
|
* @category Controllers/User
|
||||||
|
* @author Deon George
|
||||||
|
* @copyright (c) 2009-2013 Deon George
|
||||||
|
* @license http://dev.leenooks.net/license.html
|
||||||
|
*/
|
||||||
|
class Controller_User_Admin extends Controller_Admin {
|
||||||
|
protected $secure_actions = array(
|
||||||
|
'add'=>0,
|
||||||
|
'view'=>0,
|
||||||
|
);
|
||||||
|
|
||||||
|
private function admin_name($i) {
|
||||||
|
return sprintf('%s%02dA',$this->ao->id(),$i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function action_add() {
|
||||||
|
$n = ORM::factory('ADMIN')->where('EMAIL_ADDRESS','=',$this->ao->email)->find_all();
|
||||||
|
|
||||||
|
if ($n->count() >= $this->ao->max_admin) {
|
||||||
|
SystemMessage::add(array(
|
||||||
|
'title'=>_('Maximum admins created'),
|
||||||
|
'type'=>'info',
|
||||||
|
'body'=>_('Additional admins cannot be created for your account, you have already reached your maximum. If you really need more, please contact us.'),
|
||||||
|
));
|
||||||
|
|
||||||
|
HTTP::redirect(URL::link('user','welcome'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->request->post()) {
|
||||||
|
// Find a free name.
|
||||||
|
for ($i=1;$i<$n->count();$i++)
|
||||||
|
if (! Object::in_array('ADMIN_NAME',$this->admin_name($i),$n->as_array()))
|
||||||
|
break;
|
||||||
|
|
||||||
|
$ao = ORM::factory('ADMIN');
|
||||||
|
$ao->ADMIN_NAME=$this->admin_name($i);
|
||||||
|
$ao->CONTACT=$this->ao->name();
|
||||||
|
$ao->EMAILADDRESS=$this->ao->email;
|
||||||
|
$ao->values($x=Arr::merge(Kohana::$config->load('tsm')->admin_create,$this->request->post()));
|
||||||
|
|
||||||
|
$this->save($ao);
|
||||||
|
|
||||||
|
if ($ao->saved())
|
||||||
|
#HTTP::redirect(URL::link('user','admin/view/'.$ao->ADMIN_NAME));
|
||||||
|
HTTP::redirect(URL::link('user','welcome'));
|
||||||
|
}
|
||||||
|
|
||||||
|
Block::factory()
|
||||||
|
->type('form-horizontal')
|
||||||
|
->title('Register ADMIN')
|
||||||
|
->title_icon('fa-graduation-cap')
|
||||||
|
->body(View::factory('admin/user/add')->set('o',$this->ao));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -20,19 +20,19 @@ class Controller_User_Node extends Controller_Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function action_add() {
|
public function action_add() {
|
||||||
|
$n = ORM::factory('NODE')->where('EMAIL_ADDRESS','=',$this->ao->email)->find_all();
|
||||||
|
|
||||||
|
if ($n->count() >= $this->ao->max_nodes) {
|
||||||
|
SystemMessage::add(array(
|
||||||
|
'title'=>_('Maximum nodes created'),
|
||||||
|
'type'=>'info',
|
||||||
|
'body'=>_('Additional nodes cannot be created for your account, you have already reached your maximum. If you really need more, please contact us.'),
|
||||||
|
));
|
||||||
|
|
||||||
|
HTTP::redirect(URL::link('user','welcome'));
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->request->post()) {
|
if ($this->request->post()) {
|
||||||
$n = ORM::factory('NODE')->where('EMAIL_ADDRESS','=',$this->ao->email)->find_all();
|
|
||||||
|
|
||||||
if (FALSE AND $n->count() > $this->ao->max_nodes) {
|
|
||||||
SystemMessage::add(array(
|
|
||||||
'title'=>_('Maximum nodes created'),
|
|
||||||
'type'=>'info',
|
|
||||||
'body'=>_('Additional nodes cannot be created for your account, you have already reached your maximum. If you really need more, please contact us.'),
|
|
||||||
));
|
|
||||||
|
|
||||||
HTTP::redirect(URL::link('user','welcome'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find a free name.
|
// Find a free name.
|
||||||
for ($i=1;$i<$n->count();$i++)
|
for ($i=1;$i<$n->count();$i++)
|
||||||
if (! Object::in_array('NODE_NAME',$this->node_name($i),$n->as_array()))
|
if (! Object::in_array('NODE_NAME',$this->node_name($i),$n->as_array()))
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
return array
|
return array
|
||||||
(
|
(
|
||||||
|
'admin_create' => array(
|
||||||
|
'FORCEPWRESET'=>'YES',
|
||||||
|
'PASSEXP'=>90,
|
||||||
|
'PASSWORD'=>'ch@ng3Me!',
|
||||||
|
'SSL'=>'YES',
|
||||||
|
),
|
||||||
'node_create' => array(
|
'node_create' => array(
|
||||||
'PASSEXP'=>90,
|
'PASSEXP'=>90,
|
||||||
'PASSWORD'=>'ch@ng3Me!',
|
'PASSWORD'=>'ch@ng3Me!',
|
||||||
|
13
application/views/admin/user/add.php
Normal file
13
application/views/admin/user/add.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<fieldset>
|
||||||
|
<legend>Register a TSM admin</legend>
|
||||||
|
|
||||||
|
<p>Please give us a description for this admin.<p>
|
||||||
|
<?php echo Form::input('description','',array('divclass'=>'col-md-6','label'=>'Description','placeholder'=>'Description for Admin')); ?>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-offset-1">
|
||||||
|
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||||
|
<button type="button" class="btn btn-default">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -24,6 +24,10 @@ abstract class lnApp_Database_Query_Builder_Insert extends Kohana_Database_Query
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch ($this->_table) {
|
switch ($this->_table) {
|
||||||
|
case 'ADMINS':
|
||||||
|
$query = sprintf('REGISTER ADMIN %s %s %s',$this->pop_value('ADMIN_NAME'),$this->pop_value('PASSWORD'),$this->insert_values());
|
||||||
|
|
||||||
|
break;
|
||||||
case 'NODES':
|
case 'NODES':
|
||||||
$query = sprintf('REGISTER NODE %s %s %s',$this->pop_value('NODE_NAME'),$this->pop_value('PASSWORD'),$this->insert_values());
|
$query = sprintf('REGISTER NODE %s %s %s',$this->pop_value('NODE_NAME'),$this->pop_value('PASSWORD'),$this->insert_values());
|
||||||
|
|
||||||
|
@ -25,6 +25,13 @@ abstract class lnApp_Model_ADMIN extends ORM_TSM {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
protected $_custom_cols = array(
|
||||||
|
'EMAILADDRESS',
|
||||||
|
'FORCEPWRESET',
|
||||||
|
'PASSWORD',
|
||||||
|
'SSL',
|
||||||
|
);
|
||||||
|
|
||||||
public function name() {
|
public function name() {
|
||||||
return $this->ADMIN_NAME;
|
return $this->ADMIN_NAME;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user