summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-05-18 23:02:59 +0200
committerFlorian Pritz <bluewind@xinu.at>2018-05-18 23:02:59 +0200
commit9f8486c87cd81cdb888b8e518f0d3eb50b6abbb9 (patch)
treed12253783735e71a45c3055c463e40ca9a768251 /application
parentdd9351c023f57c011cf72bb113c9003ae5aeb2c5 (diff)
Extract invitation key creation to \service\user
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r--application/controllers/User.php20
-rw-r--r--application/service/user.php26
2 files changed, 27 insertions, 19 deletions
diff --git a/application/controllers/User.php b/application/controllers/User.php
index 892bbe1b6..a2ce5c823 100644
--- a/application/controllers/User.php
+++ b/application/controllers/User.php
@@ -128,25 +128,7 @@ class User extends MY_Controller {
$userid = $this->muser->get_userid();
- $invitations = $this->db->select('user')
- ->from('actions')
- ->where('user', $userid)
- ->where('action', 'invitation')
- ->count_all_results();
-
- if ($invitations + 1 > $this->config->item('max_invitation_keys')) {
- throw new \exceptions\PublicApiException("user/invitation-limit", "You can't create more invitation keys at this time.");
- }
-
- $key = random_alphanum(12, 16);
-
- $this->db->set(array(
- 'key' => $key,
- 'user' => $userid,
- 'date' => time(),
- 'action' => 'invitation'
- ))
- ->insert('actions');
+ \service\user::create_invitation_key($userid);
redirect("user/invite");
}
diff --git a/application/service/user.php b/application/service/user.php
index 1d922a102..bb0c44599 100644
--- a/application/service/user.php
+++ b/application/service/user.php
@@ -77,4 +77,30 @@ class user {
"apikeys" => $ret,
);
}
+
+ static public function create_invitation_key($userid) {
+ $CI =& get_instance();
+
+ $invitations = $CI->db->select('user')
+ ->from('actions')
+ ->where('user', $userid)
+ ->where('action', 'invitation')
+ ->count_all_results();
+
+ if ($invitations + 1 > $CI->config->item('max_invitation_keys')) {
+ throw new \exceptions\PublicApiException("user/invitation-limit", "You can't create more invitation keys at this time.");
+ }
+
+ $key = random_alphanum(12, 16);
+
+ $CI->db->set(array(
+ 'key' => $key,
+ 'user' => $userid,
+ 'date' => time(),
+ 'action' => 'invitation'
+ ))
+ ->insert('actions');
+
+ return $key;
+ }
}