mirror of
https://github.com/Ekokumppanit/ystavakylaecard.git
synced 2026-03-19 22:00:29 +00:00
Admins can now add other users
This commit is contained in:
@@ -142,6 +142,14 @@ class Yllapito extends CI_Controller
|
|||||||
$page_title = array();
|
$page_title = array();
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
|
case 'add':
|
||||||
|
$page_title = array('Lisää uusi käyttäjä', 'Käyttäjät');
|
||||||
|
break;
|
||||||
|
case 'create':
|
||||||
|
$new_id = $this->users->add($this->input->post());
|
||||||
|
$redir = (! $new_id) ? '' : 'show/'.$new_id;
|
||||||
|
redirect('yllapito/users/'.$redir);
|
||||||
|
break;
|
||||||
case 'delete':
|
case 'delete':
|
||||||
$this->user->delete($user_id);
|
$this->user->delete($user_id);
|
||||||
redirect('yllapito/users');
|
redirect('yllapito/users');
|
||||||
|
|||||||
@@ -12,6 +12,22 @@ class User_model extends MY_Model
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function add($data)
|
||||||
|
{
|
||||||
|
if (empty($data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset(
|
||||||
|
$data['password_again'],
|
||||||
|
$data['savedata'],
|
||||||
|
$data['submit']
|
||||||
|
);
|
||||||
|
$data['password'] = $this->passwordhash($data['password']);
|
||||||
|
|
||||||
|
return $this->insert($data);
|
||||||
|
}
|
||||||
|
|
||||||
public function save($uid = null, $data = null)
|
public function save($uid = null, $data = null)
|
||||||
{
|
{
|
||||||
if (empty($uid) || empty($data)) {
|
if (empty($uid) || empty($data)) {
|
||||||
|
|||||||
118
application/views/yllapito/users_add.php
Normal file
118
application/views/yllapito/users_add.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
if (empty($userdata)) {
|
||||||
|
$userdata = array();
|
||||||
|
}
|
||||||
|
if (empty($user)) {
|
||||||
|
$user = new stdClass();
|
||||||
|
}
|
||||||
|
if (empty($userid)) {
|
||||||
|
$userid = 0;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="large-12 small-12 columns">
|
||||||
|
<div class="panel">
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($user->can_modusers == "no") {
|
||||||
|
?>
|
||||||
|
<div data-alert class="alert-box error">
|
||||||
|
Sinulla ei ole oikeutta käyttäjien lisäämiseen.
|
||||||
|
</div>
|
||||||
|
<?php echo lnk("yllapito/users", "Takaisin"); ?>
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$post_url = site_url("yllapito/users/create");
|
||||||
|
$options = array('no' => 'Ei voi', 'yes' => 'Kyllä voi');
|
||||||
|
$dd = ' class="medium large-6 small-12"';
|
||||||
|
|
||||||
|
$inputs = array(
|
||||||
|
'name' => 'name',
|
||||||
|
'id' => 'name',
|
||||||
|
'value' => '',
|
||||||
|
'required' => null
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
<h2>Lisää uusi käyttäjä</h2>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<form action="<?php echo $post_url; ?>" method="post"
|
||||||
|
accept-charset="utf-8" id="user_add" class="custom">
|
||||||
|
<div class="large-4 small-12 columns">
|
||||||
|
<h3>Tiedot</h3>
|
||||||
|
<?php
|
||||||
|
echo form_label('Käyttäjätunnus (email)', 'username') . "\n";
|
||||||
|
$inputs['type'] = 'email';
|
||||||
|
$inputs['name'] = 'username';
|
||||||
|
$inputs['id'] = 'username';
|
||||||
|
echo form_input($inputs) . "\n";
|
||||||
|
|
||||||
|
unset($inputs['type']);
|
||||||
|
|
||||||
|
echo form_label('Etunimi', 'firstname') . "\n";
|
||||||
|
$inputs['name'] = 'firstname';
|
||||||
|
$inputs['id'] = 'firstname';
|
||||||
|
echo form_input($inputs) . "\n";
|
||||||
|
|
||||||
|
echo form_label('Sukunimi', 'lastname') . "\n";
|
||||||
|
$inputs['name'] = 'lastname';
|
||||||
|
$inputs['id'] = 'lastname';
|
||||||
|
echo form_input($inputs) . "\n";
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="large-4 small-12 columns">
|
||||||
|
<h3>Oikeudet</h3>
|
||||||
|
<?php
|
||||||
|
echo form_label('Voi hallita kortteja', 'can_approve') . "\n";
|
||||||
|
echo form_dropdown('can_approve', $options, null, $dd);
|
||||||
|
|
||||||
|
echo form_label('Voi nähdä käyttäjät', 'can_seeusers') . "\n";
|
||||||
|
echo form_dropdown('can_seeusers', $options, null, $dd);
|
||||||
|
|
||||||
|
echo form_label('Voi muokata käyttäjiä', 'can_modusers') . "\n";
|
||||||
|
echo form_dropdown('can_modusers', $options, null, $dd);
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="large-4 small-12 columns">
|
||||||
|
<h3>Salasana</h3>
|
||||||
|
<?php
|
||||||
|
$password = array(
|
||||||
|
'id' => 'password',
|
||||||
|
'name' => 'password',
|
||||||
|
'minlength' => "2",
|
||||||
|
'value' => '',
|
||||||
|
'required' => null
|
||||||
|
);
|
||||||
|
echo form_label('Salasana', 'password') . "\n";
|
||||||
|
echo form_password($password) . "\n";
|
||||||
|
|
||||||
|
$password['id'] = 'password_again';
|
||||||
|
$password['name'] = 'password_again';
|
||||||
|
echo form_label('Salasana uudelleen', 'password_again') . "\n";
|
||||||
|
echo form_password($password) . "\n";
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="large-12 small-12 columns">
|
||||||
|
<?php
|
||||||
|
echo form_submit(
|
||||||
|
array(
|
||||||
|
'name' => 'savedata',
|
||||||
|
'value' => 'Tallenna tiedot',
|
||||||
|
'class' => 'button small large-12 small-12'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -11,12 +11,18 @@ if (empty($user)) {
|
|||||||
$user = new stdClass();
|
$user = new stdClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user->can_seeusers == 'no') { ?>
|
if ($user->can_seeusers == 'no' && isset($user->can_seeusers)) { ?>
|
||||||
<div data-alert class="alert-box error">
|
<div data-alert class="alert-box error">
|
||||||
Sinulla ei ole oikeutta käyttäjien listaamiseen.
|
Sinulla ei ole oikeutta käyttäjien listaamiseen.
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
} else { ?>
|
} else {
|
||||||
|
if ($user->can_modusers == 'yes') {
|
||||||
|
echo lnk("yllapito/users/add", "Lisää uusi käyttäjä");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@@ -25,6 +25,19 @@ jQuery(document).ready(function($) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#user_add').validate({
|
||||||
|
rules: {
|
||||||
|
username: "email",
|
||||||
|
password: "required",
|
||||||
|
password_again: {
|
||||||
|
equalTo: "#password"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
submitHandler: function(form) {
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Provide zebra striping to our table
|
// Provide zebra striping to our table
|
||||||
$('table tbody tr:odd').addClass("zebra");
|
$('table tbody tr:odd').addClass("zebra");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user