diff --git a/application/controllers/yllapito.php b/application/controllers/yllapito.php index 9fa8c97..f16691a 100644 --- a/application/controllers/yllapito.php +++ b/application/controllers/yllapito.php @@ -142,6 +142,14 @@ class Yllapito extends CI_Controller $page_title = array(); 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': $this->user->delete($user_id); redirect('yllapito/users'); diff --git a/application/models/user_model.php b/application/models/user_model.php index 038a604..a9649e5 100644 --- a/application/models/user_model.php +++ b/application/models/user_model.php @@ -12,6 +12,22 @@ class User_model extends MY_Model 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) { if (empty($uid) || empty($data)) { diff --git a/application/views/yllapito/users_add.php b/application/views/yllapito/users_add.php new file mode 100644 index 0000000..1c8ea4b --- /dev/null +++ b/application/views/yllapito/users_add.php @@ -0,0 +1,118 @@ + + +
+
+
+ +can_modusers == "no") { + ?> +
+ Sinulla ei ole oikeutta käyttäjien lisäämiseen. +
+ + 'Ei voi', 'yes' => 'Kyllä voi'); + $dd = ' class="medium large-6 small-12"'; + + $inputs = array( + 'name' => 'name', + 'id' => 'name', + 'value' => '', + 'required' => null + ); + ?> +

Lisää uusi käyttäjä

+ +
+
+
+

Tiedot

+ +
+
+

Oikeudet

+ +
+
+

Salasana

+ '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"; + + ?> +
+
+ 'savedata', + 'value' => 'Tallenna tiedot', + 'class' => 'button small large-12 small-12' + ) + ); + + ?> +
+
+
+ + +
+
+
\ No newline at end of file diff --git a/application/views/yllapito/users_listall.php b/application/views/yllapito/users_listall.php index fd849bd..9f304fb 100644 --- a/application/views/yllapito/users_listall.php +++ b/application/views/yllapito/users_listall.php @@ -11,12 +11,18 @@ if (empty($user)) { $user = new stdClass(); } -if ($user->can_seeusers == 'no') { ?> +if ($user->can_seeusers == 'no' && isset($user->can_seeusers)) { ?>
Sinulla ei ole oikeutta käyttäjien listaamiseen.
+} else { + if ($user->can_modusers == 'yes') { + echo lnk("yllapito/users/add", "Lisää uusi käyttäjä"); + } + ?> + + diff --git a/assets/js/scripts.js b/assets/js/scripts.js index 95a3175..8bc57d3 100644 --- a/assets/js/scripts.js +++ b/assets/js/scripts.js @@ -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 $('table tbody tr:odd').addClass("zebra");