diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/controllers/User.php | 12 | ||||
-rw-r--r-- | application/service/user.php | 11 | ||||
-rw-r--r-- | application/test/tests/test_service_user.php | 61 | ||||
-rw-r--r-- | application/views/user/invite.php | 6 |
4 files changed, 90 insertions, 0 deletions
diff --git a/application/controllers/User.php b/application/controllers/User.php index a2ce5c823..26704f3e5 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -133,6 +133,18 @@ class User extends MY_Controller { redirect("user/invite"); } + function delete_invitation_key() + { + $this->duser->require_implemented("can_register_new_users"); + $this->muser->require_access(); + + $userid = $this->muser->get_userid(); + $key = $this->input->post("key"); + + \service\user::delete_invitation_key($userid, $key); + redirect("user/invite"); + } + function invite() { $this->duser->require_implemented("can_register_new_users"); diff --git a/application/service/user.php b/application/service/user.php index bb0c44599..f7dfa5799 100644 --- a/application/service/user.php +++ b/application/service/user.php @@ -103,4 +103,15 @@ class user { return $key; } + + static public function delete_invitation_key($userid, $key) { + $CI =& get_instance(); + + $CI->db + ->where('key', $key) + ->where('user', $userid) + ->delete('actions'); + + return $CI->db->affected_rows(); + } } diff --git a/application/test/tests/test_service_user.php b/application/test/tests/test_service_user.php new file mode 100644 index 000000000..4cbbdfac0 --- /dev/null +++ b/application/test/tests/test_service_user.php @@ -0,0 +1,61 @@ +<?php +/* + * Copyright 2018 Florian "Bluewind" Pritz <bluewind@server-speed.net> + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ + +namespace test\tests; + +class test_service_user extends \test\Test { + + public function __construct() { + parent::__construct(); + } + + public function init() { + } + + public function cleanup() { + } + + public function test_invitation_key_delete() { + $CI =& get_instance(); + + $userid = 1; + + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([], $result, "database contains no actions"); + + $key = \service\user::create_invitation_key($userid); + + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key"); + + \service\user::delete_invitation_key($userid+1, $key); + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key after incorrect deletion"); + + \service\user::delete_invitation_key($userid+1, "foobar-"); + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key after incorrect deletion"); + + \service\user::delete_invitation_key($userid+1, ""); + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key after incorrect deletion"); + + \service\user::delete_invitation_key($userid, ""); + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key"); + + \service\user::delete_invitation_key($userid, $key); + + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([], $result, "key has been deleted"); + + } + +} + diff --git a/application/views/user/invite.php b/application/views/user/invite.php index d3e2fb7a6..042ba0b61 100644 --- a/application/views/user/invite.php +++ b/application/views/user/invite.php @@ -26,6 +26,12 @@ <td><?php echo $i++; ?></td> <td><?php echo anchor("user/register/".$item["key"], $item["key"]) ?></td> <td><?php echo date("Y/m/d H:i", $item["date"]) ?></td> + <td> + <?php echo form_open('user/delete_invitation_key'); ?> + <input class="btn btn-danger btn-xs" type="submit" value="Delete" name="delete" /> + <input type="hidden" name="key" value="<?php echo $item["key"]; ?>" /> + </form> + </td> </tr> <?php endforeach; ?> </tbody> |