浏览代码

added user get

tags/0.1.0
Robin Thoni 9 年前
父节点
当前提交
9a7c95259a

+ 2
- 0
src/Auth/Business/LuticateBusiness.php 查看文件

@@ -112,6 +112,8 @@ class LuticateBusiness
112 112
 
113 113
         $route->post("$prefix/users/login", "${ns}LuticateUsersBusiness", "login");
114 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 117
         $route->post("$prefix/users/add", "${ns}LuticateUsersBusiness", "add",
116 118
             array(LuticatePermissions::USER_ADD, LuticatePermissions::USER_GET));
117 119
         $route->post("$prefix/users/$user_id/del", "${ns}LuticateUsersBusiness", "del",

+ 12
- 1
src/Auth/Business/LuticateUsersBusiness.php 查看文件

@@ -4,6 +4,7 @@ namespace Luticate\Auth\Business;
4 4
 
5 5
 use Illuminate\Support\Facades\DB;
6 6
 use Luticate\Auth\DBO\LuticatePermissions;
7
+use Luticate\Auth\DBO\LuticateUsersLightDbo;
7 8
 use Luticate\Auth\DBO\LuticateUsersLoginDbo;
8 9
 use Luticate\Utils\LuBusiness;
9 10
 use Luticate\Auth\DataAccess\LuticateUsersDataAccess;
@@ -99,6 +100,16 @@ class LuticateUsersBusiness extends LuBusiness {
99 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 113
     public static function add($username, $email, $password)
103 114
     {
104 115
         $hash = self::hashPassword($password);
@@ -124,7 +135,7 @@ class LuticateUsersBusiness extends LuBusiness {
124 135
         $user_id = LuticateUsersDataAccess::addId($user);
125 136
 
126 137
         if (!is_null(LuticateGroupsBusiness::getById(0))) {
127
-            LuticateGroupsBusiness::addUserToGroup($user_id, 0);
138
+            LuticateGroupsBusiness::addUser($user_id, 0);
128 139
         }
129 140
         DB::commit();
130 141
 

+ 31
- 0
src/Auth/DBO/LuticateUsersLightDbo.php 查看文件

@@ -0,0 +1,31 @@
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
+}

正在加载...
取消
保存