Browse Source

added user get

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
9a7c95259a

+ 2
- 0
src/Auth/Business/LuticateBusiness.php View File

112
 
112
 
113
         $route->post("$prefix/users/login", "${ns}LuticateUsersBusiness", "login");
113
         $route->post("$prefix/users/login", "${ns}LuticateUsersBusiness", "login");
114
         $route->post("$prefix/users/logout", "${ns}LuticateUsersBusiness", "logout");
114
         $route->post("$prefix/users/logout", "${ns}LuticateUsersBusiness", "logout");
115
+        $route->post("$prefix/users/$id", "${ns}LuticateUsersBusiness", "getById", LuticatePermissions::USER_GET);
116
+        $route->post("$prefix/users", "${ns}LuticateUsersBusiness", "getAll", LuticatePermissions::USER_GET);
115
         $route->post("$prefix/users/add", "${ns}LuticateUsersBusiness", "add",
117
         $route->post("$prefix/users/add", "${ns}LuticateUsersBusiness", "add",
116
             array(LuticatePermissions::USER_ADD, LuticatePermissions::USER_GET));
118
             array(LuticatePermissions::USER_ADD, LuticatePermissions::USER_GET));
117
         $route->post("$prefix/users/$user_id/del", "${ns}LuticateUsersBusiness", "del",
119
         $route->post("$prefix/users/$user_id/del", "${ns}LuticateUsersBusiness", "del",

+ 12
- 1
src/Auth/Business/LuticateUsersBusiness.php View File

4
 
4
 
5
 use Illuminate\Support\Facades\DB;
5
 use Illuminate\Support\Facades\DB;
6
 use Luticate\Auth\DBO\LuticatePermissions;
6
 use Luticate\Auth\DBO\LuticatePermissions;
7
+use Luticate\Auth\DBO\LuticateUsersLightDbo;
7
 use Luticate\Auth\DBO\LuticateUsersLoginDbo;
8
 use Luticate\Auth\DBO\LuticateUsersLoginDbo;
8
 use Luticate\Utils\LuBusiness;
9
 use Luticate\Utils\LuBusiness;
9
 use Luticate\Auth\DataAccess\LuticateUsersDataAccess;
10
 use Luticate\Auth\DataAccess\LuticateUsersDataAccess;
99
         return true;
100
         return true;
100
     }
101
     }
101
 
102
 
103
+    public static function getAll($page = 0, $perPage = PHP_INT_MAX)
104
+    {
105
+        $users = self::search($page, $perPage, "username", "ASC");
106
+        $usersLight = array();
107
+        foreach ($users as $user) {
108
+            $usersLight[] = LuticateUsersLightDbo::fromUserDbo($user);
109
+        }
110
+        return $usersLight;
111
+    }
112
+
102
     public static function add($username, $email, $password)
113
     public static function add($username, $email, $password)
103
     {
114
     {
104
         $hash = self::hashPassword($password);
115
         $hash = self::hashPassword($password);
124
         $user_id = LuticateUsersDataAccess::addId($user);
135
         $user_id = LuticateUsersDataAccess::addId($user);
125
 
136
 
126
         if (!is_null(LuticateGroupsBusiness::getById(0))) {
137
         if (!is_null(LuticateGroupsBusiness::getById(0))) {
127
-            LuticateGroupsBusiness::addUserToGroup($user_id, 0);
138
+            LuticateGroupsBusiness::addUser($user_id, 0);
128
         }
139
         }
129
         DB::commit();
140
         DB::commit();
130
 
141
 

+ 31
- 0
src/Auth/DBO/LuticateUsersLightDbo.php View File

1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 10/9/15
6
+ * Time: 2:35 PM
7
+ */
8
+
9
+namespace Luticate\Auth\DBO;
10
+
11
+
12
+class LuticateUsersLightDbo extends LuticateUsersDbo
13
+{
14
+    /**
15
+     * @param $user LuticateUsersDbo
16
+     * @return LuticateUsersLoginDbo|null
17
+     */
18
+    public static function fromUserDbo($user)
19
+    {
20
+        return $user->castAs('Luticate\Auth\DBO\LuticateUsersLoginDbo');
21
+    }
22
+
23
+    public function jsonSerialize()
24
+    {
25
+        $array = parent::jsonSerialize();
26
+        unset($array["Password"]);
27
+        unset($array["Salt"]);
28
+        return $array;
29
+    }
30
+
31
+}

Loading…
Cancel
Save