Browse Source

get permission value SPs; tests

develop
Robin Thoni 8 years ago
parent
commit
e8987c5c4e
80 changed files with 286 additions and 4908 deletions
  1. 1
    0
      .gitignore
  2. 0
    3
      TODO
  3. 2
    6
      composer.json
  4. 14
    0
      config.example.json
  5. 0
    57
      generate.php
  6. 28
    0
      phpunit.xml
  7. 0
    52
      sql/data_0_1_2.sql
  8. 0
    159
      sql/data_init.sql
  9. 0
    85
      sql/struct_0_1_2.sql
  10. 0
    240
      sql/struct_init.sql
  11. 0
    173
      src/Auth/Business/LuticateBusiness.php
  12. 0
    84
      src/Auth/Business/LuticateGroupsBusiness.php
  13. 0
    70
      src/Auth/Business/LuticateMiddleware.php
  14. 0
    93
      src/Auth/Business/LuticatePermissionsBusiness.php
  15. 0
    74
      src/Auth/Business/LuticatePermissionsGroupsBusiness.php
  16. 0
    68
      src/Auth/Business/LuticatePermissionsUsersBusiness.php
  17. 0
    170
      src/Auth/Business/LuticateSettingsBusiness.php
  18. 0
    73
      src/Auth/Business/LuticateSettingsUsersBusiness.php
  19. 0
    192
      src/Auth/Business/LuticateUsersBusiness.php
  20. 0
    102
      src/Auth/Controller/LuticateGroupsController.php
  21. 0
    111
      src/Auth/Controller/LuticatePermissionsController.php
  22. 0
    72
      src/Auth/Controller/LuticatePermissionsGroupsController.php
  23. 0
    72
      src/Auth/Controller/LuticatePermissionsUsersController.php
  24. 0
    110
      src/Auth/Controller/LuticateSettingsController.php
  25. 0
    69
      src/Auth/Controller/LuticateSettingsUsersController.php
  26. 0
    140
      src/Auth/Controller/LuticateUsersController.php
  27. 0
    67
      src/Auth/DBO/LuticateGroupsDbo.php
  28. 0
    50
      src/Auth/DBO/LuticateGroupsDboArray.php
  29. 0
    51
      src/Auth/DBO/LuticatePermissions.php
  30. 0
    67
      src/Auth/DBO/LuticatePermissionsDbo.php
  31. 0
    50
      src/Auth/DBO/LuticatePermissionsDboArray.php
  32. 0
    85
      src/Auth/DBO/LuticatePermissionsGroupsDbo.php
  33. 0
    50
      src/Auth/DBO/LuticatePermissionsGroupsDboArray.php
  34. 0
    85
      src/Auth/DBO/LuticatePermissionsUsersDbo.php
  35. 0
    50
      src/Auth/DBO/LuticatePermissionsUsersDboArray.php
  36. 0
    121
      src/Auth/DBO/LuticateSettingsDbo.php
  37. 0
    50
      src/Auth/DBO/LuticateSettingsDboArray.php
  38. 0
    103
      src/Auth/DBO/LuticateSettingsUsersDbo.php
  39. 0
    50
      src/Auth/DBO/LuticateSettingsUsersDboArray.php
  40. 0
    175
      src/Auth/DBO/LuticateUsersDbo.php
  41. 0
    50
      src/Auth/DBO/LuticateUsersDboArray.php
  42. 0
    32
      src/Auth/DBO/LuticateUsersLightDbo.php
  43. 0
    51
      src/Auth/DBO/LuticateUsersLoginDbo.php
  44. 10
    0
      src/Auth/DataAccess/LuPermissionsDataAccess.php
  45. 0
    78
      src/Auth/DataAccess/LuticateGroupsDataAccess.php
  46. 0
    67
      src/Auth/DataAccess/LuticatePermissionsDataAccess.php
  47. 0
    39
      src/Auth/DataAccess/LuticatePermissionsGroupsDataAccess.php
  48. 0
    39
      src/Auth/DataAccess/LuticatePermissionsUsersDataAccess.php
  49. 0
    77
      src/Auth/DataAccess/LuticateSettingsDataAccess.php
  50. 0
    57
      src/Auth/DataAccess/LuticateSettingsUsersDataAccess.php
  51. 0
    39
      src/Auth/DataAccess/LuticateUsersDataAccess.php
  52. 0
    18
      src/Auth/DataAccess/Models/LuticateGroups.php
  53. 0
    49
      src/Auth/DataAccess/Models/LuticateGroupsModel.php
  54. 0
    10
      src/Auth/DataAccess/Models/LuticatePermissions.php
  55. 0
    10
      src/Auth/DataAccess/Models/LuticatePermissionsGroups.php
  56. 0
    51
      src/Auth/DataAccess/Models/LuticatePermissionsGroupsModel.php
  57. 0
    49
      src/Auth/DataAccess/Models/LuticatePermissionsModel.php
  58. 0
    10
      src/Auth/DataAccess/Models/LuticatePermissionsUsers.php
  59. 0
    51
      src/Auth/DataAccess/Models/LuticatePermissionsUsersModel.php
  60. 0
    10
      src/Auth/DataAccess/Models/LuticateSettings.php
  61. 0
    55
      src/Auth/DataAccess/Models/LuticateSettingsModel.php
  62. 0
    10
      src/Auth/DataAccess/Models/LuticateSettingsUsers.php
  63. 0
    53
      src/Auth/DataAccess/Models/LuticateSettingsUsersModel.php
  64. 0
    18
      src/Auth/DataAccess/Models/LuticateUsers.php
  65. 0
    61
      src/Auth/DataAccess/Models/LuticateUsersModel.php
  66. 0
    120
      src/Auth/DataAccess/SP/SpLuGetAllUserPermission.php
  67. 0
    101
      src/Auth/DataAccess/SP/SpLuGetAllUserSettings.php
  68. 0
    81
      src/Auth/DataAccess/SP/SpLuGetUserPermission.php
  69. 0
    81
      src/Auth/DataAccess/SP/SpLuGetUserSetting.php
  70. 0
    2
      src/Auth/DataAccess/SP/src/sp_lu_get_all_user_permission.sql
  71. 0
    5
      src/Auth/DataAccess/SP/src/sp_lu_get_all_user_settings.sql
  72. 0
    22
      src/Auth/DataAccess/SP/src/sp_lu_get_user_permission.sql
  73. 0
    18
      src/Auth/DataAccess/SP/src/sp_lu_get_user_setting.sql
  74. 36
    0
      src/Auth/DataAccess/Sp/SpLuGetUserPermissionById.php
  75. 36
    0
      src/Auth/DataAccess/Sp/SpLuGetUserPermissionByName.php
  76. 77
    0
      src/Auth/Dbo/LuPermissionLite.php
  77. 0
    74
      test/TestPermission.php
  78. 0
    91
      test/test_permissions.sql
  79. 68
    0
      tests/LuPermissionTest.php
  80. 14
    0
      tests/bootstrap.php

+ 1
- 0
.gitignore View File

@@ -2,3 +2,4 @@
2 2
 /vendor
3 3
 /.env
4 4
 composer.lock
5
+/config.json

+ 0
- 3
TODO View File

@@ -1,3 +0,0 @@
1
-Get all users who are not in a group
2
-Get all groups for a user
3
-Check permission downgrade on permission update

+ 2
- 6
composer.json View File

@@ -9,18 +9,14 @@
9 9
     ],
10 10
     "repositories": [{
11 11
       "type": "vcs",
12
-      "url":  "/home/robin/projects/luticate/api/utils"
13
-    },{
14
-      "type": "vcs",
15
-      "url":  "https://git.rthoni.com/luticate/api-generator.git"
12
+      "url":  "https://git.rthoni.com/luticate/api-utils"
16 13
     }],
17 14
     "require": {
18 15
       "firebase/php-jwt": "~2.0",
19 16
       "luticate/utils": "dev-develop"
20 17
     },
21 18
     "require-dev": {
22
-      "vlucas/phpdotenv": "~1.0",
23
-      "luticate/generator": "0.1.x"
19
+      "phpunit/phpunit": "5.3.*"
24 20
     },
25 21
     "autoload": {
26 22
       "psr-4": {

+ 14
- 0
config.example.json View File

@@ -0,0 +1,14 @@
1
+{
2
+  "logs": "storage/logs/luticate.log",
3
+  "websocket": {
4
+    "address": "0.0.0.0",
5
+    "port": 8180
6
+  },
7
+  "databases": [
8
+    {
9
+      "name": "luticatedb", "driver": "pgsql",
10
+      "host": "localhost", "port": "5432", "database": "luticate",
11
+      "username": "luticate", "password": "password"
12
+    }
13
+  ]
14
+}

+ 0
- 57
generate.php View File

@@ -1,57 +0,0 @@
1
-<?php
2
-/**
3
- * Created by PhpStorm.
4
- * User: robin
5
- * Date: 9/26/15
6
- * Time: 4:03 PM
7
- */
8
-
9
-use Luticate\Generator\LuGenerator;
10
-
11
-require_once('vendor/autoload.php');
12
-
13
-Dotenv::load(".");
14
-
15
-$gen = new LuGenerator(getenv("DB_CONNECTION"), getenv("DB_DATABASE"), getenv("DB_HOST"),
16
-    getenv("DB_PORT"), getenv("DB_USERNAME"), getenv("DB_PASSWORD"));
17
-
18
-$gen->setConfig(array("dbo" =>
19
-    array(
20
-        "namespace" => 'Luticate\Auth\DBO',
21
-        "folder" => 'src/Auth/DBO'
22
-    ),
23
-    "models" =>
24
-        array(
25
-            "namespace" => 'Luticate\Auth\DataAccess\Models',
26
-            "folder" => 'src/Auth/DataAccess/Models'
27
-        ),
28
-    "sp" =>
29
-        array(
30
-            "namespace" => 'Luticate\Auth\DataAccess\SP',
31
-            "folder" => 'src/Auth/DataAccess/SP'
32
-        ),
33
-    "dataaccess" =>
34
-        array(
35
-            "namespace" => 'Luticate\Auth\DataAccess',
36
-            "folder" => 'src/Auth/DataAccess'
37
-        ),
38
-    "business" =>
39
-        array(
40
-            "namespace" => 'Luticate\Auth\Business',
41
-            "folder" => 'src/Auth/Business'
42
-        ),
43
-    "controller" =>
44
-        array(
45
-            "namespace" => 'Luticate\Auth\Controller',
46
-            "folder" => 'src/Auth/Controller'
47
-        ),
48
-    "mode" => 0775,
49
-    "ignore" => array(
50
-        "tables" => array(
51
-            "/luticate_users_groups/"
52
-        ),
53
-        "sp" => array(),
54
-        "controllers" => array()
55
-    )
56
-));
57
-$gen->run();

+ 28
- 0
phpunit.xml View File

@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<phpunit backupGlobals="false"
3
+         backupStaticAttributes="false"
4
+         bootstrap="tests/bootstrap.php"
5
+         colors="true"
6
+         convertErrorsToExceptions="true"
7
+         convertNoticesToExceptions="true"
8
+         convertWarningsToExceptions="true"
9
+         processIsolation="false"
10
+         stopOnFailure="false"
11
+         syntaxCheck="false">
12
+    <testsuites>
13
+        <testsuite name="Application Test Suite">
14
+            <directory>./tests/</directory>
15
+        </testsuite>
16
+    </testsuites>
17
+    <filter>
18
+        <whitelist>
19
+            <directory suffix=".php">app/</directory>
20
+        </whitelist>
21
+    </filter>
22
+    <php>
23
+        <env name="APP_ENV" value="testing"/>
24
+        <env name="CACHE_DRIVER" value="array"/>
25
+        <env name="SESSION_DRIVER" value="array"/>
26
+        <env name="QUEUE_DRIVER" value="sync"/>
27
+    </php>
28
+</phpunit>

+ 0
- 52
sql/data_0_1_2.sql View File

@@ -1,56 +0,0 @@
1
---
2
---
3
-
4
-INSERT INTO luticate_settings VALUES ('LU_SESSION_DAYS', 'int', '30', true, true);
5
-INSERT INTO luticate_settings VALUES ('LU_USERS_PER_PAGE', 'int', '15', false, false);
6
-INSERT INTO luticate_settings VALUES ('LU_GROUPS_PER_PAGE', 'int', '15', false, false);
7
-INSERT INTO luticate_settings VALUES ('LU_SETTINGS_PER_PAGE', 'int', '15', false, false);
8
-INSERT INTO luticate_settings VALUES ('LU_PERMISSIONS_PER_PAGE', 'int', '15', false, false);
9
-
10
---
11
---
12
-
13
-INSERT INTO luticate_permissions VALUES ('LU_SETTING_DEL', false);
14
-INSERT INTO luticate_permissions VALUES ('LU_SETTING_EDIT', false);
15
-INSERT INTO luticate_permissions VALUES ('LU_SETTING_EFFECTIVE_GET', false);
16
-INSERT INTO luticate_permissions VALUES ('LU_SETTING_GET', false);
17
-INSERT INTO luticate_permissions VALUES ('LU_SETTING_USER_EDIT', false);
18
-INSERT INTO luticate_permissions VALUES ('LU_SETTING_USER_GET', false);
19
-INSERT INTO luticate_permissions VALUES ('LU_SETTING_EDIT_ME', false);
20
-INSERT INTO luticate_permissions VALUES ('LU_SETTING_ADD', false);
21
-
22
---
23
---
24
-
25
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_ADD', false, 1);
26
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_DEL', false, 1);
27
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_EDIT', true, 1);
28
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_EFFECTIVE_GET', true, 1);
29
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_GET', true, 1);
30
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_USER_EDIT', true, 1);
31
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_USER_GET', true, 1);
32
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_ADD', true, 0);
33
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_DEL', true, 0);
34
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_EDIT', true, 0);
35
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_EFFECTIVE_GET', true, 0);
36
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_GET', true, 0);
37
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_USER_EDIT', true, 0);
38
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_USER_GET', true, 0);
39
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_EDIT_ME', true, 1);
40
-INSERT INTO luticate_permissions_groups VALUES ('LU_SETTING_EDIT_ME', true, 0);
41
-
42
---
43
---
44
-
45
-INSERT INTO luticate_permissions_users VALUES ('LU_SETTING_USER_GET', true, 0);
46
-INSERT INTO luticate_permissions_users VALUES ('LU_SETTING_ADD', false, 0);
47
-INSERT INTO luticate_permissions_users VALUES ('LU_SETTING_EDIT', false, 0);
48
-INSERT INTO luticate_permissions_users VALUES ('LU_SETTING_EFFECTIVE_GET', false, 0);
49
-INSERT INTO luticate_permissions_users VALUES ('LU_SETTING_DEL', false, 0);
50
-INSERT INTO luticate_permissions_users VALUES ('LU_SETTING_EDIT_ME', false, 0);
51
-INSERT INTO luticate_permissions_users VALUES ('LU_SETTING_GET', false, 0);
52
-INSERT INTO luticate_permissions_users VALUES ('LU_SETTING_USER_EDIT', false, 0);

+ 0
- 159
sql/data_init.sql View File

@@ -1,169 +0,0 @@
1
---
2
---
3
---
4
---
5
-
6
-INSERT INTO luticate_groups VALUES (0, 'Super Administrators');
7
-INSERT INTO luticate_groups VALUES (1, 'Administrators');
8
-
9
-
10
---
11
---
12
-
13
-SELECT pg_catalog.setval('luticate_groups_id_seq', 2, true);
14
-
15
-
16
---
17
---
18
-
19
-INSERT INTO luticate_permissions VALUES ('LU_USER_GET', false);
20
-INSERT INTO luticate_permissions VALUES ('LU_USER_SET_PASSWORD', false);
21
-INSERT INTO luticate_permissions VALUES ('LU_USER_LOGIN', true);
22
-INSERT INTO luticate_permissions VALUES ('LU_USER_EDIT_ME', true);
23
-INSERT INTO luticate_permissions VALUES ('LU_USER_SET_PASSWORD_ME', true);
24
-INSERT INTO luticate_permissions VALUES ('LU_GROUP_ADD', false);
25
-INSERT INTO luticate_permissions VALUES ('LU_GROUP_DEL', false);
26
-INSERT INTO luticate_permissions VALUES ('LU_GROUP_EDIT', false);
27
-INSERT INTO luticate_permissions VALUES ('LU_GROUP_USER_ADD', false);
28
-INSERT INTO luticate_permissions VALUES ('LU_GROUP_USER_DEL', false);
29
-INSERT INTO luticate_permissions VALUES ('LU_PERM_ADD', false);
30
-INSERT INTO luticate_permissions VALUES ('LU_PERM_DEL', false);
31
-INSERT INTO luticate_permissions VALUES ('LU_PERM_EDIT', false);
32
-INSERT INTO luticate_permissions VALUES ('LU_PERM_EFFECTIVE_GET', false);
33
-INSERT INTO luticate_permissions VALUES ('LU_PERM_GET', false);
34
-INSERT INTO luticate_permissions VALUES ('LU_PERM_GROUP_ADD', false);
35
-INSERT INTO luticate_permissions VALUES ('LU_PERM_GROUP_DEL', false);
36
-INSERT INTO luticate_permissions VALUES ('LU_PERM_GROUP_EDIT', false);
37
-INSERT INTO luticate_permissions VALUES ('LU_PERM_GROUP_GET', false);
38
-INSERT INTO luticate_permissions VALUES ('LU_GROUP_GET', false);
39
-INSERT INTO luticate_permissions VALUES ('LU_PERM_USER_ADD', false);
40
-INSERT INTO luticate_permissions VALUES ('LU_PERM_USER_DEL', false);
41
-INSERT INTO luticate_permissions VALUES ('LU_PERM_USER_EDIT', false);
42
-INSERT INTO luticate_permissions VALUES ('LU_USER_EDIT', false);
43
-INSERT INTO luticate_permissions VALUES ('LU_USER_DEL', false);
44
-INSERT INTO luticate_permissions VALUES ('LU_USER_ADD', false);
45
-INSERT INTO luticate_permissions VALUES ('LU_PERM_USER_GET', false);
46
-
47
-
48
---
49
---
50
-
51
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_ADD', true, 0);
52
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_DEL', true, 0);
53
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_EDIT', true, 0);
54
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_GET', true, 0);
55
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_USER_ADD', true, 0);
56
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_USER_DEL', true, 0);
57
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_EFFECTIVE_GET', true, 0);
58
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GET', true, 0);
59
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GROUP_ADD', true, 0);
60
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GROUP_DEL', true, 0);
61
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GROUP_EDIT', true, 0);
62
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GROUP_GET', true, 0);
63
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_USER_ADD', true, 0);
64
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_USER_DEL', true, 0);
65
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_USER_EDIT', true, 0);
66
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_USER_GET', true, 0);
67
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_ADD', true, 0);
68
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_DEL', true, 0);
69
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_EDIT', true, 0);
70
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_EDIT_ME', true, 0);
71
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_GET', true, 0);
72
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_LOGIN', true, 0);
73
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_SET_PASSWORD', true, 0);
74
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_SET_PASSWORD_ME', true, 0);
75
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_ADD', true, 1);
76
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_DEL', true, 1);
77
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_EDIT', true, 1);
78
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_GET', true, 1);
79
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_USER_ADD', true, 1);
80
-INSERT INTO luticate_permissions_groups VALUES ('LU_GROUP_USER_DEL', true, 1);
81
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_EFFECTIVE_GET', true, 1);
82
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GET', true, 1);
83
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GROUP_ADD', true, 1);
84
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GROUP_DEL', true, 1);
85
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GROUP_EDIT', true, 1);
86
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_GROUP_GET', true, 1);
87
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_USER_ADD', true, 1);
88
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_USER_DEL', true, 1);
89
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_USER_EDIT', true, 1);
90
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_USER_GET', true, 1);
91
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_ADD', true, 1);
92
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_DEL', true, 1);
93
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_EDIT', true, 1);
94
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_EDIT_ME', true, 1);
95
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_GET', true, 1);
96
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_LOGIN', true, 1);
97
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_SET_PASSWORD', true, 1);
98
-INSERT INTO luticate_permissions_groups VALUES ('LU_USER_SET_PASSWORD_ME', true, 1);
99
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_EDIT', true, 0);
100
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_DEL', true, 0);
101
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_ADD', true, 0);
102
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_ADD', false, 1);
103
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_EDIT', false, 1);
104
-INSERT INTO luticate_permissions_groups VALUES ('LU_PERM_DEL', false, 1);
105
-
106
-
107
---
108
---
109
-
110
-INSERT INTO luticate_users VALUES (0, 'anonymous', 'anonymous@example.com', '', '', NULL, 'anonymous', 'anonymous');
111
-INSERT INTO luticate_users VALUES (1, 'root', 'root@example.com', '$2y$10$m1aN1a1ZEr1vmjFPfWl4Pu/63EhcxVCrC/DF0DFhdGbvORwtJtCmy', '3vwW1qQ28I', NULL, 'root', 'root');
112
-
113
-
114
---
115
---
116
-
117
-INSERT INTO luticate_permissions_users VALUES ('LU_GROUP_ADD', false, 0);
118
-INSERT INTO luticate_permissions_users VALUES ('LU_GROUP_DEL', false, 0);
119
-INSERT INTO luticate_permissions_users VALUES ('LU_GROUP_EDIT', false, 0);
120
-INSERT INTO luticate_permissions_users VALUES ('LU_GROUP_USER_ADD', false, 0);
121
-INSERT INTO luticate_permissions_users VALUES ('LU_GROUP_USER_DEL', false, 0);
122
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_ADD', false, 0);
123
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_DEL', false, 0);
124
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_EDIT', false, 0);
125
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_EFFECTIVE_GET', false, 0);
126
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_GET', false, 0);
127
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_GROUP_ADD', false, 0);
128
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_GROUP_DEL', false, 0);
129
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_GROUP_EDIT', false, 0);
130
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_GROUP_GET', false, 0);
131
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_USER_ADD', false, 0);
132
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_USER_DEL', false, 0);
133
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_USER_EDIT', false, 0);
134
-INSERT INTO luticate_permissions_users VALUES ('LU_PERM_USER_GET', false, 0);
135
-INSERT INTO luticate_permissions_users VALUES ('LU_USER_ADD', false, 0);
136
-INSERT INTO luticate_permissions_users VALUES ('LU_USER_DEL', false, 0);
137
-INSERT INTO luticate_permissions_users VALUES ('LU_USER_EDIT', false, 0);
138
-INSERT INTO luticate_permissions_users VALUES ('LU_USER_EDIT_ME', false, 0);
139
-INSERT INTO luticate_permissions_users VALUES ('LU_USER_GET', false, 0);
140
-INSERT INTO luticate_permissions_users VALUES ('LU_USER_SET_PASSWORD', false, 0);
141
-INSERT INTO luticate_permissions_users VALUES ('LU_USER_SET_PASSWORD_ME', false, 0);
142
-INSERT INTO luticate_permissions_users VALUES ('LU_USER_LOGIN', true, 0);
143
-INSERT INTO luticate_permissions_users VALUES ('LU_GROUP_GET', false, 0);
144
-
145
-
146
---
147
---
148
-
149
-INSERT INTO luticate_users_groups VALUES (1, 0);
150
-
151
-
152
---
153
---
154
-
155
-SELECT pg_catalog.setval('luticate_users_id_seq', 2, true);
156
-
157
-
158
---
159
---

+ 0
- 85
sql/struct_0_1_2.sql View File

@@ -1,93 +0,0 @@
1
---
2
---
3
-
4
-CREATE TABLE luticate_settings (
5
-    name character varying(128) NOT NULL,
6
-    type character varying(128) NOT NULL,
7
-    value text NOT NULL,
8
-    is_blocked boolean NOT NULL,
9
-    is_admin boolean NOT NULL
10
-);
11
-
12
-
13
---
14
---
15
-
16
-CREATE TABLE luticate_settings_users (
17
-    name character varying(128) NOT NULL,
18
-    value text NOT NULL,
19
-    user_id integer NOT NULL,
20
-    is_blocked boolean NOT NULL
21
-);
22
-
23
---
24
---
25
-
26
-ALTER TABLE ONLY luticate_settings
27
-    ADD CONSTRAINT luticate_settings_pkey PRIMARY KEY (name);
28
-
29
-
30
---
31
---
32
-
33
-ALTER TABLE ONLY luticate_settings_users
34
-    ADD CONSTRAINT luticate_settings_users_pkey PRIMARY KEY (name, user_id);
35
-
36
---
37
---
38
-
39
-ALTER TABLE ONLY luticate_settings_users
40
-    ADD CONSTRAINT luticate_settings_users_name_fkey FOREIGN KEY (name) REFERENCES luticate_settings(name) ON DELETE CASCADE;
41
-
42
-
43
---
44
---
45
-
46
-ALTER TABLE ONLY luticate_settings_users
47
-    ADD CONSTRAINT luticate_settings_users_user_id_fkey FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
48
-
49
---
50
---
51
-
52
-CREATE FUNCTION sp_lu_get_user_setting(_user_id integer, _setting_name character varying, OUT setting json) RETURNS json
53
-    LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER COST 10
54
-    AS $$
55
-DECLARE
56
-_setting luticate_settings;
57
-_setting_user luticate_settings_users;
58
-BEGIN
59
-    SELECT * INTO _setting FROM luticate_settings WHERE "name" = _setting_name AND NOT "is_admin";
60
-    IF _setting IS NULL THEN
61
-        setting := NULL;
62
-    ELSE
63
-        IF NOT _setting.is_blocked THEN
64
-            SELECT * INTO _setting_user FROM luticate_settings_users WHERE "user_id" = _user_id AND "name" = _setting_name;
65
-            IF _setting_user IS NOT NULL THEN
66
-                _setting.value := _setting_user.value;
67
-            END IF;
68
-        END IF;
69
-        setting := to_json(_setting);
70
-    END IF;
71
-END;
72
-$$;
73
-
74
-
75
---
76
---
77
-
78
-CREATE FUNCTION sp_lu_get_all_user_settings(_user_id integer, OUT _settings json) RETURNS SETOF json
79
-    LANGUAGE sql IMMUTABLE SECURITY DEFINER COST 10
80
-    AS $$
81
-	SELECT sp_lu_get_user_setting(_user_id, s.name)
82
-	FROM luticate_settings s
83
-	WHERE NOT s.is_admin
84
-	ORDER BY s.name
85
-$$;

+ 0
- 240
sql/struct_init.sql View File

@@ -1,267 +0,0 @@
1
---
2
---
3
-
4
---
5
---
6
-
7
-CREATE SEQUENCE luticate_groups_id_seq
8
-START WITH 1
9
-INCREMENT BY 1
10
-NO MINVALUE
11
-NO MAXVALUE
12
-CACHE 1;
13
-
14
-SET default_tablespace = '';
15
-
16
-SET default_with_oids = false;
17
-
18
---
19
---
20
-
21
-CREATE TABLE luticate_groups (
22
-    id integer DEFAULT nextval('luticate_groups_id_seq'::regclass) NOT NULL,
23
-    name character varying NOT NULL
24
-);
25
-
26
-
27
-
28
---
29
---
30
-
31
-CREATE TABLE luticate_permissions (
32
-    name character varying(128) NOT NULL,
33
-    value boolean NOT NULL
34
-);
35
-
36
-
37
-
38
---
39
---
40
-
41
-CREATE TABLE luticate_permissions_groups (
42
-    name character varying(128) NOT NULL,
43
-    value boolean NOT NULL,
44
-    group_id integer NOT NULL
45
-);
46
-
47
-
48
-
49
---
50
---
51
-
52
-CREATE TABLE luticate_permissions_users (
53
-    name character varying(128) NOT NULL,
54
-    value boolean,
55
-    user_id integer NOT NULL
56
-);
57
-
58
-
59
-
60
---
61
---
62
-
63
-CREATE SEQUENCE luticate_users_id_seq
64
-START WITH 1
65
-INCREMENT BY 1
66
-NO MINVALUE
67
-NO MAXVALUE
68
-CACHE 1;
69
-
70
-
71
-
72
---
73
---
74
-
75
-CREATE TABLE luticate_users (
76
-    id integer DEFAULT nextval('luticate_users_id_seq'::regclass) NOT NULL,
77
-    username character varying(255) NOT NULL,
78
-    email character varying(255) NOT NULL,
79
-    password character varying(255) NOT NULL,
80
-    salt character varying(10) NOT NULL,
81
-    profile_id integer,
82
-    firstname character varying(255) NOT NULL,
83
-    lastname character varying(255) NOT NULL
84
-);
85
-
86
-
87
-
88
---
89
---
90
-
91
-CREATE TABLE luticate_users_groups (
92
-    user_id integer NOT NULL,
93
-    group_id integer NOT NULL
94
-);
95
-
96
-
97
---
98
---
99
-
100
-ALTER TABLE ONLY luticate_groups
101
-ADD CONSTRAINT luticate_groups_name_key UNIQUE (name);
102
-
103
-
104
---
105
---
106
-
107
-ALTER TABLE ONLY luticate_groups
108
-ADD CONSTRAINT luticate_groups_pkey PRIMARY KEY (id);
109
-
110
-
111
---
112
---
113
-
114
-ALTER TABLE ONLY luticate_permissions
115
-ADD CONSTRAINT luticate_permissions_pkey PRIMARY KEY (name);
116
-
117
-
118
---
119
---
120
-
121
-ALTER TABLE ONLY luticate_permissions_users
122
-ADD CONSTRAINT luticate_permissions_users_pkey PRIMARY KEY (name, user_id);
123
-
124
-
125
---
126
---
127
-
128
-ALTER TABLE ONLY luticate_users
129
-ADD CONSTRAINT luticate_users_email_key UNIQUE (email);
130
-
131
-
132
---
133
---
134
-
135
-ALTER TABLE ONLY luticate_users_groups
136
-ADD CONSTRAINT luticate_users_groups_pkey PRIMARY KEY (user_id, group_id);
137
-
138
-
139
---
140
---
141
-
142
-ALTER TABLE ONLY luticate_users
143
-ADD CONSTRAINT luticate_users_pkey PRIMARY KEY (id);
144
-
145
-
146
---
147
---
148
-
149
-ALTER TABLE ONLY luticate_users
150
-ADD CONSTRAINT luticate_users_username_key UNIQUE (username);
151
-
152
-
153
---
154
---
155
-
156
-ALTER TABLE ONLY luticate_permissions_groups
157
-ADD CONSTRAINT pkey PRIMARY KEY (name, group_id);
158
-
159
-
160
---
161
---
162
-
163
-ALTER TABLE ONLY luticate_permissions_groups
164
-ADD CONSTRAINT foreign_group FOREIGN KEY (group_id) REFERENCES luticate_groups(id) ON DELETE CASCADE;
165
-
166
-
167
---
168
---
169
-
170
-ALTER TABLE ONLY luticate_users_groups
171
-ADD CONSTRAINT foreign_group FOREIGN KEY (group_id) REFERENCES luticate_groups(id) ON DELETE CASCADE;
172
-
173
-
174
---
175
---
176
-
177
-ALTER TABLE ONLY luticate_permissions_groups
178
-ADD CONSTRAINT foreign_name FOREIGN KEY (name) REFERENCES luticate_permissions(name) ON DELETE CASCADE;
179
-
180
-
181
---
182
---
183
-
184
-ALTER TABLE ONLY luticate_permissions_users
185
-ADD CONSTRAINT foreign_name FOREIGN KEY (name) REFERENCES luticate_permissions(name) ON DELETE CASCADE;
186
-
187
-
188
---
189
---
190
-
191
-ALTER TABLE ONLY luticate_permissions_users
192
-ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
193
-
194
-
195
---
196
---
197
-
198
-ALTER TABLE ONLY luticate_users_groups
199
-ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
200
-
201
---
202
---
203
-
204
-CREATE FUNCTION sp_lu_get_user_permission(_user_id integer, _permisson_name character varying, OUT val boolean) RETURNS boolean
205
-LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER COST 10
206
-AS $$
207
-DECLARE
208
-    groups int[];
209
-    g INT;
210
-BEGIN
211
-    SELECT "value" INTO val FROM luticate_permissions_users WHERE "user_id" = _user_id AND "name" = _permisson_name;
212
-    IF val is null THEN
213
-        SELECT lpg."value" into val FROM luticate_permissions_groups lpg
214
-            INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
215
-            INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
216
-        WHERE lpg."name" = _permisson_name and lpg."value" = FALSE;
217
-        IF val is null then
218
-            SELECT lpg."value" into val FROM luticate_permissions_groups lpg
219
-                INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
220
-                INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
221
-            WHERE lpg."name" = _permisson_name and lpg."value" = TRUE;
222
-            IF val is null then
223
-                SELECT "value" INTO val FROM luticate_permissions WHERE "name" = _permisson_name;
224
-            END IF;
225
-        end if;
226
-    END IF;
227
-END;
228
-$$;
229
-
230
---
231
---
232
-
233
-CREATE FUNCTION sp_lu_get_all_user_permission(_user_id integer, OUT _permisson_name character varying, OUT val boolean) RETURNS SETOF record
234
-LANGUAGE sql IMMUTABLE SECURITY DEFINER COST 10
235
-AS $$
236
-SELECT p.name, sp_lu_get_user_permission(_user_id, p.name) FROM luticate_permissions p ORDER bY p.name
237
-$$;
238
-
239
---
240
---

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

@@ -1,173 +0,0 @@
1
-<?php
2
-/**
3
- * Created by PhpStorm.
4
- * User: robin
5
- * Date: 9/30/15
6
- * Time: 7:04 PM
7
- */
8
-
9
-namespace Luticate\Auth\Business;
10
-
11
-use Luticate\Auth\DBO\LuticatePermissions;
12
-use Luticate\Auth\DBO\LuticateUsersDbo;
13
-use Luticate\Utils\LuRoute;
14
-
15
-class LuticateBusiness
16
-{
17
-    /**
18
-     * @var LuticateUsersDbo
19
-     */
20
-    private static $_currentUser;
21
-
22
-    public static function getCurrentUser()
23
-    {
24
-        return self::$_currentUser;
25
-    }
26
-
27
-    public static function setCurrentUser($user)
28
-    {
29
-        self::$_currentUser = $user;
30
-    }
31
-
32
-    public static function setupAuth()
33
-    {
34
-        $route = LuRoute::getInstance();
35
-        $route->addMiddleware('Luticate\Auth\Business\LuticateMiddleware');
36
-    }
37
-
38
-    /**
39
-     * @param $prefix string
40
-     */
41
-    public static function setupRoutes($prefix = "/luticate")
42
-    {
43
-        $ns = 'Luticate\Auth\Controller\\';
44
-
45
-        $int = "[0-9]+";
46
-        $name = "[A-Z0-9_]+";
47
-        $bool = "true|false";
48
-
49
-        $group_id = "{group_id:$int}";
50
-        $user_id = "{user_id:$int}";
51
-        $permission_name = "{permission_name:$name}";
52
-        $permission_value = "{permission_value:$bool}";
53
-        $setting_name = "{setting_name:$name}";
54
-
55
-        $route = LuRoute::getInstance();
56
-
57
-        $route->post("$prefix/users/login", "${ns}LuticateUsersController", "login");
58
-        $route->post("$prefix/users/logout", "${ns}LuticateUsersController", "logout");
59
-        $route->get("$prefix/users/me", "${ns}LuticateUsersController", "getLightMe");
60
-        $route->get("$prefix/users/$user_id", "${ns}LuticateUsersController",
61
-            "getLightById", LuticatePermissions::USER_GET);
62
-        $route->get("$prefix/users", "${ns}LuticateUsersController", "getAllLight", LuticatePermissions::USER_GET);
63
-        $route->post("$prefix/users/add", "${ns}LuticateUsersController",
64
-            "add", array(LuticatePermissions::USER_ADD, LuticatePermissions::USER_GET));
65
-        $route->post("$prefix/users/$user_id/del", "${ns}LuticateUsersController",
66
-            "del", array(LuticatePermissions::USER_DEL, LuticatePermissions::USER_GET));
67
-        $route->post("$prefix/users/$user_id/edit", "${ns}LuticateUsersController",
68
-            "edit", array(LuticatePermissions::USER_EDIT, LuticatePermissions::USER_GET));
69
-        $route->post("$prefix/users/me/edit", "${ns}LuticateUsersController",
70
-            "editMe", LuticatePermissions::USER_EDIT_ME);
71
-        $route->post("$prefix/users/$user_id/setPassword", "${ns}LuticateUsersController",
72
-            "setPassword", array(LuticatePermissions::USER_SET_PASSWORD, LuticatePermissions::USER_GET));
73
-        $route->post("$prefix/users/me/setPassword", "${ns}LuticateUsersController", "setPasswordMe",
74
-            LuticatePermissions::USER_SET_PASSWORD_ME);
75
-
76
-
77
-        $route->get("$prefix/groups/$group_id", "${ns}LuticateGroupsController",
78
-            "getById", LuticatePermissions::GROUP_GET);
79
-        $route->get("$prefix/groups", "${ns}LuticateGroupsController", "getAll", LuticatePermissions::GROUP_GET);
80
-        $route->post("$prefix/groups/add", "${ns}LuticateGroupsController",
81
-            "add", array(LuticatePermissions::GROUP_ADD, LuticatePermissions::GROUP_GET));
82
-        $route->post("$prefix/groups/$group_id/del", "${ns}LuticateGroupsController",
83
-            "del", array(LuticatePermissions::GROUP_DEL, LuticatePermissions::GROUP_GET));
84
-        $route->post("$prefix/groups/$group_id/edit", "${ns}LuticateGroupsController",
85
-            "edit", array(LuticatePermissions::GROUP_EDIT, LuticatePermissions::GROUP_GET));
86
-
87
-        $route->get("$prefix/groups/$group_id/users/", "${ns}LuticateGroupsController",
88
-            "getUsers", LuticatePermissions::GROUP_GET);
89
-        $route->post("$prefix/groups/$group_id/users/$user_id/add", "${ns}LuticateGroupsController",
90
-            "addUser", array(LuticatePermissions::GROUP_USER_ADD, LuticatePermissions::GROUP_GET));
91
-        $route->post("$prefix/groups/$group_id/users/$user_id/del", "${ns}LuticateGroupsController",
92
-            "delUser", array(LuticatePermissions::GROUP_USER_DEL, LuticatePermissions::GROUP_GET));
93
-
94
-
95
-        $route->get("$prefix/permissions/effective/$user_id/$permission_name", "${ns}LuticatePermissionsController",
96
-            "getEffectivePermission", LuticatePermissions::PERM_EFFECTIVE_GET);
97
-        $route->get("$prefix/permissions/effective/$user_id", "${ns}LuticatePermissionsController",
98
-            "getAllEffectivePermission", array(LuticatePermissions::PERM_GET, LuticatePermissions::PERM_EFFECTIVE_GET));
99
-        $route->get("$prefix/permissions/effective/me/$permission_name", "${ns}LuticatePermissionsController",
100
-            "getEffectivePermissionMe");
101
-        $route->get("$prefix/permissions/effective/me", "${ns}LuticatePermissionsController",
102
-            "getAllEffectivePermissionMe");
103
-
104
-        $route->get("$prefix/permissions/$permission_name", "${ns}LuticatePermissionsController", "get",
105
-            LuticatePermissions::PERM_GET);
106
-        $route->get("$prefix/permissions", "${ns}LuticatePermissionsController", "getAll",
107
-            LuticatePermissions::PERM_GET);
108
-        $route->post("$prefix/permissions/add/$permission_name/$permission_value", "${ns}LuticatePermissionsController",
109
-            "add", array(LuticatePermissions::PERM_ADD, LuticatePermissions::PERM_GET));
110
-        $route->post("$prefix/permissions/$permission_name/del", "${ns}LuticatePermissionsController", "del",
111
-            array(LuticatePermissions::PERM_DEL, LuticatePermissions::PERM_GET));
112
-        $route->post("$prefix/permissions/$permission_name/edit/$permission_value", "${ns}LuticatePermissionsController",
113
-            "edit", array(LuticatePermissions::PERM_EDIT, LuticatePermissions::PERM_GET));
114
-
115
-        $route->get("$prefix/permissions/group/$group_id/$permission_name", "${ns}LuticatePermissionsGroupsController",
116
-            "get", LuticatePermissions::PERM_GROUP_GET);
117
-        $route->get("$prefix/permissions/group/$group_id", "${ns}LuticatePermissionsGroupsController",
118
-            "getAllByGroup", LuticatePermissions::PERM_GROUP_GET);
119
-        $route->post("$prefix/permissions/group/$group_id/add/$permission_name/$permission_value",
120
-            "${ns}LuticatePermissionsGroupsController", "add", array(LuticatePermissions::PERM_GROUP_ADD,
121
-                LuticatePermissions::PERM_GROUP_GET));
122
-        $route->post("$prefix/permissions/group/$group_id/$permission_name/del",
123
-            "${ns}LuticatePermissionsGroupsController", "del", array(LuticatePermissions::PERM_GROUP_DEL,
124
-                LuticatePermissions::PERM_GROUP_GET));
125
-        $route->post("$prefix/permissions/group/$group_id/$permission_name/edit/$permission_value",
126
-            "${ns}LuticatePermissionsGroupsController", "edit", array(LuticatePermissions::PERM_GROUP_EDIT,
127
-                LuticatePermissions::PERM_GROUP_GET));
128
-
129
-        $route->get("$prefix/permissions/user/$user_id/$permission_name", "${ns}LuticatePermissionsUsersController",
130
-            "get", LuticatePermissions::PERM_USER_GET);
131
-        $route->get("$prefix/permissions/user/$user_id", "${ns}LuticatePermissionsUsersController",
132
-            "getAllByUser", LuticatePermissions::PERM_USER_GET);
133
-        $route->post("$prefix/permissions/user/$user_id/add/$permission_name/$permission_value",
134
-            "${ns}LuticatePermissionsUsersController", "add", array(LuticatePermissions::PERM_USER_ADD,
135
-                LuticatePermissions::PERM_USER_GET));
136
-        $route->post("$prefix/permissions/user/$user_id/$permission_name/del", "${ns}LuticatePermissionsUsersController",
137
-            "del", array(LuticatePermissions::PERM_USER_DEL, LuticatePermissions::PERM_USER_GET));
138
-        $route->post("$prefix/permissions/user/$user_id/$permission_name/edit/$permission_value",
139
-            "${ns}LuticatePermissionsUsersController", "edit", array(LuticatePermissions::PERM_USER_EDIT,
140
-                LuticatePermissions::PERM_USER_GET));
141
-
142
-
143
-        $route->get("$prefix/settings/effective/$user_id/$setting_name", "${ns}LuticateSettingsController",
144
-            "getEffectiveSetting", LuticatePermissions::SETTING_EFFECTIVE_GET);
145
-        $route->get("$prefix/settings/effective/$user_id", "${ns}LuticateSettingsController",
146
-            "getAllEffectiveSetting", array(LuticatePermissions::SETTING_GET, LuticatePermissions::SETTING_EFFECTIVE_GET));
147
-        $route->get("$prefix/settings/effective/me/$setting_name", "${ns}LuticateSettingsController",
148
-            "getEffectiveSettingMe");
149
-        $route->get("$prefix/settings/effective/me", "${ns}LuticateSettingsController",
150
-            "getAllEffectiveSettingMe");
151
-
152
-        $route->get("$prefix/settings/$setting_name", "${ns}LuticateSettingsController",
153
-            "get", LuticatePermissions::SETTING_GET);
154
-        $route->get("$prefix/settings", "${ns}LuticateSettingsController",
155
-            "getAll", LuticatePermissions::SETTING_GET);
156
-        $route->post("$prefix/settings/add", "${ns}LuticateSettingsController",
157
-            "add", array(LuticatePermissions::SETTING_ADD, LuticatePermissions::SETTING_GET));
158
-        $route->post("$prefix/settings/$setting_name/del", "${ns}LuticateSettingsController",
159
-            "del", array(LuticatePermissions::SETTING_DEL, LuticatePermissions::SETTING_GET));
160
-        $route->post("$prefix/settings/$setting_name/edit", "${ns}LuticateSettingsController",
161
-            "edit", array(LuticatePermissions::SETTING_EDIT, LuticatePermissions::SETTING_GET));
162
-
163
-        $route->get("$prefix/settings/user/$user_id/$setting_name", "${ns}LuticateSettingsUsersController",
164
-            "get", LuticatePermissions::SETTING_USER_GET);
165
-        $route->get("$prefix/settings/user/$user_id", "${ns}LuticateSettingsUsersController",
166
-            "getAllByUser", LuticatePermissions::SETTING_USER_GET);
167
-        $route->post("$prefix/settings/user/$user_id/$setting_name/edit", "${ns}LuticateSettingsUsersController",
168
-            "edit", array(LuticatePermissions::SETTING_USER_EDIT, LuticatePermissions::SETTING_USER_GET));
169
-        $route->post("$prefix/settings/user/me/$setting_name/edit", "${ns}LuticateSettingsUsersController",
170
-            "editMe", LuticatePermissions::SETTING_EDIT_ME);
171
-
172
-    }
173
-}

+ 0
- 84
src/Auth/Business/LuticateGroupsBusiness.php View File

@@ -1,84 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Business;
4
-
5
-use Luticate\Utils\LuBusiness;
6
-use Luticate\Auth\DataAccess\LuticateGroupsDataAccess;
7
-use Luticate\Auth\DBO\LuticateGroupsDbo;
8
-
9
-class LuticateGroupsBusiness extends LuBusiness {
10
-    protected static function getDataAccess()
11
-    {
12
-        return new LuticateGroupsDataAccess();
13
-    }
14
-
15
-    /**
16
-     * @param $group_id
17
-     * @return LuticateGroupsDbo|null
18
-     */
19
-    public static function checkGroupId($group_id)
20
-    {
21
-        $group = LuticateGroupsDataAccess::getById($group_id);
22
-        if (is_null($group)) {
23
-            self::notFound("Group not found");
24
-        }
25
-        return $group;
26
-    }
27
-
28
-    public static function getUsers($group_id, $page = 0, $perPage = 2000000000, $query = "")
29
-    {
30
-        return LuticateGroupsDataAccess::getUsers($group_id, $page, $perPage, $query);
31
-    }
32
-
33
-    public static function getByName($group_name)
34
-    {
35
-        return LuticateGroupsDataAccess::getByName($group_name);
36
-    }
37
-
38
-    public static function hasUser($user_id, $group_id)
39
-    {
40
-        return LuticateGroupsDataAccess::hasUser($user_id, $group_id);
41
-    }
42
-
43
-    public static function addUser($user_id, $group_id)
44
-    {
45
-        self::checkGroupId($group_id);
46
-        LuticateUsersBusiness::checkUserId($user_id);
47
-        if (self::hasUser($user_id, $group_id)) {
48
-            return true;
49
-        }
50
-        return LuticateGroupsDataAccess::addUser($user_id, $group_id);
51
-    }
52
-
53
-    public static function delUser($user_id, $group_id)
54
-    {
55
-        self::checkGroupId($group_id);
56
-        LuticateUsersBusiness::checkUserId($user_id);
57
-        return LuticateGroupsDataAccess::delUser($user_id, $group_id);
58
-    }
59
-
60
-    public static function add($group_name)
61
-    {
62
-        $group = self::getByName($group_name);
63
-        if (is_null($group)) {
64
-            $group = new LuticateGroupsDbo();
65
-            $group->setName($group_name);
66
-            return LuticateGroupsDataAccess::addId($group);
67
-        }
68
-        self::badInput("Group name already exists");
69
-        return -1;
70
-    }
71
-
72
-    public static function edit($group_id, $group_name)
73
-    {
74
-        $group = self::getByName($group_name);
75
-        if (!is_null($group) && $group->getId() != $group_id) {
76
-            self::badInput("Group name already exists");
77
-        }
78
-        $group = self::checkGroupId($group_id);
79
-        $group->setName($group_name);
80
-
81
-        LuticateGroupsDataAccess::editById($group_id, $group);
82
-        return true;
83
-    }
84
-}

+ 0
- 70
src/Auth/Business/LuticateMiddleware.php View File

@@ -1,70 +0,0 @@
1
-<?php
2
-/**
3
- * Created by PhpStorm.
4
- * User: robin
5
- * Date: 10/19/15
6
- * Time: 9:14 PM
7
- */
8
-
9
-namespace Luticate\Auth\Business;
10
-
11
-use Closure;
12
-use Illuminate\Http\Request;
13
-use Luticate\Auth\DBO\LuticatePermissions;
14
-use Luticate\Auth\DBO\LuticateUsersDbo;
15
-use Luticate\Utils\LuBusiness;
16
-use Luticate\Utils\LuController;
17
-
18
-class LuticateMiddleware
19
-{
20
-    const TOKEN_HEADER = "X-Authorization";
21
-
22
-    /**
23
-     * @param $request Request
24
-     * @param Closure $next
25
-     * @param ...$permissions
26
-     * @return null|string
27
-     */
28
-    public function handle($request, Closure $next, ...$permissions)
29
-    {
30
-        /**
31
-         * @var $user LuticateUsersDbo
32
-         */
33
-        $user = null;
34
-        $token = $request->header(self::TOKEN_HEADER);
35
-        if ($token != null && $token != "") {
36
-            $data = JwtHelper::decode($token);
37
-            if ($data != null) {
38
-                $user_id = $data[LuticateUsersBusiness::KEY_USER_ID];
39
-                $salt = $data[LuticateUsersBusiness::KEY_SALT];
40
-                $user = LuticateUsersBusiness::getById($user_id);
41
-                if ($user->getSalt() != $salt) {
42
-                    $user = null;
43
-                }
44
-            }
45
-        }
46
-        if (is_null($user)) {
47
-            if ($token != null && $token != "") {
48
-                abort(401, "Invalid token");
49
-            }
50
-            $user = LuticateUsersBusiness::getById(0);
51
-        }
52
-
53
-        LuticateBusiness::setCurrentUser($user);
54
-        LuBusiness::$parameters["_user"] = $user;
55
-
56
-        $permissions[] = LuticatePermissions::USER_LOGIN;
57
-        foreach ($permissions as $permission) {
58
-            try {
59
-                $perm = LuticatePermissionsBusiness::getEffectivePermission($user->getId(), $permission);
60
-                if (!$perm->getValue()) {
61
-                    abort(401, "Permission denied");
62
-                }
63
-            } catch (\Exception $e)
64
-            {
65
-                abort(401, "Permission denied");
66
-            }
67
-        }
68
-        return $next($request);
69
-    }
70
-}

+ 0
- 93
src/Auth/Business/LuticatePermissionsBusiness.php View File

@@ -1,93 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Business;
4
-
5
-use Luticate\Utils\LuBusiness;
6
-use Luticate\Auth\DataAccess\LuticatePermissionsDataAccess;
7
-use Luticate\Auth\DBO\LuticatePermissionsDbo;
8
-use Luticate\Utils\LuMultipleDbo;
9
-
10
-class LuticatePermissionsBusiness extends LuBusiness {
11
-    protected static function getDataAccess()
12
-    {
13
-        return new LuticatePermissionsDataAccess();
14
-    }
15
-
16
-    public static function checkPermissionName($permission_name)
17
-    {
18
-        $perm = LuticatePermissionsDataAccess::getByName($permission_name);
19
-        if (is_null($perm)) {
20
-            self::notFound("Permission not found");
21
-        }
22
-        return $perm;
23
-    }
24
-
25
-    public static function getEffectivePermission($user_id, $permission_name)
26
-    {
27
-        self::checkPermissionName($permission_name);
28
-        $val = LuticatePermissionsDataAccess::getEffectivePermission($user_id, $permission_name);
29
-        $perm = new LuticatePermissionsDbo();
30
-        $perm->setValue($val);
31
-        $perm->setName($permission_name);
32
-        return $perm;
33
-    }
34
-
35
-    public static function getAllEffectivePermission($user_id)
36
-    {
37
-        $values = LuticatePermissionsDataAccess::getAllEffectivePermission($user_id);
38
-        $dbos = [];
39
-        foreach ($values as $value) {
40
-            $dbo = new LuticatePermissionsDbo();
41
-            $dbo->setName($value->getPermissonName());
42
-            $dbo->setValue($value->getVal());
43
-            $dbos[] = $dbo;
44
-        }
45
-        return new LuMultipleDbo(count($dbos), $dbos);
46
-    }
47
-
48
-    public static function getEffectiveDynamicPermission($user_id, $permission_name, $resource_id)
49
-    {
50
-        $dynamic_permission_name = "LU_DYN_" . $permission_name . "_" . $resource_id;
51
-        $val = self::getEffectivePermission($user_id, $dynamic_permission_name);
52
-        if (is_null($val->getValue())) {
53
-            return self::getEffectivePermission($user_id, $permission_name);
54
-        }
55
-        return $val;
56
-    }
57
-
58
-    public static function get($permission_name)
59
-    {
60
-        $perm = LuticatePermissionsDataAccess::getByName($permission_name);
61
-        if (is_null($perm)) {
62
-            self::notFound("Permission not found");
63
-        }
64
-        return $perm;
65
-    }
66
-
67
-    public static function add($permission_name, $permission_value)
68
-    {
69
-        $perm = LuticatePermissionsDataAccess::getByName($permission_name);
70
-        if (is_null($perm)) {
71
-            $perm = new LuticatePermissionsDbo();
72
-            $perm->setName($permission_name);
73
-            $perm->setValue($permission_value);
74
-            LuticatePermissionsDataAccess::add($perm);
75
-            return true;
76
-        }
77
-        self::badInput("Permission name already exists");
78
-        return false;
79
-    }
80
-
81
-    public static function del($permission_name)
82
-    {
83
-        LuticatePermissionsDataAccess::delete($permission_name);
84
-        return true;
85
-    }
86
-
87
-    public static function edit($permission_name, $permission_value)
88
-    {
89
-        self::checkPermissionName($permission_name);
90
-        LuticatePermissionsDataAccess::edit($permission_name, $permission_value);
91
-        return true;
92
-    }
93
-}

+ 0
- 74
src/Auth/Business/LuticatePermissionsGroupsBusiness.php View File

@@ -1,74 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Business;
4
-
5
-use Luticate\Auth\DBO\LuticatePermissionsDbo;
6
-use Luticate\Utils\LuBusiness;
7
-use Luticate\Auth\DataAccess\LuticatePermissionsGroupsDataAccess;
8
-use Luticate\Auth\DBO\LuticatePermissionsGroupsDbo;
9
-use Luticate\Utils\LuMultipleDbo;
10
-
11
-class LuticatePermissionsGroupsBusiness extends LuBusiness {
12
-    protected static function getDataAccess()
13
-    {
14
-        return new LuticatePermissionsGroupsDataAccess();
15
-    }
16
-
17
-    public static function checkPermissionGroupName($group_id, $permission_name)
18
-    {
19
-        LuticateGroupsBusiness::checkGroupId($group_id);
20
-        LuticatePermissionsBusiness::checkPermissionName($permission_name);
21
-        return LuticatePermissionsGroupsDataAccess::getByName($group_id, $permission_name);
22
-    }
23
-
24
-    public static function getAllByGroup($group_id, $page = 0, $perPage = 2000000000)
25
-    {
26
-        $users = LuticatePermissionsGroupsDataAccess::getAllByGroup($group_id, $page, $perPage);
27
-        return $users->map(function($user)
28
-        {
29
-            $dbo = new LuticatePermissionsDbo();
30
-            $dbo->setValue($user->getValue());
31
-            $dbo->setName($user->getName());
32
-            return $dbo;
33
-        });
34
-    }
35
-
36
-    public static function get($group_id, $permission_name)
37
-    {
38
-        $perm = self::checkPermissionGroupName($group_id, $permission_name);
39
-        if (is_null($perm)) {
40
-            $perm = new LuticatePermissionsGroupsDbo();
41
-            $perm->setName($permission_name);
42
-            $perm->setValue(null);
43
-            $perm->setGroupId($group_id);
44
-        }
45
-        return $perm;
46
-    }
47
-
48
-    public static function add($group_id, $permission_name, $permission_value)
49
-    {
50
-        $perm = self::checkPermissionGroupName($group_id, $permission_name);
51
-        if (!is_null($perm)) {
52
-            self::badInput("Group permission already exists");
53
-        }
54
-        $perm = new LuticatePermissionsGroupsDbo();
55
-        $perm->setName($permission_name);
56
-        $perm->setValue($permission_value);
57
-        $perm->setGroupId($group_id);
58
-        LuticatePermissionsGroupsDataAccess::add($perm);
59
-        return true;
60
-    }
61
-
62
-    public static function del($group_id, $permission_name)
63
-    {
64
-        self::checkPermissionGroupName($group_id, $permission_name);
65
-        LuticatePermissionsGroupsDataAccess::delete($group_id, $permission_name);
66
-        return true;
67
-    }
68
-
69
-    public static function edit($group_id, $permission_name, $permission_value)
70
-    {
71
-        self::del($group_id, $permission_name);
72
-        return self::add($group_id, $permission_name, $permission_value);
73
-    }
74
-}

+ 0
- 68
src/Auth/Business/LuticatePermissionsUsersBusiness.php View File

@@ -1,68 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Business;
4
-
5
-use Luticate\Auth\DBO\LuticatePermissionsDbo;
6
-use Luticate\Utils\LuBusiness;
7
-use Luticate\Auth\DataAccess\LuticatePermissionsUsersDataAccess;
8
-use Luticate\Auth\DBO\LuticatePermissionsUsersDbo;
9
-use Luticate\Utils\LuMultipleDbo;
10
-
11
-class LuticatePermissionsUsersBusiness extends LuBusiness {
12
-    protected static function getDataAccess()
13
-    {
14
-        return new LuticatePermissionsUsersDataAccess();
15
-    }
16
-
17
-    public static function checkPermissionUserName($user_id, $permission_name)
18
-    {
19
-        LuticateUsersBusiness::checkUserId($user_id);
20
-        LuticatePermissionsBusiness::checkPermissionName($permission_name);
21
-        return LuticatePermissionsUsersDataAccess::getByName($user_id, $permission_name);
22
-    }
23
-
24
-    public static function getAllByUser($user_id, $page = 0, $perPage = 2000000000)
25
-    {
26
-        $values = LuticatePermissionsUsersDataAccess::getAllByUser($user_id, $page, $perPage);
27
-        $dbos = [];
28
-        foreach ($values->getData() as $value) {
29
-            $dbo = new LuticatePermissionsDbo();
30
-            $dbo->setValue($value->getValue());
31
-            $dbo->setName($value->getName());
32
-            $dbos[] = $dbo;
33
-        }
34
-        return new LuMultipleDbo($values->getCount(), $dbos);
35
-    }
36
-
37
-    public static function get($user_id, $permission_name)
38
-    {
39
-        return LuticatePermissionsUsersDataAccess::getByName($user_id, $permission_name);
40
-    }
41
-
42
-    public static function add($user_id, $permission_name, $permission_value)
43
-    {
44
-        $perm = self::checkPermissionUserName($user_id, $permission_name);
45
-        if (!is_null($perm)) {
46
-            self::badInput("User permission already exists");
47
-        }
48
-        $perm = new LuticatePermissionsUsersDbo();
49
-        $perm->setName($permission_name);
50
-        $perm->setValue($permission_value);
51
-        $perm->setUserId($user_id);
52
-        LuticatePermissionsUsersDataAccess::add($perm);
53
-        return true;
54
-    }
55
-
56
-    public static function del($user_id, $permission_name)
57
-    {
58
-        self::checkPermissionUserName($user_id, $permission_name);
59
-        LuticatePermissionsUsersDataAccess::delete($user_id, $permission_name);
60
-        return true;
61
-    }
62
-
63
-    public static function edit($user_id, $permission_name, $permission_value)
64
-    {
65
-        self::del($user_id, $permission_name);
66
-        return self::add($user_id, $permission_name, $permission_value);
67
-    }
68
-}

+ 0
- 170
src/Auth/Business/LuticateSettingsBusiness.php View File

@@ -1,170 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Business;
4
-
5
-use Luticate\Utils\LuBusiness;
6
-use Luticate\Auth\DataAccess\LuticateSettingsDataAccess;
7
-use Luticate\Auth\DBO\LuticateSettingsDbo;
8
-use Luticate\Utils\LuMultipleDbo;
9
-use Luticate\Utils\LuStringUtils;
10
-
11
-class LuticateSettingsBusiness extends LuBusiness {
12
-    protected static function getDataAccess()
13
-    {
14
-        return new LuticateSettingsDataAccess();
15
-    }
16
-
17
-    /**
18
-     * @param $setting LuticateSettingsDbo
19
-     */
20
-    public static function checkSetting($setting)
21
-    {
22
-        $val = $setting->getValue();
23
-        $type = $setting->getType();
24
-        if (is_null($setting->getName())) {
25
-            self::notFound("Setting Name cannot be null");
26
-        }
27
-        if (is_null($val)) {
28
-            self::notFound("Setting Value cannot be null");
29
-        }
30
-        if (is_null($type)) {
31
-            self::notFound("Setting Type cannot be null");
32
-        }
33
-        if (!is_bool($setting->getIsBlocked())) {
34
-            self::notFound("Setting IsBlocked must be boolean");
35
-        }
36
-        if (!is_bool($setting->getIsAdmin())) {
37
-            self::notFound("Setting IsAdmin must be boolean");
38
-        }
39
-        else {
40
-            if ($type == "string") {
41
-                if (!is_string($val)) {
42
-                    self::badInput("Invalid Value");
43
-                }
44
-            }
45
-            else if ($type == "int") {
46
-                if (!is_int($val)) {
47
-                    self::badInput("Invalid Value");
48
-                }
49
-            }
50
-            else if ($type == "float") {
51
-                if (!is_float($val) && !is_int($val)) {
52
-                    self::badInput("Invalid Value");
53
-                }
54
-            }
55
-            else if ($type == "bool") {
56
-                if (!is_bool($val)) {
57
-                    self::badInput("Invalid Value");
58
-                }
59
-            }
60
-            else if ($type == "object") {
61
-                if (!is_array($val)) {
62
-                    self::badInput("Invalid Value");
63
-                }
64
-            }
65
-            else {
66
-                self::badInput("Unknown Type");
67
-            }
68
-            $setting->setValue(json_encode($val));
69
-        }
70
-    }
71
-
72
-    public static function checkSettingName($setting_name)
73
-    {
74
-        $setting = LuticateSettingsDataAccess::getByName($setting_name);
75
-        if (is_null($setting)) {
76
-            self::notFound("Setting not found");
77
-        }
78
-        return $setting;
79
-    }
80
-
81
-    public static function getAll($page = 0, $perPage = 2000000000, $query = "")
82
-    {
83
-        return parent::getAll($page, $perPage, $query)->map(function($value)
84
-        {
85
-            $value->setValue(json_decode($value->getValue()));
86
-            return $value;
87
-        });
88
-    }
89
-
90
-    public static function getEffectiveSetting($user_id, $setting_name)
91
-    {
92
-        $val = LuticateSettingsDataAccess::getEffectiveSetting($user_id, $setting_name);
93
-        if (is_null($val->getSetting())) {
94
-            self::notFound("Setting not found");
95
-        }
96
-
97
-        $setting = LuStringUtils::convertJsonString($val->getSetting());
98
-        $setting["Value"] = json_decode($setting["Value"]);
99
-        return $setting;
100
-    }
101
-
102
-    public static function getEffectiveSettingValue($user_id, $setting_name)
103
-    {
104
-        $setting = self::getEffectiveSetting($user_id, $setting_name);
105
-        return $setting["Value"];
106
-    }
107
-
108
-    public static function getAllEffectiveSetting($user_id)
109
-    {
110
-        return LuticateSettingsDataAccess::getAllEffectiveSetting($user_id)->map(function($value)
111
-        {
112
-            $setting = $value["Settings"];
113
-            $setting["Value"] = json_decode($setting["Value"]);
114
-            return $setting;
115
-        });
116
-    }
117
-
118
-    public static function get($setting_name)
119
-    {
120
-        $setting = LuticateSettingsDataAccess::getByName($setting_name);
121
-        if (is_null($setting)) {
122
-            self::notFound("Permission not found");
123
-        }
124
-        $setting->setValue(json_decode($setting->getValue()));
125
-        return $setting;
126
-    }
127
-
128
-    public static function getValue($setting_name)
129
-    {
130
-        $setting = self::get($setting_name);
131
-        return $setting->getValue();
132
-    }
133
-
134
-    /**
135
-     * @param $setting LuticateSettingsDbo
136
-     * @return bool
137
-     */
138
-    public static function add($setting)
139
-    {
140
-        self::checkSetting($setting);
141
-        $perm = LuticateSettingsDataAccess::getByName($setting->getName());
142
-        if (is_null($perm)) {
143
-            LuticateSettingsDataAccess::add($setting);
144
-            return true;
145
-        }
146
-        self::badInput("Setting name already exists");
147
-        return false;
148
-    }
149
-
150
-    public static function del($setting_name)
151
-    {
152
-        LuticateSettingsDataAccess::delete($setting_name);
153
-        return true;
154
-    }
155
-
156
-    /**
157
-     * @param $setting_name string
158
-     * @param $setting LuticateSettingsDbo
159
-     * @return bool
160
-     */
161
-    public static function edit($setting_name, $setting)
162
-    {
163
-        $set = self::checkSettingName($setting_name);
164
-        $setting->setName($set->getName());
165
-        $setting->setType($set->getType());
166
-        self::checkSetting($setting);
167
-        LuticateSettingsDataAccess::edit($setting_name, $setting);
168
-        return true;
169
-    }
170
-}

+ 0
- 73
src/Auth/Business/LuticateSettingsUsersBusiness.php View File

@@ -1,73 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Business;
4
-
5
-use Luticate\Utils\LuBusiness;
6
-use Luticate\Auth\DataAccess\LuticateSettingsUsersDataAccess;
7
-use Luticate\Auth\DBO\LuticateSettingsUsersDbo;
8
-use Luticate\Utils\LuMultipleDbo;
9
-
10
-class LuticateSettingsUsersBusiness extends LuBusiness {
11
-    protected static function getDataAccess()
12
-    {
13
-        return new LuticateSettingsUsersDataAccess();
14
-    }
15
-
16
-    public static function checkSettingUserName($user_id, $setting_name)
17
-    {
18
-        LuticateUsersBusiness::checkUserId($user_id);
19
-        LuticateSettingsBusiness::checkSettingName($setting_name);
20
-        $setting = LuticateSettingsUsersDataAccess::getByName($user_id, $setting_name);
21
-        if (is_null($setting)) {
22
-            self::notFound("User setting not found");
23
-        }
24
-        return $setting;
25
-    }
26
-
27
-    public static function getAllByUser($user_id, $page = 0, $perPage = 2000000000)
28
-    {
29
-        return LuticateSettingsUsersDataAccess::getAllByUser($user_id, $page, $perPage)->map(function($value)
30
-        {
31
-            $value->setValue(json_decode($value->getValue()));
32
-            return $value;
33
-        });
34
-    }
35
-
36
-    /**
37
-     * @param $user_setting LuticateSettingsUsersDbo
38
-     * @param $admin_edit bool
39
-     * @return bool
40
-     */
41
-    public static function edit($user_setting, $admin_edit)
42
-    {
43
-        LuticateUsersBusiness::checkUserId($user_setting->getUserId());
44
-        $setting = LuticateSettingsBusiness::checkSettingName($user_setting->getName());
45
-        if ($setting->getIsBlocked() && !$admin_edit) {
46
-            self::unauthorized("Setting is blocked");
47
-        }
48
-        if (is_null($user_setting->getValue())) {
49
-            LuticateSettingsUsersDataAccess::delete($user_setting->getUserId(), $user_setting->getName());
50
-        } else {
51
-            $setting->setValue($user_setting->getValue());
52
-            LuticateSettingsBusiness::checkSetting($setting);
53
-            $user_setting->setValue(json_encode($user_setting->getValue()));
54
-            $real_user_setting = LuticateSettingsUsersDataAccess::getByName($user_setting->getUserId(), $user_setting->getName());
55
-            if (is_null($real_user_setting)) {
56
-                if (is_null($user_setting->getIsBlocked())) {
57
-                    $user_setting->setIsBlocked(false);
58
-                }
59
-                LuticateSettingsUsersDataAccess::add($user_setting);
60
-            }
61
-            else {
62
-                if ($real_user_setting->getIsBlocked() && !$admin_edit) {
63
-                    self::unauthorized("User setting is blocked");
64
-                }
65
-                if (is_null($user_setting->getIsBlocked())) {
66
-                    $user_setting->setIsBlocked($real_user_setting->getIsBlocked());
67
-                }
68
-                LuticateSettingsUsersDataAccess::edit($user_setting);
69
-            }
70
-        }
71
-        return true;
72
-    }
73
-}

+ 0
- 192
src/Auth/Business/LuticateUsersBusiness.php View File

@@ -1,192 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Business;
4
-
5
-use Illuminate\Support\Facades\DB;
6
-use Luticate\Auth\DBO\LuticatePermissions;
7
-use Luticate\Auth\DBO\LuticateUsersLightDbo;
8
-use Luticate\Auth\DBO\LuticateUsersLoginDbo;
9
-use Luticate\Utils\LuBusiness;
10
-use Luticate\Auth\DataAccess\LuticateUsersDataAccess;
11
-use Luticate\Auth\DBO\LuticateUsersDbo;
12
-use Luticate\Utils\LuMultipleDbo;
13
-
14
-class LuticateUsersBusiness extends LuBusiness {
15
-
16
-    const KEY_USER_ID =  "user_id";
17
-    const KEY_SALT =  "salt";
18
-    const KEY_DATA =  "data";
19
-
20
-    protected static function getDataAccess()
21
-    {
22
-        return new LuticateUsersDataAccess();
23
-    }
24
-
25
-    protected static function badPassword()
26
-    {
27
-        abort(401, "Bad username/password");
28
-    }
29
-
30
-    public static function hashPassword($password)
31
-    {
32
-        return password_hash($password, PASSWORD_BCRYPT);
33
-    }
34
-
35
-    public static function verifyPassword($password, $hash)
36
-    {
37
-        return password_verify($password, $hash);
38
-    }
39
-
40
-    public static function getSalt($length = 10)
41
-    {
42
-        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
43
-        $charactersLength = strlen($characters);
44
-        $randomString = '';
45
-        for ($i = 0; $i < $length; $i++) {
46
-            $randomString .= $characters[rand(0, $charactersLength - 1)];
47
-        }
48
-        return $randomString;
49
-    }
50
-
51
-    /**
52
-     * @param $user LuticateUsersDbo
53
-     * @param $data mixed
54
-     * @return string
55
-     */
56
-    public static function getToken($user, $data = null)
57
-    {
58
-        $session_time = LuticateSettingsBusiness::getValue("LU_SESSION_DAYS");
59
-        return JwtHelper::encode(array(
60
-            self::KEY_USER_ID => $user->getId(),
61
-            self::KEY_SALT => $user->getSalt(),
62
-            self::KEY_DATA => $data
63
-            ), $session_time);
64
-    }
65
-
66
-    /**
67
-     * @param $user_id
68
-     * @return LuticateUsersDbo|null
69
-     */
70
-    public static function checkUserId($user_id)
71
-    {
72
-        $user = LuticateUsersDataAccess::getById($user_id);
73
-        if (is_null($user)) {
74
-            self::notFound("User not found");
75
-        }
76
-        return $user;
77
-    }
78
-
79
-    public static function login($username, $password)
80
-    {
81
-        $user = LuticateUsersDataAccess::getByUsernameOrEmail($username);
82
-        if (is_null($user))
83
-            self::badPassword();
84
-        if (!self::verifyPassword($password, $user->getPassword()))
85
-            self::badPassword();
86
-
87
-        $user = LuticateUsersLoginDbo::fromUserDbo($user);
88
-        $user->setToken(self::getToken($user));
89
-        return $user;
90
-    }
91
-
92
-    /**
93
-     * @param $user LuticateUsersDbo
94
-     * @return bool
95
-     */
96
-    public static function logout($user)
97
-    {
98
-        if ($user->getId() != 0) {
99
-            $user->setSalt(self::getSalt());
100
-            LuticateUsersDataAccess::editById($user->getId(), $user);
101
-        }
102
-        return true;
103
-    }
104
-
105
-    public static function getAllLight($page = 0, $perPage = 2000000000, $query = "")
106
-    {
107
-        $users = self::getAll($page, $perPage, $query);
108
-        return $users->map(function($user)
109
-        {
110
-            return LuticateUsersLightDbo::fromUserDbo($user);
111
-        });
112
-    }
113
-
114
-    public static function getLightById($user_id)
115
-    {
116
-        $user = self::getById($user_id);
117
-        if (is_null($user)) {
118
-            self::notFound(self::getResourceName() . " not found");
119
-        }
120
-        return LuticateUsersLightDbo::fromUserDbo($user);
121
-    }
122
-
123
-    public static function deleteById($id)
124
-    {
125
-        if ($id != 0) {
126
-            $res = static::getDataAccess()->deleteById($id);
127
-            if (!$res)
128
-                self::notFound(static::getResourceName() . " not found");
129
-        }
130
-        return true;
131
-    }
132
-
133
-    public static function add($username, $email, $firstname, $lastname, $password)
134
-    {
135
-        if (strlen($password) < 5) {
136
-            self::badInput("Password must have at least 5 characters");
137
-        }
138
-        $hash = self::hashPassword($password);
139
-        if (filter_var($username, FILTER_VALIDATE_EMAIL))
140
-            self::badInput("Username can not be an email");
141
-        if (!preg_match("/^[A-Za-z0-9\\-_\\.]+$/", $username)) {
142
-            self::badInput("Username can only contain letters (A-Z a-z), numbers (0-9), hyphen (-), underscore (_) and dot (.)");
143
-        }
144
-        if (!filter_var($email, FILTER_VALIDATE_EMAIL))
145
-            self::badInput("Invalid email address");
146
-        $user = LuticateUsersDataAccess::getByUsernameOrEmail($username);
147
-        if (!is_null($user))
148
-            self::badInput("Username already exists");
149
-        $user = LuticateUsersDataAccess::getByUsernameOrEmail($email);
150
-        if (!is_null($user))
151
-            self::badInput("Email already used");
152
-
153
-        $user = new LuticateUsersDbo();
154
-        $user->setEmail($email);
155
-        $user->setPassword($hash);
156
-        $user->setUsername($username);
157
-        $user->setFirstname($firstname);
158
-        $user->setLastname($lastname);
159
-        $user->setSalt(self::getSalt());
160
-
161
-        return LuticateUsersDataAccess::addId($user);
162
-    }
163
-
164
-    public static function edit($user_id, $firstname, $lastname, $email)
165
-    {
166
-        $user = self::checkUserId($user_id);
167
-        if (!filter_var($email, FILTER_VALIDATE_EMAIL))
168
-            self::badInput("Invalid email address");
169
-        $user->setEmail($email);
170
-        $user->setFirstname($firstname);
171
-        $user->setLastname($lastname);
172
-        LuticateUsersDataAccess::editById($user_id, $user);
173
-        return true;
174
-    }
175
-
176
-    public static function setPassword($user_id, $password)
177
-    {
178
-        if ($user_id != 0) {
179
-            $user = self::checkUserId($user_id);
180
-            $user->setPassword(self::hashPassword($password));
181
-            $user->setSalt(self::getSalt());
182
-            LuticateUsersDataAccess::editById($user_id, $user);
183
-        }
184
-        return true;
185
-    }
186
-
187
-    public static function setPasswordMe($password, $oldPassword, $user)
188
-    {
189
-        self::login($user->getUsername(), $oldPassword);
190
-        return self::setPassword($user->getId(), $password);
191
-    }
192
-}

+ 0
- 102
src/Auth/Controller/LuticateGroupsController.php View File

@@ -1,102 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Controller;
4
-
5
-use Luticate\Utils\LuController;
6
-use Luticate\Auth\Business\LuticateGroupsBusiness;
7
-use Luticate\Auth\DBO\LuticateGroupsDbo;
8
-
9
-class LuticateGroupsController extends LuController {
10
-    protected function getBusiness()
11
-    {
12
-        return new LuticateGroupsBusiness();
13
-    }
14
-
15
-    /**
16
-     * Get a group by its id
17
-     * @param $group_id int The group id
18
-     * @return \Luticate\Utils\LuDbo
19
-     */
20
-    public function getById($group_id)
21
-    {
22
-        return LuticateGroupsBusiness::getById($group_id);
23
-    }
24
-
25
-    /**
26
-     * Get all groups
27
-     * @param int $page The page number, 0 based
28
-     * @param int $perPage The number of items per page
29
-     * @param string $query The filter query
30
-     * @return \Luticate\Utils\LuMultipleDbo
31
-     */
32
-    public function getAll($page = 0, $perPage = 2000000000, $query = "")
33
-    {
34
-        return LuticateGroupsBusiness::getAll($page, $perPage, $query);
35
-    }
36
-
37
-    /**
38
-     * Get all users in group
39
-     * @param $group_id int The group id
40
-     * @param int $page The page number, 0 based
41
-     * @param int $perPage The number of items per page
42
-     * @param string $query The filter query
43
-     * @return \Luticate\Utils\LuMultipleDbo
44
-     */
45
-    public function getUsers($group_id, $page = 0, $perPage = 2000000000, $query = "")
46
-    {
47
-        return LuticateGroupsBusiness::getUsers($group_id, $page, $perPage, $query);
48
-    }
49
-
50
-    /**
51
-     * Add a new group
52
-     * @param $group_name string The group name
53
-     * @return int
54
-     */
55
-    public function add($group_name)
56
-    {
57
-        return LuticateGroupsBusiness::add($group_name);
58
-    }
59
-
60
-    /**
61
-     * Delete a group by its id
62
-     * @param $group_id int The group id
63
-     * @return bool
64
-     */
65
-    public function del($group_id)
66
-    {
67
-        return LuticateGroupsBusiness::deleteById($group_id);
68
-    }
69
-
70
-    /**
71
-     * Edit a group name by its id
72
-     * @param $group_id int The group id
73
-     * @param $group_name string The new group name
74
-     * @return bool
75
-     */
76
-    public function edit($group_id, $group_name)
77
-    {
78
-        return LuticateGroupsBusiness::edit($group_id, $group_name);
79
-    }
80
-
81
-    /**
82
-     * Add a user to a group
83
-     * @param $user_id int The user id
84
-     * @param $group_id int The group id
85
-     * @return bool
86
-     */
87
-    public function addUser($user_id, $group_id)
88
-    {
89
-        return LuticateGroupsBusiness::addUser($user_id, $group_id);
90
-    }
91
-
92
-    /**
93
-     * Delete a user from a group
94
-     * @param $user_id int The user id
95
-     * @param $group_id int The group id
96
-     * @return bool
97
-     */
98
-    public static function delUser($user_id, $group_id)
99
-    {
100
-        return LuticateGroupsBusiness::delUser($user_id, $group_id);
101
-    }
102
-}

+ 0
- 111
src/Auth/Controller/LuticatePermissionsController.php View File

@@ -1,111 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Controller;
4
-
5
-use Luticate\Auth\DBO\LuticateUsersDbo;
6
-use Luticate\Utils\LuController;
7
-use Luticate\Auth\Business\LuticatePermissionsBusiness;
8
-use Luticate\Auth\DBO\LuticatePermissionsDbo;
9
-
10
-class LuticatePermissionsController extends LuController {
11
-    protected function getBusiness()
12
-    {
13
-        return new LuticatePermissionsBusiness();
14
-    }
15
-
16
-    /**
17
-     * Get the effective permission for a user
18
-     * @param $user_id int The user id
19
-     * @param $permission_name string The permission name
20
-     * @return LuticatePermissionsDbo
21
-     */
22
-    public function getEffectivePermission($user_id, $permission_name)
23
-    {
24
-        return LuticatePermissionsBusiness::getEffectivePermission($user_id, $permission_name);
25
-    }
26
-
27
-    /**
28
-     * Get the effective permission for the logged user
29
-     * @param $_user LuticateUsersDbo Logged user
30
-     * @param $permission_name string The permission name
31
-     * @return LuticatePermissionsDbo
32
-     */
33
-    public function getEffectivePermissionMe($_user, $permission_name)
34
-    {
35
-        return LuticatePermissionsBusiness::getEffectivePermission($_user->getId(), $permission_name);
36
-    }
37
-
38
-    /**
39
-     * Get all the effective permission for a user
40
-     * @param $user_id int The user id
41
-     * @return LuticatePermissionsDbo
42
-     */
43
-    public function getAllEffectivePermission($user_id)
44
-    {
45
-        return LuticatePermissionsBusiness::getAllEffectivePermission($user_id);
46
-    }
47
-
48
-    /**
49
-     * Get all the effective permission for the logged user
50
-     * @param $_user LuticateUsersDbo Logged user
51
-     * @return LuticatePermissionsDbo
52
-     */
53
-    public function getAllEffectivePermissionMe($_user)
54
-    {
55
-        return LuticatePermissionsBusiness::getAllEffectivePermission($_user->getId());
56
-    }
57
-
58
-    /**
59
-     * Get a permission
60
-     * @param $permission_name string The permission name
61
-     * @return \Luticate\Utils\LuDbo
62
-     */
63
-    public function get($permission_name)
64
-    {
65
-        return LuticatePermissionsBusiness::get($permission_name);
66
-    }
67
-
68
-    /**
69
-     * Get all permissions
70
-     * @param int $page The page number, 0 based
71
-     * @param int $perPage The number of items per page
72
-     * @param string $query The filter query
73
-     * @return \Luticate\Utils\LuMultipleDbo
74
-     */
75
-    public function getAll($page = 0, $perPage = 2000000000, $query = "")
76
-    {
77
-        return LuticatePermissionsBusiness::getAll($page, $perPage, $query);
78
-    }
79
-
80
-    /**
81
-     * Add a permission
82
-     * @param $permission_name string The permission name
83
-     * @param $permission_value bool The default permission value
84
-     * @return bool
85
-     */
86
-    public function add($permission_name, $permission_value)
87
-    {
88
-        return LuticatePermissionsBusiness::add($permission_name, $permission_value);
89
-    }
90
-
91
-    /**
92
-     * Remove a permission
93
-     * @param $permission_name string The permission name
94
-     * @return bool
95
-     */
96
-    public function del($permission_name)
97
-    {
98
-        return LuticatePermissionsBusiness::del($permission_name);
99
-    }
100
-
101
-    /**
102
-     * Edit the default permission value
103
-     * @param $permission_name string The permission name
104
-     * @param $permission_value bool The default permission value
105
-     * @return bool
106
-     */
107
-    public function edit($permission_name, $permission_value)
108
-    {
109
-        return LuticatePermissionsBusiness::edit($permission_name, $permission_value);
110
-    }
111
-}

+ 0
- 72
src/Auth/Controller/LuticatePermissionsGroupsController.php View File

@@ -1,72 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Controller;
4
-
5
-use Luticate\Utils\LuController;
6
-use Luticate\Auth\Business\LuticatePermissionsGroupsBusiness;
7
-use Luticate\Auth\DBO\LuticatePermissionsGroupsDbo;
8
-
9
-class LuticatePermissionsGroupsController extends LuController {
10
-    protected function getBusiness()
11
-    {
12
-        return new LuticatePermissionsGroupsBusiness();
13
-    }
14
-
15
-    /**
16
-     * Get all permissions for a group
17
-     * @param $group_id int The group id
18
-     * @param int $page The page number, 0 based
19
-     * @param int $perPage The number of items per page
20
-     * @return \Luticate\Utils\LuMultipleDbo
21
-     */
22
-    public function getAllByGroup($group_id, $page = 0, $perPage = 2000000000)
23
-    {
24
-        return LuticatePermissionsGroupsBusiness::getAllByGroup($group_id, $page, $perPage);
25
-    }
26
-
27
-    /**
28
-     * Get a permission group
29
-     * @param $group_id int The group id
30
-     * @param $permission_name string The permission name
31
-     * @return LuticatePermissionsGroupsDbo
32
-     */
33
-    public function get($group_id, $permission_name)
34
-    {
35
-        return LuticatePermissionsGroupsBusiness::get($group_id, $permission_name);
36
-    }
37
-
38
-    /**
39
-     * Add a permission for a group
40
-     * @param $group_id int The group id
41
-     * @param $permission_name string The permission name
42
-     * @param $permission_value bool The permission value
43
-     * @return bool
44
-     */
45
-    public function add($group_id, $permission_name, $permission_value)
46
-    {
47
-        return LuticatePermissionsGroupsBusiness::add($group_id, $permission_name, $permission_value);
48
-    }
49
-
50
-    /**
51
-     * Delete a permission for a group
52
-     * @param $group_id int The group id
53
-     * @param $permission_name string The permission name
54
-     * @return bool
55
-     */
56
-    public function del($group_id, $permission_name)
57
-    {
58
-        return LuticatePermissionsGroupsBusiness::del($group_id, $permission_name);
59
-    }
60
-
61
-    /**
62
-     * Edit the permission value for a group
63
-     * @param $group_id int The group id
64
-     * @param $permission_name string The permission name
65
-     * @param $permission_value bool The permission value
66
-     * @return bool
67
-     */
68
-    public function edit($group_id, $permission_name, $permission_value)
69
-    {
70
-        return LuticatePermissionsGroupsBusiness::edit($group_id, $permission_name, $permission_value);
71
-    }
72
-}

+ 0
- 72
src/Auth/Controller/LuticatePermissionsUsersController.php View File

@@ -1,72 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Controller;
4
-
5
-use Luticate\Utils\LuController;
6
-use Luticate\Auth\Business\LuticatePermissionsUsersBusiness;
7
-use Luticate\Auth\DBO\LuticatePermissionsUsersDbo;
8
-
9
-class LuticatePermissionsUsersController extends LuController {
10
-    protected function getBusiness()
11
-    {
12
-        return new LuticatePermissionsUsersBusiness();
13
-    }
14
-
15
-    /**
16
-     * Get all permissions for a user
17
-     * @param $user_id int The user id
18
-     * @param int $page The page number, 0 based
19
-     * @param int $perPage The number of items per page
20
-     * @return \Luticate\Utils\LuMultipleDbo
21
-     */
22
-    public function getAllByUser($user_id, $page = 0, $perPage = 2000000000)
23
-    {
24
-        return LuticatePermissionsUsersBusiness::getAllByUser($user_id, $page, $perPage);
25
-    }
26
-
27
-    /**
28
-     * Get a permission for a user
29
-     * @param $user_id int The user id
30
-     * @param $permission_name string The permission name
31
-     * @return \Luticate\Utils\LuDbo
32
-     */
33
-    public function get($user_id, $permission_name)
34
-    {
35
-        return LuticatePermissionsUsersBusiness::get($user_id, $permission_name);
36
-    }
37
-
38
-    /**
39
-     * Add a permission for a user
40
-     * @param $user_id int The user id
41
-     * @param $permission_name string The permission name
42
-     * @param $permission_value bool The permission value
43
-     * @return bool
44
-     */
45
-    public function add($user_id, $permission_name, $permission_value)
46
-    {
47
-        return LuticatePermissionsUsersBusiness::add($user_id, $permission_name, $permission_value);
48
-    }
49
-
50
-    /**
51
-     * Delete a permission for a user
52
-     * @param $user_id int The user id
53
-     * @param $permission_name string The permission name
54
-     * @return bool
55
-     */
56
-    public function del($user_id, $permission_name)
57
-    {
58
-        return LuticatePermissionsUsersBusiness::del($user_id, $permission_name);
59
-    }
60
-
61
-    /**
62
-     * Edit the permission value for a user
63
-     * @param $user_id int The user id
64
-     * @param $permission_name string The permission name
65
-     * @param $permission_value bool The permission value
66
-     * @return bool
67
-     */
68
-    public function edit($user_id, $permission_name, $permission_value)
69
-    {
70
-        return LuticatePermissionsUsersBusiness::edit($user_id, $permission_name, $permission_value);
71
-    }
72
-}

+ 0
- 110
src/Auth/Controller/LuticateSettingsController.php View File

@@ -1,110 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Controller;
4
-
5
-use Luticate\Auth\DBO\LuticateUsersDbo;
6
-use Luticate\Utils\LuController;
7
-use Luticate\Auth\Business\LuticateSettingsBusiness;
8
-use Luticate\Auth\DBO\LuticateSettingsDbo;
9
-
10
-class LuticateSettingsController extends LuController {
11
-    protected function getBusiness()
12
-    {
13
-        return new LuticateSettingsBusiness();
14
-    }
15
-
16
-    /**
17
-     * Get the effective setting for a user
18
-     * @param $user_id int The user id
19
-     * @param $setting_name string The setting name
20
-     * @return LuticateSettingsDbo
21
-     */
22
-    public function getEffectiveSetting($user_id, $setting_name)
23
-    {
24
-        return LuticateSettingsBusiness::getEffectiveSetting($user_id, $setting_name);
25
-    }
26
-
27
-    /**
28
-     * Get the effective setting for the logged user
29
-     * @param $_user LuticateUsersDbo Logged user
30
-     * @param $setting_name string The setting name
31
-     * @return LuticateSettingsDbo
32
-     */
33
-    public function getEffectiveSettingMe($_user, $setting_name)
34
-    {
35
-        return LuticateSettingsBusiness::getEffectiveSetting($_user->getId(), $setting_name);
36
-    }
37
-
38
-    /**
39
-     * Get all the effective setting for a user
40
-     * @param $user_id int The user id
41
-     * @return LuticateSettingsDbo[]
42
-     */
43
-    public function getAllEffectiveSetting($user_id)
44
-    {
45
-        return LuticateSettingsBusiness::getAllEffectiveSetting($user_id);
46
-    }
47
-
48
-    /**
49
-     * Get all the effective setting for the logged user
50
-     * @param $_user LuticateUsersDbo Logged user
51
-     * @return LuticateSettingsDbo[]
52
-     */
53
-    public function getAllEffectiveSettingMe($_user)
54
-    {
55
-        return LuticateSettingsBusiness::getAllEffectiveSetting($_user->getId());
56
-    }
57
-
58
-    /**
59
-     * Get a setting
60
-     * @param $setting_name string The setting name
61
-     * @return \Luticate\Utils\LuDbo
62
-     */
63
-    public function get($setting_name)
64
-    {
65
-        return LuticateSettingsBusiness::get($setting_name);
66
-    }
67
-
68
-    /**
69
-     * Get all settings
70
-     * @param int $page The page number, 0 based
71
-     * @param int $perPage The number of items per page
72
-     * @param string $query The filter query
73
-     * @return \Luticate\Utils\LuMultipleDbo
74
-     */
75
-    public function getAll($page = 0, $perPage = 2000000000, $query = "")
76
-    {
77
-        return LuticateSettingsBusiness::getAll($page, $perPage, $query);
78
-    }
79
-
80
-    /**
81
-     * Add a setting
82
-     * @param $setting LuticateSettingsDbo The setting
83
-     * @return bool
84
-     */
85
-    public function add(LuticateSettingsDbo $setting)
86
-    {
87
-        return LuticateSettingsBusiness::add($setting);
88
-    }
89
-
90
-    /**
91
-     * Remove a setting
92
-     * @param $setting_name string The setting name
93
-     * @return bool
94
-     */
95
-    public function del($setting_name)
96
-    {
97
-        return LuticateSettingsBusiness::del($setting_name);
98
-    }
99
-
100
-    /**
101
-     * Edit the default setting value
102
-     * @param $setting_name string The setting name
103
-     * @param $setting LuticateSettingsDbo The setting
104
-     * @return bool
105
-     */
106
-    public function edit($setting_name, LuticateSettingsDbo $setting)
107
-    {
108
-        return LuticateSettingsBusiness::edit($setting_name, $setting);
109
-    }
110
-}

+ 0
- 69
src/Auth/Controller/LuticateSettingsUsersController.php View File

@@ -1,69 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Controller;
4
-
5
-use Luticate\Auth\DBO\LuticateUsersDbo;
6
-use Luticate\Utils\LuController;
7
-use Luticate\Auth\Business\LuticateSettingsUsersBusiness;
8
-use Luticate\Auth\DBO\LuticateSettingsUsersDbo;
9
-
10
-class LuticateSettingsUsersController extends LuController {
11
-    protected function getBusiness()
12
-    {
13
-        return new LuticateSettingsUsersBusiness();
14
-    }
15
-
16
-    /**
17
-     * Get all settings for a user
18
-     * @param $user_id int The user id
19
-     * @param int $page The page number, 0 based
20
-     * @param int $perPage The number of items per page
21
-     * @return \Luticate\Utils\LuMultipleDbo
22
-     */
23
-    public function getAllByUser($user_id, $page = 0, $perPage = 2000000000)
24
-    {
25
-        return LuticateSettingsUsersBusiness::getAllByUser($user_id, $page, $perPage);
26
-    }
27
-
28
-    /**
29
-     * Get a setting for a user
30
-     * @param $user_id int The user id
31
-     * @param $setting_name string The setting name
32
-     * @return \Luticate\Utils\LuDbo
33
-     */
34
-    public function get($user_id, $setting_name)
35
-    {
36
-        return LuticateSettingsUsersBusiness::checkSettingUserName($user_id, $setting_name);
37
-    }
38
-
39
-    /**
40
-     * Edit a setting for a user
41
-     * @param $user_id int The user id
42
-     * @param $setting_name string The setting name
43
-     * @param $setting LuticateSettingsUsersDbo The setting
44
-     * @return bool
45
-     */
46
-    public function edit($user_id, $setting_name, LuticateSettingsUsersDbo $setting)
47
-    {
48
-        $setting->setUserId($user_id);
49
-        $setting->setName($setting_name);
50
-        return LuticateSettingsUsersBusiness::edit($setting, true);
51
-    }
52
-
53
-    /**
54
-     * Edit a setting for the logged user
55
-     * @param $_user LuticateUsersDbo The logged user
56
-     * @param $setting_name string The setting name
57
-     * @param $setting_value string The setting value
58
-     * @return bool
59
-     */
60
-    public function editMe($_user, $setting_name, $setting_value)
61
-    {
62
-        $setting = new LuticateSettingsUsersDbo();
63
-        $setting->setUserId($_user->getId());
64
-        $setting->setName($setting_name);
65
-        $setting->setIsBlocked(null);
66
-        $setting->setValue(json_decode($setting_value));
67
-        return LuticateSettingsUsersBusiness::edit($setting, false);
68
-    }
69
-}

+ 0
- 140
src/Auth/Controller/LuticateUsersController.php View File

@@ -1,140 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\Controller;
4
-
5
-use Luticate\Utils\LuController;
6
-use Luticate\Auth\Business\LuticateUsersBusiness;
7
-use Luticate\Auth\DBO\LuticateUsersDbo;
8
-
9
-class LuticateUsersController extends LuController {
10
-    protected function getBusiness()
11
-    {
12
-        return new LuticateUsersBusiness();
13
-    }
14
-
15
-    /**
16
-     * Login the user
17
-     * @param $username string The user username
18
-     * @param $password string The user password
19
-     * @return LuticateUsersDbo
20
-     */
21
-    public function login($username, $password)
22
-    {
23
-        return LuticateUsersBusiness::login($username, $password);
24
-    }
25
-
26
-    /**
27
-     * Logout the logged user
28
-     * @param $_user LuticateUsersDbo The logged user
29
-     * @return bool
30
-     */
31
-    public function logout($_user)
32
-    {
33
-        return LuticateUsersBusiness::logout($_user);
34
-    }
35
-
36
-    /**
37
-     * Get a user by its id
38
-     * @param $user_id int The user id
39
-     * @return \Luticate\Utils\LuDbo
40
-     */
41
-    public function getLightById($user_id)
42
-    {
43
-        return LuticateUsersBusiness::getLightById($user_id);
44
-    }
45
-
46
-    /**
47
-     * Get the logged user
48
-     * @param $_user LuticateUsersDbo The logged user
49
-     * @return \Luticate\Utils\LuDbo
50
-     */
51
-    public function getLightMe($_user)
52
-    {
53
-        return LuticateUsersBusiness::getLightById($_user->getId());
54
-    }
55
-
56
-    /**
57
-     * Get all users
58
-     * @param int $page The page number, 0 based
59
-     * @param int $perPage The number of items per page
60
-     * @param string $query The filter query
61
-     * @return array
62
-     */
63
-    public function getAllLight($page = 0, $perPage = 2000000000, $query = "")
64
-    {
65
-        return LuticateUsersBusiness::getAllLight($page, $perPage, $query);
66
-    }
67
-
68
-    /**
69
-     * Add a user
70
-     * @param $username string The new user username
71
-     * @param $email string The new user email
72
-     * @param $firstname string The user firstname
73
-     * @param $lastname string The user lastname
74
-     * @param $password string The new user plain text password
75
-     * @return int
76
-     */
77
-    public function add($username, $email, $firstname, $lastname, $password)
78
-    {
79
-        return LuticateUsersBusiness::add($username, $email, $firstname, $lastname, $password);
80
-    }
81
-
82
-    /**
83
-     * Delete a user by its id
84
-     * @param $user_id int The user id
85
-     * @return bool
86
-     */
87
-    public function del($user_id)
88
-    {
89
-        return LuticateUsersBusiness::deleteById($user_id);
90
-    }
91
-
92
-    /**
93
-     * Edit the user details
94
-     * @param $email string The new user amil
95
-     * @param $user_id int The user id
96
-     * @param $firstname string The user firstname
97
-     * @param $lastname string The user lastname
98
-     * @return bool
99
-     */
100
-    public function edit($email, $firstname, $lastname, $user_id)
101
-    {
102
-        return LuticateUsersBusiness::edit($user_id, $firstname, $lastname, $email);
103
-    }
104
-
105
-    /**
106
-     * Edit the logged user email
107
-     * @param $email string The new user email
108
-     * @param $firstname string The user firstname
109
-     * @param $lastname string The user lastname
110
-     * @param $_user LuticateUsersDbo The logged user
111
-     * @return bool
112
-     */
113
-    public function editMe($email, $firstname, $lastname, $_user)
114
-    {
115
-        return LuticateUsersBusiness::edit($_user->getId(), $firstname, $lastname, $email);
116
-    }
117
-
118
-    /**
119
-     * Edit the password for a user
120
-     * @param $password string The new plain text password
121
-     * @param $user_id int The user id
122
-     * @return bool
123
-     */
124
-    public function setPassword($password, $user_id)
125
-    {
126
-        return LuticateUsersBusiness::setPassword($user_id, $password);
127
-    }
128
-
129
-    /**
130
-     * Edit the password for the logged user
131
-     * @param $password string The new plain text password
132
-     * @param $oldPassword string The old plain text password
133
-     * @param $_user LuticateUsersDbo The logged user
134
-     * @return bool
135
-     */
136
-    public function setPasswordMe($password, $oldPassword, $_user)
137
-    {
138
-        return LuticateUsersBusiness::setPasswordMe($password, $oldPassword, $_user);
139
-    }
140
-}

+ 0
- 67
src/Auth/DBO/LuticateGroupsDbo.php View File

@@ -1,67 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticateGroupsDbo extends LuDbo {
13
-
14
-    public function jsonSerialize()
15
-    {
16
-        return array(
17
-            "Id" => $this->_id,
18
-            "Name" => $this->_name
19
-        );
20
-    }
21
-
22
-    public static function jsonDeserialize($json)
23
-    {
24
-        $dbo = new LuticateGroupsDbo();
25
-        if (isset($json["Id"])) {
26
-            $dbo->setId($json["Id"]);
27
-        }
28
-        if (isset($json["Name"])) {
29
-            $dbo->setName($json["Name"]);
30
-        }
31
-        return $dbo;
32
-    }
33
-
34
-    public static function generateSample()
35
-    {
36
-        $dbo = new LuticateGroupsDbo();
37
-        $dbo->setId(42);
38
-        $dbo->setName("sample string");
39
-        return $dbo;
40
-    }
41
-
42
-    /**
43
-     * @var integer
44
-     */
45
-    protected $_id;
46
-    public function getId()
47
-    {
48
-        return $this->_id;
49
-    }
50
-    public function setId($value)
51
-    {
52
-        $this->_id = $value;
53
-    }
54
-
55
-    /**
56
-     * @var string
57
-     */
58
-    protected $_name;
59
-    public function getName()
60
-    {
61
-        return $this->_name;
62
-    }
63
-    public function setName($value)
64
-    {
65
-        $this->_name = $value;
66
-    }
67
-}

+ 0
- 50
src/Auth/DBO/LuticateGroupsDboArray.php View File

@@ -1,50 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticateGroupsDboArray extends LuDbo {
13
-
14
-    /**
15
-    * @var LuticateGroupsDbo[]
16
-    */
17
-    protected $_array;
18
-    public function getArray()
19
-    {
20
-        return $this->_array;
21
-    }
22
-    public function setArray($value)
23
-    {
24
-        $this->_array = $value;
25
-    }
26
-
27
-    public function jsonSerialize()
28
-    {
29
-        return $this->_array;
30
-    }
31
-
32
-    public static function jsonDeserialize($json)
33
-    {
34
-        $dbo = new LuticateGroupsDboArray();
35
-        $array = [];
36
-        foreach ($json as $data) {
37
-            $array[] = LuticateGroupsDbo::jsonDeserialize($data);
38
-        }
39
-        $dbo->setArray($array);
40
-        return $dbo;
41
-    }
42
-
43
-    public static function generateSample()
44
-    {
45
-        return [
46
-            LuticateGroupsDbo::generateSample(),
47
-            LuticateGroupsDbo::generateSample()
48
-        ];
49
-    }
50
-}

+ 0
- 51
src/Auth/DBO/LuticatePermissions.php View File

@@ -1,51 +0,0 @@
1
-<?php
2
-/**
3
- * Created by PhpStorm.
4
- * User: robin
5
- * Date: 9/30/15
6
- * Time: 11:09 PM
7
- */
8
-
9
-namespace Luticate\Auth\DBO;
10
-
11
-class LuticatePermissions
12
-{
13
-    const USER_LOGIN = "LU_USER_LOGIN";
14
-    const USER_ADD = "LU_USER_ADD";
15
-    const USER_GET = "LU_USER_GET";
16
-    const USER_EDIT = "LU_USER_EDIT";
17
-    const USER_EDIT_ME = "LU_USER_EDIT_ME";
18
-    const USER_DEL = "LU_USER_DEL";
19
-    const USER_SET_PASSWORD = "LU_USER_SET_PASSWORD";
20
-    const USER_SET_PASSWORD_ME = "LU_USER_SET_PASSWORD_ME";
21
-
22
-    const GROUP_ADD = "LU_GROUP_ADD";
23
-    const GROUP_GET = "LU_GROUP_GET";
24
-    const GROUP_EDIT = "LU_GROUP_EDIT";
25
-    const GROUP_DEL = "LU_GROUP_DEL";
26
-    const GROUP_USER_ADD = "LU_GROUP_USER_ADD";
27
-    const GROUP_USER_DEL = "LU_GROUP_USER_DEL";
28
-
29
-    const PERM_EFFECTIVE_GET = "LU_PERM_EFFECTIVE_GET";
30
-    const PERM_GET = "LU_PERM_GET";
31
-    const PERM_ADD = "LU_PERM_ADD";
32
-    const PERM_EDIT = "LU_PERM_EDIT";
33
-    const PERM_DEL = "LU_PERM_DEL";
34
-    const PERM_GROUP_GET = "LU_PERM_GROUP_GET";
35
-    const PERM_GROUP_ADD = "LU_PERM_GROUP_ADD";
36
-    const PERM_GROUP_EDIT = "LU_PERM_GROUP_EDIT";
37
-    const PERM_GROUP_DEL = "LU_PERM_GROUP_DEL";
38
-    const PERM_USER_GET = "LU_PERM_USER_GET";
39
-    const PERM_USER_ADD = "LU_PERM_USER_ADD";
40
-    const PERM_USER_EDIT = "LU_PERM_USER_EDIT";
41
-    const PERM_USER_DEL = "LU_PERM_USER_DEL";
42
-
43
-    const SETTING_EFFECTIVE_GET = "LU_SETTING_EFFECTIVE_GET";
44
-    const SETTING_GET = "LU_SETTING_GET";
45
-    const SETTING_ADD = "LU_SETTING_ADD";
46
-    const SETTING_EDIT = "LU_SETTING_EDIT";
47
-    const SETTING_DEL = "LU_SETTING_DEL";
48
-    const SETTING_USER_GET = "LU_SETTING_USER_GET";
49
-    const SETTING_USER_EDIT = "LU_SETTING_USER_EDIT";
50
-    const SETTING_EDIT_ME = "LU_SETTING_EDIT_ME";
51
-}

+ 0
- 67
src/Auth/DBO/LuticatePermissionsDbo.php View File

@@ -1,67 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticatePermissionsDbo extends LuDbo {
13
-
14
-    public function jsonSerialize()
15
-    {
16
-        return array(
17
-            "Name" => $this->_name,
18
-            "Value" => $this->_value
19
-        );
20
-    }
21
-
22
-    public static function jsonDeserialize($json)
23
-    {
24
-        $dbo = new LuticatePermissionsDbo();
25
-        if (isset($json["Name"])) {
26
-            $dbo->setName($json["Name"]);
27
-        }
28
-        if (isset($json["Value"])) {
29
-            $dbo->setValue($json["Value"]);
30
-        }
31
-        return $dbo;
32
-    }
33
-
34
-    public static function generateSample()
35
-    {
36
-        $dbo = new LuticatePermissionsDbo();
37
-        $dbo->setName("sample string");
38
-        $dbo->setValue(true);
39
-        return $dbo;
40
-    }
41
-
42
-    /**
43
-     * @var string
44
-     */
45
-    protected $_name;
46
-    public function getName()
47
-    {
48
-        return $this->_name;
49
-    }
50
-    public function setName($value)
51
-    {
52
-        $this->_name = $value;
53
-    }
54
-
55
-    /**
56
-     * @var boolean
57
-     */
58
-    protected $_value;
59
-    public function getValue()
60
-    {
61
-        return $this->_value;
62
-    }
63
-    public function setValue($value)
64
-    {
65
-        $this->_value = $value;
66
-    }
67
-}

+ 0
- 50
src/Auth/DBO/LuticatePermissionsDboArray.php View File

@@ -1,50 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticatePermissionsDboArray extends LuDbo {
13
-
14
-    /**
15
-    * @var LuticatePermissionsDbo[]
16
-    */
17
-    protected $_array;
18
-    public function getArray()
19
-    {
20
-        return $this->_array;
21
-    }
22
-    public function setArray($value)
23
-    {
24
-        $this->_array = $value;
25
-    }
26
-
27
-    public function jsonSerialize()
28
-    {
29
-        return $this->_array;
30
-    }
31
-
32
-    public static function jsonDeserialize($json)
33
-    {
34
-        $dbo = new LuticatePermissionsDboArray();
35
-        $array = [];
36
-        foreach ($json as $data) {
37
-            $array[] = LuticatePermissionsDbo::jsonDeserialize($data);
38
-        }
39
-        $dbo->setArray($array);
40
-        return $dbo;
41
-    }
42
-
43
-    public static function generateSample()
44
-    {
45
-        return [
46
-            LuticatePermissionsDbo::generateSample(),
47
-            LuticatePermissionsDbo::generateSample()
48
-        ];
49
-    }
50
-}

+ 0
- 85
src/Auth/DBO/LuticatePermissionsGroupsDbo.php View File

@@ -1,85 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticatePermissionsGroupsDbo extends LuDbo {
13
-
14
-    public function jsonSerialize()
15
-    {
16
-        return array(
17
-            "Name" => $this->_name,
18
-            "Value" => $this->_value,
19
-            "GroupId" => $this->_groupId
20
-        );
21
-    }
22
-
23
-    public static function jsonDeserialize($json)
24
-    {
25
-        $dbo = new LuticatePermissionsGroupsDbo();
26
-        if (isset($json["Name"])) {
27
-            $dbo->setName($json["Name"]);
28
-        }
29
-        if (isset($json["Value"])) {
30
-            $dbo->setValue($json["Value"]);
31
-        }
32
-        if (isset($json["GroupId"])) {
33
-            $dbo->setGroupId($json["GroupId"]);
34
-        }
35
-        return $dbo;
36
-    }
37
-
38
-    public static function generateSample()
39
-    {
40
-        $dbo = new LuticatePermissionsGroupsDbo();
41
-        $dbo->setName("sample string");
42
-        $dbo->setValue(true);
43
-        $dbo->setGroupId(42);
44
-        return $dbo;
45
-    }
46
-
47
-    /**
48
-     * @var string
49
-     */
50
-    protected $_name;
51
-    public function getName()
52
-    {
53
-        return $this->_name;
54
-    }
55
-    public function setName($value)
56
-    {
57
-        $this->_name = $value;
58
-    }
59
-
60
-    /**
61
-     * @var boolean
62
-     */
63
-    protected $_value;
64
-    public function getValue()
65
-    {
66
-        return $this->_value;
67
-    }
68
-    public function setValue($value)
69
-    {
70
-        $this->_value = $value;
71
-    }
72
-
73
-    /**
74
-     * @var integer
75
-     */
76
-    protected $_groupId;
77
-    public function getGroupId()
78
-    {
79
-        return $this->_groupId;
80
-    }
81
-    public function setGroupId($value)
82
-    {
83
-        $this->_groupId = $value;
84
-    }
85
-}

+ 0
- 50
src/Auth/DBO/LuticatePermissionsGroupsDboArray.php View File

@@ -1,50 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticatePermissionsGroupsDboArray extends LuDbo {
13
-
14
-    /**
15
-    * @var LuticatePermissionsGroupsDbo[]
16
-    */
17
-    protected $_array;
18
-    public function getArray()
19
-    {
20
-        return $this->_array;
21
-    }
22
-    public function setArray($value)
23
-    {
24
-        $this->_array = $value;
25
-    }
26
-
27
-    public function jsonSerialize()
28
-    {
29
-        return $this->_array;
30
-    }
31
-
32
-    public static function jsonDeserialize($json)
33
-    {
34
-        $dbo = new LuticatePermissionsGroupsDboArray();
35
-        $array = [];
36
-        foreach ($json as $data) {
37
-            $array[] = LuticatePermissionsGroupsDbo::jsonDeserialize($data);
38
-        }
39
-        $dbo->setArray($array);
40
-        return $dbo;
41
-    }
42
-
43
-    public static function generateSample()
44
-    {
45
-        return [
46
-            LuticatePermissionsGroupsDbo::generateSample(),
47
-            LuticatePermissionsGroupsDbo::generateSample()
48
-        ];
49
-    }
50
-}

+ 0
- 85
src/Auth/DBO/LuticatePermissionsUsersDbo.php View File

@@ -1,85 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticatePermissionsUsersDbo extends LuDbo {
13
-
14
-    public function jsonSerialize()
15
-    {
16
-        return array(
17
-            "Name" => $this->_name,
18
-            "Value" => $this->_value,
19
-            "UserId" => $this->_userId
20
-        );
21
-    }
22
-
23
-    public static function jsonDeserialize($json)
24
-    {
25
-        $dbo = new LuticatePermissionsUsersDbo();
26
-        if (isset($json["Name"])) {
27
-            $dbo->setName($json["Name"]);
28
-        }
29
-        if (isset($json["Value"])) {
30
-            $dbo->setValue($json["Value"]);
31
-        }
32
-        if (isset($json["UserId"])) {
33
-            $dbo->setUserId($json["UserId"]);
34
-        }
35
-        return $dbo;
36
-    }
37
-
38
-    public static function generateSample()
39
-    {
40
-        $dbo = new LuticatePermissionsUsersDbo();
41
-        $dbo->setName("sample string");
42
-        $dbo->setValue(true);
43
-        $dbo->setUserId(42);
44
-        return $dbo;
45
-    }
46
-
47
-    /**
48
-     * @var string
49
-     */
50
-    protected $_name;
51
-    public function getName()
52
-    {
53
-        return $this->_name;
54
-    }
55
-    public function setName($value)
56
-    {
57
-        $this->_name = $value;
58
-    }
59
-
60
-    /**
61
-     * @var boolean
62
-     */
63
-    protected $_value;
64
-    public function getValue()
65
-    {
66
-        return $this->_value;
67
-    }
68
-    public function setValue($value)
69
-    {
70
-        $this->_value = $value;
71
-    }
72
-
73
-    /**
74
-     * @var integer
75
-     */
76
-    protected $_userId;
77
-    public function getUserId()
78
-    {
79
-        return $this->_userId;
80
-    }
81
-    public function setUserId($value)
82
-    {
83
-        $this->_userId = $value;
84
-    }
85
-}

+ 0
- 50
src/Auth/DBO/LuticatePermissionsUsersDboArray.php View File

@@ -1,50 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticatePermissionsUsersDboArray extends LuDbo {
13
-
14
-    /**
15
-    * @var LuticatePermissionsUsersDbo[]
16
-    */
17
-    protected $_array;
18
-    public function getArray()
19
-    {
20
-        return $this->_array;
21
-    }
22
-    public function setArray($value)
23
-    {
24
-        $this->_array = $value;
25
-    }
26
-
27
-    public function jsonSerialize()
28
-    {
29
-        return $this->_array;
30
-    }
31
-
32
-    public static function jsonDeserialize($json)
33
-    {
34
-        $dbo = new LuticatePermissionsUsersDboArray();
35
-        $array = [];
36
-        foreach ($json as $data) {
37
-            $array[] = LuticatePermissionsUsersDbo::jsonDeserialize($data);
38
-        }
39
-        $dbo->setArray($array);
40
-        return $dbo;
41
-    }
42
-
43
-    public static function generateSample()
44
-    {
45
-        return [
46
-            LuticatePermissionsUsersDbo::generateSample(),
47
-            LuticatePermissionsUsersDbo::generateSample()
48
-        ];
49
-    }
50
-}

+ 0
- 121
src/Auth/DBO/LuticateSettingsDbo.php View File

@@ -1,121 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticateSettingsDbo extends LuDbo {
13
-
14
-    public function jsonSerialize()
15
-    {
16
-        return array(
17
-            "Name" => $this->_name,
18
-            "Type" => $this->_type,
19
-            "Value" => $this->_value,
20
-            "IsBlocked" => $this->_isBlocked,
21
-            "IsAdmin" => $this->_isAdmin
22
-        );
23
-    }
24
-
25
-    public static function jsonDeserialize($json)
26
-    {
27
-        $dbo = new LuticateSettingsDbo();
28
-        if (isset($json["Name"])) {
29
-            $dbo->setName($json["Name"]);
30
-        }
31
-        if (isset($json["Type"])) {
32
-            $dbo->setType($json["Type"]);
33
-        }
34
-        if (isset($json["Value"])) {
35
-            $dbo->setValue($json["Value"]);
36
-        }
37
-        if (isset($json["IsBlocked"])) {
38
-            $dbo->setIsBlocked($json["IsBlocked"]);
39
-        }
40
-        if (isset($json["IsAdmin"])) {
41
-            $dbo->setIsAdmin($json["IsAdmin"]);
42
-        }
43
-        return $dbo;
44
-    }
45
-
46
-    public static function generateSample()
47
-    {
48
-        $dbo = new LuticateSettingsDbo();
49
-        $dbo->setName("sample string");
50
-        $dbo->setType("sample string");
51
-        $dbo->setValue("sample string");
52
-        $dbo->setIsBlocked(true);
53
-        $dbo->setIsAdmin(true);
54
-        return $dbo;
55
-    }
56
-
57
-    /**
58
-     * @var string
59
-     */
60
-    protected $_name;
61
-    public function getName()
62
-    {
63
-        return $this->_name;
64
-    }
65
-    public function setName($value)
66
-    {
67
-        $this->_name = $value;
68
-    }
69
-
70
-    /**
71
-     * @var string
72
-     */
73
-    protected $_type;
74
-    public function getType()
75
-    {
76
-        return $this->_type;
77
-    }
78
-    public function setType($value)
79
-    {
80
-        $this->_type = $value;
81
-    }
82
-
83
-    /**
84
-     * @var text
85
-     */
86
-    protected $_value;
87
-    public function getValue()
88
-    {
89
-        return $this->_value;
90
-    }
91
-    public function setValue($value)
92
-    {
93
-        $this->_value = $value;
94
-    }
95
-
96
-    /**
97
-     * @var boolean
98
-     */
99
-    protected $_isBlocked;
100
-    public function getIsBlocked()
101
-    {
102
-        return $this->_isBlocked;
103
-    }
104
-    public function setIsBlocked($value)
105
-    {
106
-        $this->_isBlocked = $value;
107
-    }
108
-
109
-    /**
110
-     * @var boolean
111
-     */
112
-    protected $_isAdmin;
113
-    public function getIsAdmin()
114
-    {
115
-        return $this->_isAdmin;
116
-    }
117
-    public function setIsAdmin($value)
118
-    {
119
-        $this->_isAdmin = $value;
120
-    }
121
-}

+ 0
- 50
src/Auth/DBO/LuticateSettingsDboArray.php View File

@@ -1,50 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticateSettingsDboArray extends LuDbo {
13
-
14
-    /**
15
-    * @var LuticateSettingsDbo[]
16
-    */
17
-    protected $_array;
18
-    public function getArray()
19
-    {
20
-        return $this->_array;
21
-    }
22
-    public function setArray($value)
23
-    {
24
-        $this->_array = $value;
25
-    }
26
-
27
-    public function jsonSerialize()
28
-    {
29
-        return $this->_array;
30
-    }
31
-
32
-    public static function jsonDeserialize($json)
33
-    {
34
-        $dbo = new LuticateSettingsDboArray();
35
-        $array = [];
36
-        foreach ($json as $data) {
37
-            $array[] = LuticateSettingsDbo::jsonDeserialize($data);
38
-        }
39
-        $dbo->setArray($array);
40
-        return $dbo;
41
-    }
42
-
43
-    public static function generateSample()
44
-    {
45
-        return [
46
-            LuticateSettingsDbo::generateSample(),
47
-            LuticateSettingsDbo::generateSample()
48
-        ];
49
-    }
50
-}

+ 0
- 103
src/Auth/DBO/LuticateSettingsUsersDbo.php View File

@@ -1,103 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticateSettingsUsersDbo extends LuDbo {
13
-
14
-    public function jsonSerialize()
15
-    {
16
-        return array(
17
-            "Name" => $this->_name,
18
-            "Value" => $this->_value,
19
-            "UserId" => $this->_userId,
20
-            "IsBlocked" => $this->_isBlocked
21
-        );
22
-    }
23
-
24
-    public static function jsonDeserialize($json)
25
-    {
26
-        $dbo = new LuticateSettingsUsersDbo();
27
-        if (isset($json["Name"])) {
28
-            $dbo->setName($json["Name"]);
29
-        }
30
-        if (isset($json["Value"])) {
31
-            $dbo->setValue($json["Value"]);
32
-        }
33
-        if (isset($json["UserId"])) {
34
-            $dbo->setUserId($json["UserId"]);
35
-        }
36
-        if (isset($json["IsBlocked"])) {
37
-            $dbo->setIsBlocked($json["IsBlocked"]);
38
-        }
39
-        return $dbo;
40
-    }
41
-
42
-    public static function generateSample()
43
-    {
44
-        $dbo = new LuticateSettingsUsersDbo();
45
-        $dbo->setName("sample string");
46
-        $dbo->setValue("sample string");
47
-        $dbo->setUserId(42);
48
-        $dbo->setIsBlocked(true);
49
-        return $dbo;
50
-    }
51
-
52
-    /**
53
-     * @var string
54
-     */
55
-    protected $_name;
56
-    public function getName()
57
-    {
58
-        return $this->_name;
59
-    }
60
-    public function setName($value)
61
-    {
62
-        $this->_name = $value;
63
-    }
64
-
65
-    /**
66
-     * @var text
67
-     */
68
-    protected $_value;
69
-    public function getValue()
70
-    {
71
-        return $this->_value;
72
-    }
73
-    public function setValue($value)
74
-    {
75
-        $this->_value = $value;
76
-    }
77
-
78
-    /**
79
-     * @var integer
80
-     */
81
-    protected $_userId;
82
-    public function getUserId()
83
-    {
84
-        return $this->_userId;
85
-    }
86
-    public function setUserId($value)
87
-    {
88
-        $this->_userId = $value;
89
-    }
90
-
91
-    /**
92
-     * @var boolean
93
-     */
94
-    protected $_isBlocked;
95
-    public function getIsBlocked()
96
-    {
97
-        return $this->_isBlocked;
98
-    }
99
-    public function setIsBlocked($value)
100
-    {
101
-        $this->_isBlocked = $value;
102
-    }
103
-}

+ 0
- 50
src/Auth/DBO/LuticateSettingsUsersDboArray.php View File

@@ -1,50 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticateSettingsUsersDboArray extends LuDbo {
13
-
14
-    /**
15
-    * @var LuticateSettingsUsersDbo[]
16
-    */
17
-    protected $_array;
18
-    public function getArray()
19
-    {
20
-        return $this->_array;
21
-    }
22
-    public function setArray($value)
23
-    {
24
-        $this->_array = $value;
25
-    }
26
-
27
-    public function jsonSerialize()
28
-    {
29
-        return $this->_array;
30
-    }
31
-
32
-    public static function jsonDeserialize($json)
33
-    {
34
-        $dbo = new LuticateSettingsUsersDboArray();
35
-        $array = [];
36
-        foreach ($json as $data) {
37
-            $array[] = LuticateSettingsUsersDbo::jsonDeserialize($data);
38
-        }
39
-        $dbo->setArray($array);
40
-        return $dbo;
41
-    }
42
-
43
-    public static function generateSample()
44
-    {
45
-        return [
46
-            LuticateSettingsUsersDbo::generateSample(),
47
-            LuticateSettingsUsersDbo::generateSample()
48
-        ];
49
-    }
50
-}

+ 0
- 175
src/Auth/DBO/LuticateUsersDbo.php View File

@@ -1,175 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticateUsersDbo extends LuDbo {
13
-
14
-    public function jsonSerialize()
15
-    {
16
-        return array(
17
-            "Id" => $this->_id,
18
-            "Username" => $this->_username,
19
-            "Email" => $this->_email,
20
-            "Password" => $this->_password,
21
-            "Salt" => $this->_salt,
22
-            "ProfileId" => $this->_profileId,
23
-            "Firstname" => $this->_firstname,
24
-            "Lastname" => $this->_lastname
25
-        );
26
-    }
27
-
28
-    public static function jsonDeserialize($json)
29
-    {
30
-        $dbo = new LuticateUsersDbo();
31
-        if (isset($json["Id"])) {
32
-            $dbo->setId($json["Id"]);
33
-        }
34
-        if (isset($json["Username"])) {
35
-            $dbo->setUsername($json["Username"]);
36
-        }
37
-        if (isset($json["Email"])) {
38
-            $dbo->setEmail($json["Email"]);
39
-        }
40
-        if (isset($json["Password"])) {
41
-            $dbo->setPassword($json["Password"]);
42
-        }
43
-        if (isset($json["Salt"])) {
44
-            $dbo->setSalt($json["Salt"]);
45
-        }
46
-        if (isset($json["ProfileId"])) {
47
-            $dbo->setProfileId($json["ProfileId"]);
48
-        }
49
-        if (isset($json["Firstname"])) {
50
-            $dbo->setFirstname($json["Firstname"]);
51
-        }
52
-        if (isset($json["Lastname"])) {
53
-            $dbo->setLastname($json["Lastname"]);
54
-        }
55
-        return $dbo;
56
-    }
57
-
58
-    public static function generateSample()
59
-    {
60
-        $dbo = new LuticateUsersDbo();
61
-        $dbo->setId(42);
62
-        $dbo->setUsername("sample string");
63
-        $dbo->setEmail("sample string");
64
-        $dbo->setPassword("sample string");
65
-        $dbo->setSalt("sample string");
66
-        $dbo->setProfileId(42);
67
-        $dbo->setFirstname("sample string");
68
-        $dbo->setLastname("sample string");
69
-        return $dbo;
70
-    }
71
-
72
-    /**
73
-     * @var integer
74
-     */
75
-    protected $_id;
76
-    public function getId()
77
-    {
78
-        return $this->_id;
79
-    }
80
-    public function setId($value)
81
-    {
82
-        $this->_id = $value;
83
-    }
84
-
85
-    /**
86
-     * @var string
87
-     */
88
-    protected $_username;
89
-    public function getUsername()
90
-    {
91
-        return $this->_username;
92
-    }
93
-    public function setUsername($value)
94
-    {
95
-        $this->_username = $value;
96
-    }
97
-
98
-    /**
99
-     * @var string
100
-     */
101
-    protected $_email;
102
-    public function getEmail()
103
-    {
104
-        return $this->_email;
105
-    }
106
-    public function setEmail($value)
107
-    {
108
-        $this->_email = $value;
109
-    }
110
-
111
-    /**
112
-     * @var string
113
-     */
114
-    protected $_password;
115
-    public function getPassword()
116
-    {
117
-        return $this->_password;
118
-    }
119
-    public function setPassword($value)
120
-    {
121
-        $this->_password = $value;
122
-    }
123
-
124
-    /**
125
-     * @var string
126
-     */
127
-    protected $_salt;
128
-    public function getSalt()
129
-    {
130
-        return $this->_salt;
131
-    }
132
-    public function setSalt($value)
133
-    {
134
-        $this->_salt = $value;
135
-    }
136
-
137
-    /**
138
-     * @var integer
139
-     */
140
-    protected $_profileId;
141
-    public function getProfileId()
142
-    {
143
-        return $this->_profileId;
144
-    }
145
-    public function setProfileId($value)
146
-    {
147
-        $this->_profileId = $value;
148
-    }
149
-
150
-    /**
151
-     * @var string
152
-     */
153
-    protected $_firstname;
154
-    public function getFirstname()
155
-    {
156
-        return $this->_firstname;
157
-    }
158
-    public function setFirstname($value)
159
-    {
160
-        $this->_firstname = $value;
161
-    }
162
-
163
-    /**
164
-     * @var string
165
-     */
166
-    protected $_lastname;
167
-    public function getLastname()
168
-    {
169
-        return $this->_lastname;
170
-    }
171
-    public function setLastname($value)
172
-    {
173
-        $this->_lastname = $value;
174
-    }
175
-}

+ 0
- 50
src/Auth/DBO/LuticateUsersDboArray.php View File

@@ -1,50 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DBO;
9
-
10
-use Luticate\Utils\LuDbo;
11
-
12
-class LuticateUsersDboArray extends LuDbo {
13
-
14
-    /**
15
-    * @var LuticateUsersDbo[]
16
-    */
17
-    protected $_array;
18
-    public function getArray()
19
-    {
20
-        return $this->_array;
21
-    }
22
-    public function setArray($value)
23
-    {
24
-        $this->_array = $value;
25
-    }
26
-
27
-    public function jsonSerialize()
28
-    {
29
-        return $this->_array;
30
-    }
31
-
32
-    public static function jsonDeserialize($json)
33
-    {
34
-        $dbo = new LuticateUsersDboArray();
35
-        $array = [];
36
-        foreach ($json as $data) {
37
-            $array[] = LuticateUsersDbo::jsonDeserialize($data);
38
-        }
39
-        $dbo->setArray($array);
40
-        return $dbo;
41
-    }
42
-
43
-    public static function generateSample()
44
-    {
45
-        return [
46
-            LuticateUsersDbo::generateSample(),
47
-            LuticateUsersDbo::generateSample()
48
-        ];
49
-    }
50
-}

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

@@ -1,32 +0,0 @@
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\LuticateUsersLightDbo');
21
-    }
22
-
23
-    public function jsonSerialize()
24
-    {
25
-        $array = parent::jsonSerialize();
26
-        unset($array["Password"]);
27
-        unset($array["Token"]);
28
-        unset($array["Salt"]);
29
-        return $array;
30
-    }
31
-
32
-}

+ 0
- 51
src/Auth/DBO/LuticateUsersLoginDbo.php View File

@@ -1,51 +0,0 @@
1
-<?php
2
-/**
3
- * Created by PhpStorm.
4
- * User: robin
5
- * Date: 9/30/15
6
- * Time: 8:46 PM
7
- */
8
-
9
-namespace Luticate\Auth\DBO;
10
-
11
-
12
-class LuticateUsersLoginDbo 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
-    /**
24
-     * @var string
25
-     */
26
-    protected $_token;
27
-    /**
28
-     * @return string
29
-     */
30
-    public function getToken()
31
-    {
32
-        return $this->_token;
33
-    }
34
-    /**
35
-     * @param string $token
36
-     */
37
-    public function setToken($token)
38
-    {
39
-        $this->_token = $token;
40
-    }
41
-
42
-    public function jsonSerialize()
43
-    {
44
-        $array = parent::jsonSerialize();
45
-        unset($array["Password"]);
46
-        unset($array["Salt"]);
47
-        $array["Token"] = $this->_token;
48
-        return $array;
49
-    }
50
-
51
-}

+ 10
- 0
src/Auth/DataAccess/LuPermissionsDataAccess.php View File

@@ -0,0 +1,10 @@
1
+<?php
2
+
3
+namespace Luticate\Auth\DataAccess;
4
+
5
+use Luticate\Utils\DataAccess\LuDataAccess;
6
+
7
+class LuPermissionsDataAccess extends LuDataAccess {
8
+    protected static $_connection = "luticatedb";
9
+    protected static $_table = "lu_permissions";
10
+}

+ 0
- 78
src/Auth/DataAccess/LuticateGroupsDataAccess.php View File

@@ -1,78 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess;
4
-
5
-use Luticate\Auth\DataAccess\Models\LuticateUsers;
6
-use Luticate\Auth\DBO\LuticateUsersLightDbo;
7
-use Luticate\Utils\LuDataAccess;
8
-use Luticate\Auth\DataAccess\Models\LuticateGroups;
9
-use Luticate\Auth\DBO\LuticateGroupsDbo;
10
-use Luticate\Utils\LuMultipleDbo;
11
-
12
-class LuticateGroupsDataAccess extends LuDataAccess {
13
-    protected static function getModel()
14
-    {
15
-        return new LuticateGroups();
16
-    }
17
-
18
-    protected static function getOrderBy()
19
-    {
20
-        return array(array("name", "ASC"));
21
-    }
22
-
23
-    protected static function getQueryPredicate($query)
24
-    {
25
-        return array(array("name", "ilike", "%" . $query . "%", "or"));
26
-    }
27
-
28
-    /**
29
-     * @param $group_name
30
-     * @return LuticateGroupsDbo|null
31
-     */
32
-    public static function getByName($group_name)
33
-    {
34
-        $group = LuticateGroups::where("name", "=", $group_name)->first();
35
-        if (is_null($group))
36
-            return null;
37
-        return $group->toDbo();
38
-    }
39
-
40
-    public static function getUsers($group_id, $page = 0, $perPage = 2000000000, $query = "")
41
-    {
42
-        $model = LuticateUsers::/*where("luticate_users.username", "ilike", "%" . $query . "%")
43
-            ->where("luticate_users.email", "ilike", "%" . $query . "%", "or")
44
-            ->where("luticate_users.firstname", "ilike", "%" . $query . "%", "or")
45
-            ->where("luticate_users.lastname", "ilike", "%" . $query . "%", "or")
46
-            ->*/where("luticate_users_groups.group_id", "=", $group_id, "and")
47
-            ->join("luticate_users_groups", "luticate_users.id", "=", "luticate_users_groups.user_id");
48
-
49
-        $count = $model->count();
50
-
51
-        $model = $model->orderBy("luticate_users.username", "ASC");
52
-        $data = $model->take($perPage)->offset($page * $perPage)->get();
53
-        $usersLight = [];
54
-        foreach ($data as $user) {
55
-            if (!is_null($user)) {
56
-                $usersLight[] = LuticateUsersLightDbo::fromUserDbo($user->toDbo());
57
-            }
58
-        }
59
-        return new LuMultipleDbo($count, $usersLight);
60
-    }
61
-
62
-    public static function addUser($user_id, $group_id)
63
-    {
64
-        LuticateGroups::find($group_id)->users()->attach($user_id);
65
-        return true;
66
-    }
67
-
68
-    public static function delUser($user_id, $group_id)
69
-    {
70
-        LuticateGroups::find($group_id)->users()->detach($user_id);
71
-        return true;
72
-    }
73
-
74
-    public static function hasUser($user_id, $group_id)
75
-    {
76
-        return !is_null(LuticateGroups::find($group_id)->users()->find($user_id));
77
-    }
78
-}

+ 0
- 67
src/Auth/DataAccess/LuticatePermissionsDataAccess.php View File

@@ -1,67 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess;
4
-
5
-use Luticate\Auth\DataAccess\SP\SpLuGetAllUserPermission;
6
-use Luticate\Auth\DataAccess\SP\SpLuGetUserPermission;
7
-use Luticate\Utils\LuDataAccess;
8
-use Luticate\Auth\DataAccess\Models\LuticatePermissions;
9
-use Luticate\Auth\DBO\LuticatePermissionsDbo;
10
-
11
-class LuticatePermissionsDataAccess extends LuDataAccess {
12
-    protected static function getModel()
13
-    {
14
-        return new LuticatePermissions();
15
-    }
16
-
17
-    protected static function getOrderBy()
18
-    {
19
-        return array(array("name", "ASC"));
20
-    }
21
-
22
-    protected static function getQueryPredicate($query)
23
-    {
24
-        return array(array("name", "ilike", "%" . $query . "%", "or"));
25
-    }
26
-
27
-    public static function getEffectivePermission($user_id, $permission_name)
28
-    {
29
-        return SpLuGetUserPermission::execute($user_id, $permission_name)->getVal();
30
-    }
31
-
32
-    public static function getAllEffectivePermission($user_id)
33
-    {
34
-        return SpLuGetAllUserPermission::execute($user_id);
35
-    }
36
-
37
-    public static function getModelByName($permission_name)
38
-    {
39
-        return LuticatePermissions::where("name", "=", $permission_name)->first();
40
-    }
41
-
42
-    public static function getByName($permission_name)
43
-    {
44
-        $perm = self::getModelByName($permission_name);
45
-        if (is_null($perm)) {
46
-            return null;
47
-        }
48
-        return $perm->toDbo();
49
-    }
50
-
51
-    public static function delete($permission_name)
52
-    {
53
-        $perm = self::getModelByName($permission_name);
54
-        if (is_null($perm))
55
-            return;
56
-        $perm->delete();
57
-    }
58
-
59
-    public static function edit($permission_name, $permission_value)
60
-    {
61
-        $perm = self::getModelByName($permission_name);
62
-        if (is_null($perm))
63
-            return;
64
-        $perm->value = $permission_value;
65
-        $perm->save();
66
-    }
67
-}

+ 0
- 39
src/Auth/DataAccess/LuticatePermissionsGroupsDataAccess.php View File

@@ -1,39 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess;
4
-
5
-use Luticate\Auth\DataAccess\Models\LuticateGroups;
6
-use Luticate\Utils\LuDataAccess;
7
-use Luticate\Auth\DataAccess\Models\LuticatePermissionsGroups;
8
-use Luticate\Auth\DBO\LuticatePermissionsGroupsDbo;
9
-
10
-class LuticatePermissionsGroupsDataAccess extends LuDataAccess {
11
-    protected static function getModel()
12
-    {
13
-        return new LuticatePermissionsGroups();
14
-    }
15
-
16
-    public static function getModelByName($group_id, $permission_name)
17
-    {
18
-        return LuticatePermissionsGroups::where("name", "=", $permission_name)->where("group_id", "=", $group_id)->first();
19
-    }
20
-
21
-    public static function getAllByGroup($group_id, $page = 0, $perPage = 2000000000)
22
-    {
23
-        return self::getMultiple(array(array('group_id', '=', $group_id)), array(array("name", "ASC")), $page, $perPage);
24
-    }
25
-
26
-    public static function getByName($group_id, $permission_name)
27
-    {
28
-        $perm = self::getModelByName($group_id, $permission_name);
29
-        if (is_null($perm)) {
30
-            return null;
31
-        }
32
-        return $perm->toDbo();
33
-    }
34
-
35
-    public static function delete($group_id, $permission_name)
36
-    {
37
-        LuticateGroups::find($group_id)->permissions()->detach($permission_name);
38
-    }
39
-}

+ 0
- 39
src/Auth/DataAccess/LuticatePermissionsUsersDataAccess.php View File

@@ -1,39 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess;
4
-
5
-use Luticate\Auth\DataAccess\Models\LuticateUsers;
6
-use Luticate\Utils\LuDataAccess;
7
-use Luticate\Auth\DataAccess\Models\LuticatePermissionsUsers;
8
-use Luticate\Auth\DBO\LuticatePermissionsUsersDbo;
9
-
10
-class LuticatePermissionsUsersDataAccess extends LuDataAccess {
11
-    protected static function getModel()
12
-    {
13
-        return new LuticatePermissionsUsers();
14
-    }
15
-
16
-    public static function getModelByName($user_id, $permission_name)
17
-    {
18
-        return LuticatePermissionsUsers::where("name", "=", $permission_name)->where("user_id", "=", $user_id)->first();
19
-    }
20
-
21
-    public static function getAllByUser($user_id, $page = 0, $perPage = 2000000000)
22
-    {
23
-        return self::getMultiple(array(array('user_id', '=', $user_id)), array(array("name", "ASC")), $page, $perPage);
24
-    }
25
-
26
-    public static function getByName($user_id, $permission_name)
27
-    {
28
-        $perm = self::getModelByName($user_id, $permission_name);
29
-        if (is_null($perm)) {
30
-            return null;
31
-        }
32
-        return $perm->toDbo();
33
-    }
34
-
35
-    public static function delete($user_id, $permission_name)
36
-    {
37
-        LuticateUsers::find($user_id)->permissions()->detach($permission_name);
38
-    }
39
-}

+ 0
- 77
src/Auth/DataAccess/LuticateSettingsDataAccess.php View File

@@ -1,77 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess;
4
-
5
-use Luticate\Auth\DataAccess\SP\SpLuGetAllUserSettings;
6
-use Luticate\Auth\DataAccess\SP\SpLuGetUserSetting;
7
-use Luticate\Utils\LuDataAccess;
8
-use Luticate\Auth\DataAccess\Models\LuticateSettings;
9
-use Luticate\Auth\DBO\LuticateSettingsDbo;
10
-
11
-class LuticateSettingsDataAccess extends LuDataAccess {
12
-    protected static function getModel()
13
-    {
14
-        return new LuticateSettings();
15
-    }
16
-
17
-    protected static function getOrderBy()
18
-    {
19
-        return array(array("name", "ASC"));
20
-    }
21
-
22
-    protected static function getQueryPredicate($query)
23
-    {
24
-        return array(array("name", "ilike", "%" . $query . "%", "or"));
25
-    }
26
-
27
-    public static function getEffectiveSetting($user_id, $setting_name)
28
-    {
29
-        return SpLuGetUserSetting::execute($user_id, $setting_name);
30
-    }
31
-
32
-    public static function getAllEffectiveSetting($user_id)
33
-    {
34
-        return SpLuGetAllUserSettings::getMultipleJson($user_id, 0, 2000000);
35
-    }
36
-
37
-    public static function getModelByName($setting_name)
38
-    {
39
-        return LuticateSettings::where("name", "=", $setting_name)->first();
40
-    }
41
-
42
-    /**
43
-     * @param $setting_name string
44
-     * @return LuticateSettingsDbo
45
-     */
46
-    public static function getByName($setting_name)
47
-    {
48
-        $perm = self::getModelByName($setting_name);
49
-        if (is_null($perm)) {
50
-            return null;
51
-        }
52
-        return $perm->toDbo();
53
-    }
54
-
55
-    public static function delete($setting_name)
56
-    {
57
-        $perm = self::getModelByName($setting_name);
58
-        if (is_null($perm))
59
-            return;
60
-        $perm->delete();
61
-    }
62
-
63
-    /**
64
-     * @param $setting_name string
65
-     * @param $setting LuticateSettingsDbo
66
-     */
67
-    public static function edit($setting_name, $setting)
68
-    {
69
-        $perm = self::getModelByName($setting_name);
70
-        if (is_null($perm))
71
-            return;
72
-        $perm->is_blocked = $setting->getIsBlocked();
73
-        $perm->is_admin = $setting->getIsAdmin();
74
-        $perm->value = $setting->getValue();
75
-        $perm->save();
76
-    }
77
-}

+ 0
- 57
src/Auth/DataAccess/LuticateSettingsUsersDataAccess.php View File

@@ -1,57 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess;
4
-
5
-use Luticate\Auth\DataAccess\Models\LuticateUsers;
6
-use Luticate\Utils\LuDataAccess;
7
-use Luticate\Auth\DataAccess\Models\LuticateSettingsUsers;
8
-use Luticate\Auth\DBO\LuticateSettingsUsersDbo;
9
-
10
-class LuticateSettingsUsersDataAccess extends LuDataAccess {
11
-    protected static function getModel()
12
-    {
13
-        return new LuticateSettingsUsers();
14
-    }
15
-
16
-    public static function getModelByName($user_id, $setting_name)
17
-    {
18
-        return LuticateSettingsUsers::where("name", "=", $setting_name)->where("user_id", "=", $user_id)->first();
19
-    }
20
-
21
-    public static function getAllByUser($user_id, $page = 0, $perPage = 2000000000)
22
-    {
23
-        return self::getMultiple(array(array('user_id', '=', $user_id)), array(array("name", "ASC")), $page, $perPage);
24
-    }
25
-
26
-    /**
27
-     * @param $user_id int
28
-     * @param $setting_name string
29
-     * @return LuticateSettingsUsersDbo
30
-     */
31
-    public static function getByName($user_id, $setting_name)
32
-    {
33
-        $setting = self::getModelByName($user_id, $setting_name);
34
-        if (is_null($setting)) {
35
-            return null;
36
-        }
37
-        return $setting->toDbo();
38
-    }
39
-
40
-    public static function delete($user_id, $setting_name)
41
-    {
42
-        LuticateUsers::find($user_id)->settings()->detach($setting_name);
43
-    }
44
-
45
-    /**
46
-     * @param $user_setting LuticateSettingsUsersDbo
47
-     */
48
-    public static function edit($user_setting)
49
-    {
50
-        $user_setting_model = self::getModelByName($user_setting->getUserId(), $user_setting->getName());
51
-        if (is_null($user_setting))
52
-            return;
53
-        $user_setting_model->value = $user_setting->getValue();
54
-        $user_setting_model->is_blocked = $user_setting->getIsBlocked();
55
-        $user_setting_model->save();
56
-    }
57
-}

+ 0
- 39
src/Auth/DataAccess/LuticateUsersDataAccess.php View File

@@ -1,39 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess;
4
-
5
-use Luticate\Utils\LuDataAccess;
6
-use Luticate\Auth\DataAccess\Models\LuticateUsers;
7
-use Luticate\Auth\DBO\LuticateUsersDbo;
8
-
9
-class LuticateUsersDataAccess extends LuDataAccess {
10
-    protected static function getModel()
11
-    {
12
-        return new LuticateUsers();
13
-    }
14
-
15
-    protected static function getOrderBy()
16
-    {
17
-        return array(array("username", "ASC"));
18
-    }
19
-
20
-    protected static function getQueryPredicate($query)
21
-    {
22
-        return array(array("username", "ilike", "%" . $query . "%", "or"),
23
-            array("firstname", "ilike", "%" . $query . "%", "or"),
24
-            array("lastname", "ilike", "%" . $query . "%", "or"),
25
-            array("email", "ilike", "%" . $query . "%", "or"));
26
-    }
27
-
28
-    /**
29
-     * @param $username string
30
-     * @return LuticateUsersDbo|null
31
-     */
32
-    public static function getByUsernameOrEmail($username)
33
-    {
34
-        $user = LuticateUsers::where("username", "=", $username)->orWhere("email", "=", $username)->first();
35
-        if (is_null($user))
36
-            return null;
37
-        return $user->toDbo();
38
-    }
39
-}

+ 0
- 18
src/Auth/DataAccess/Models/LuticateGroups.php View File

@@ -1,18 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess\Models;
4
-
5
-use Luticate\Auth\DBO\LuticateGroupsDbo;
6
-
7
-class LuticateGroups extends LuticateGroupsModel
8
-{
9
-    public function users()
10
-    {
11
-        return $this->belongsToMany('Luticate\Auth\DataAccess\Models\LuticateUsers', "luticate_users_groups", "group_id", "user_id");
12
-    }
13
-
14
-    public function permissions()
15
-    {
16
-        return $this->belongsToMany('Luticate\Auth\DataAccess\Models\LuticatePermissions', "luticate_permissions_groups", "group_id", "name");
17
-    }
18
-}

+ 0
- 49
src/Auth/DataAccess/Models/LuticateGroupsModel.php View File

@@ -1,49 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- * DO NOT DIRECTLY USE THIS FILE
7
- * USE LuticateGroups.php
8
- * TO MAKE YOUR CHANGES AND DATABASE ACCESS
9
-*/
10
-
11
-namespace Luticate\Auth\DataAccess\Models;
12
-
13
-use Luticate\Utils\LuModel;
14
-use Luticate\Auth\DBO\LuticateGroupsDbo;
15
-
16
-class LuticateGroupsModel extends LuModel
17
-{
18
-    function __construct()
19
-    {
20
-        parent::__construct();
21
-        $this->timestamps = false;
22
-    }
23
-
24
-    public function toDbo()
25
-    {
26
-        $dbo = new LuticateGroupsDbo();
27
-
28
-        $dbo->setId($this->id);
29
-        $dbo->setName($this->name);
30
-
31
-        return $dbo;
32
-    }
33
-
34
-    /**
35
-     * @param $dbo LuticateGroupsDbo
36
-     * @param $model LuModel|null
37
-     * @return LuticateGroups
38
-     */
39
-    public function fromDbo($dbo, $model = null)
40
-    {
41
-        if (is_null($model))
42
-            $model = new LuticateGroups();
43
-
44
-        $model->id = $dbo->getId();
45
-        $model->name = $dbo->getName();
46
-
47
-        return $model;
48
-    }
49
-}

+ 0
- 10
src/Auth/DataAccess/Models/LuticatePermissions.php View File

@@ -1,10 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess\Models;
4
-
5
-use Luticate\Auth\DBO\LuticatePermissionsDbo;
6
-
7
-class LuticatePermissions extends LuticatePermissionsModel
8
-{
9
-    protected $primaryKey = "name";
10
-}

+ 0
- 10
src/Auth/DataAccess/Models/LuticatePermissionsGroups.php View File

@@ -1,10 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess\Models;
4
-
5
-use Luticate\Auth\DBO\LuticatePermissionsGroupsDbo;
6
-
7
-class LuticatePermissionsGroups extends LuticatePermissionsGroupsModel
8
-{
9
-    protected $primaryKey = "name";
10
-}

+ 0
- 51
src/Auth/DataAccess/Models/LuticatePermissionsGroupsModel.php View File

@@ -1,51 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- * DO NOT DIRECTLY USE THIS FILE
7
- * USE LuticatePermissionsGroups.php
8
- * TO MAKE YOUR CHANGES AND DATABASE ACCESS
9
-*/
10
-
11
-namespace Luticate\Auth\DataAccess\Models;
12
-
13
-use Luticate\Utils\LuModel;
14
-use Luticate\Auth\DBO\LuticatePermissionsGroupsDbo;
15
-
16
-class LuticatePermissionsGroupsModel extends LuModel
17
-{
18
-    function __construct()
19
-    {
20
-        parent::__construct();
21
-        $this->timestamps = false;
22
-    }
23
-
24
-    public function toDbo()
25
-    {
26
-        $dbo = new LuticatePermissionsGroupsDbo();
27
-
28
-        $dbo->setName($this->name);
29
-        $dbo->setValue($this->value);
30
-        $dbo->setGroupId($this->group_id);
31
-
32
-        return $dbo;
33
-    }
34
-
35
-    /**
36
-     * @param $dbo LuticatePermissionsGroupsDbo
37
-     * @param $model LuModel|null
38
-     * @return LuticatePermissionsGroups
39
-     */
40
-    public function fromDbo($dbo, $model = null)
41
-    {
42
-        if (is_null($model))
43
-            $model = new LuticatePermissionsGroups();
44
-
45
-        $model->name = $dbo->getName();
46
-        $model->value = $dbo->getValue();
47
-        $model->group_id = $dbo->getGroupId();
48
-
49
-        return $model;
50
-    }
51
-}

+ 0
- 49
src/Auth/DataAccess/Models/LuticatePermissionsModel.php View File

@@ -1,49 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- * DO NOT DIRECTLY USE THIS FILE
7
- * USE LuticatePermissions.php
8
- * TO MAKE YOUR CHANGES AND DATABASE ACCESS
9
-*/
10
-
11
-namespace Luticate\Auth\DataAccess\Models;
12
-
13
-use Luticate\Utils\LuModel;
14
-use Luticate\Auth\DBO\LuticatePermissionsDbo;
15
-
16
-class LuticatePermissionsModel extends LuModel
17
-{
18
-    function __construct()
19
-    {
20
-        parent::__construct();
21
-        $this->timestamps = false;
22
-    }
23
-
24
-    public function toDbo()
25
-    {
26
-        $dbo = new LuticatePermissionsDbo();
27
-
28
-        $dbo->setName($this->name);
29
-        $dbo->setValue($this->value);
30
-
31
-        return $dbo;
32
-    }
33
-
34
-    /**
35
-     * @param $dbo LuticatePermissionsDbo
36
-     * @param $model LuModel|null
37
-     * @return LuticatePermissions
38
-     */
39
-    public function fromDbo($dbo, $model = null)
40
-    {
41
-        if (is_null($model))
42
-            $model = new LuticatePermissions();
43
-
44
-        $model->name = $dbo->getName();
45
-        $model->value = $dbo->getValue();
46
-
47
-        return $model;
48
-    }
49
-}

+ 0
- 10
src/Auth/DataAccess/Models/LuticatePermissionsUsers.php View File

@@ -1,10 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess\Models;
4
-
5
-use Luticate\Auth\DBO\LuticatePermissionsUsersDbo;
6
-
7
-class LuticatePermissionsUsers extends LuticatePermissionsUsersModel
8
-{
9
-    protected $primaryKey = "name";
10
-}

+ 0
- 51
src/Auth/DataAccess/Models/LuticatePermissionsUsersModel.php View File

@@ -1,51 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- * DO NOT DIRECTLY USE THIS FILE
7
- * USE LuticatePermissionsUsers.php
8
- * TO MAKE YOUR CHANGES AND DATABASE ACCESS
9
-*/
10
-
11
-namespace Luticate\Auth\DataAccess\Models;
12
-
13
-use Luticate\Utils\LuModel;
14
-use Luticate\Auth\DBO\LuticatePermissionsUsersDbo;
15
-
16
-class LuticatePermissionsUsersModel extends LuModel
17
-{
18
-    function __construct()
19
-    {
20
-        parent::__construct();
21
-        $this->timestamps = false;
22
-    }
23
-
24
-    public function toDbo()
25
-    {
26
-        $dbo = new LuticatePermissionsUsersDbo();
27
-
28
-        $dbo->setName($this->name);
29
-        $dbo->setValue($this->value);
30
-        $dbo->setUserId($this->user_id);
31
-
32
-        return $dbo;
33
-    }
34
-
35
-    /**
36
-     * @param $dbo LuticatePermissionsUsersDbo
37
-     * @param $model LuModel|null
38
-     * @return LuticatePermissionsUsers
39
-     */
40
-    public function fromDbo($dbo, $model = null)
41
-    {
42
-        if (is_null($model))
43
-            $model = new LuticatePermissionsUsers();
44
-
45
-        $model->name = $dbo->getName();
46
-        $model->value = $dbo->getValue();
47
-        $model->user_id = $dbo->getUserId();
48
-
49
-        return $model;
50
-    }
51
-}

+ 0
- 10
src/Auth/DataAccess/Models/LuticateSettings.php View File

@@ -1,10 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess\Models;
4
-
5
-use Luticate\Auth\DBO\LuticateSettingsDbo;
6
-
7
-class LuticateSettings extends LuticateSettingsModel
8
-{
9
-    protected $primaryKey = "name";
10
-}

+ 0
- 55
src/Auth/DataAccess/Models/LuticateSettingsModel.php View File

@@ -1,55 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- * DO NOT DIRECTLY USE THIS FILE
7
- * USE LuticateSettings.php
8
- * TO MAKE YOUR CHANGES AND DATABASE ACCESS
9
-*/
10
-
11
-namespace Luticate\Auth\DataAccess\Models;
12
-
13
-use Luticate\Utils\LuModel;
14
-use Luticate\Auth\DBO\LuticateSettingsDbo;
15
-
16
-class LuticateSettingsModel extends LuModel
17
-{
18
-    function __construct()
19
-    {
20
-        parent::__construct();
21
-        $this->timestamps = false;
22
-    }
23
-
24
-    public function toDbo()
25
-    {
26
-        $dbo = new LuticateSettingsDbo();
27
-
28
-        $dbo->setName($this->name);
29
-        $dbo->setType($this->type);
30
-        $dbo->setValue($this->value);
31
-        $dbo->setIsBlocked($this->is_blocked);
32
-        $dbo->setIsAdmin($this->is_admin);
33
-
34
-        return $dbo;
35
-    }
36
-
37
-    /**
38
-     * @param $dbo LuticateSettingsDbo
39
-     * @param $model LuModel|null
40
-     * @return LuticateSettings
41
-     */
42
-    public function fromDbo($dbo, $model = null)
43
-    {
44
-        if (is_null($model))
45
-            $model = new LuticateSettings();
46
-
47
-        $model->name = $dbo->getName();
48
-        $model->type = $dbo->getType();
49
-        $model->value = $dbo->getValue();
50
-        $model->is_blocked = $dbo->getIsBlocked();
51
-        $model->is_admin = $dbo->getIsAdmin();
52
-
53
-        return $model;
54
-    }
55
-}

+ 0
- 10
src/Auth/DataAccess/Models/LuticateSettingsUsers.php View File

@@ -1,10 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess\Models;
4
-
5
-use Luticate\Auth\DBO\LuticateSettingsUsersDbo;
6
-
7
-class LuticateSettingsUsers extends LuticateSettingsUsersModel
8
-{
9
-    protected $primaryKey = "name";
10
-}

+ 0
- 53
src/Auth/DataAccess/Models/LuticateSettingsUsersModel.php View File

@@ -1,53 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- * DO NOT DIRECTLY USE THIS FILE
7
- * USE LuticateSettingsUsers.php
8
- * TO MAKE YOUR CHANGES AND DATABASE ACCESS
9
-*/
10
-
11
-namespace Luticate\Auth\DataAccess\Models;
12
-
13
-use Luticate\Utils\LuModel;
14
-use Luticate\Auth\DBO\LuticateSettingsUsersDbo;
15
-
16
-class LuticateSettingsUsersModel extends LuModel
17
-{
18
-    function __construct()
19
-    {
20
-        parent::__construct();
21
-        $this->timestamps = false;
22
-    }
23
-
24
-    public function toDbo()
25
-    {
26
-        $dbo = new LuticateSettingsUsersDbo();
27
-
28
-        $dbo->setName($this->name);
29
-        $dbo->setValue($this->value);
30
-        $dbo->setUserId($this->user_id);
31
-        $dbo->setIsBlocked($this->is_blocked);
32
-
33
-        return $dbo;
34
-    }
35
-
36
-    /**
37
-     * @param $dbo LuticateSettingsUsersDbo
38
-     * @param $model LuModel|null
39
-     * @return LuticateSettingsUsers
40
-     */
41
-    public function fromDbo($dbo, $model = null)
42
-    {
43
-        if (is_null($model))
44
-            $model = new LuticateSettingsUsers();
45
-
46
-        $model->name = $dbo->getName();
47
-        $model->value = $dbo->getValue();
48
-        $model->user_id = $dbo->getUserId();
49
-        $model->is_blocked = $dbo->getIsBlocked();
50
-
51
-        return $model;
52
-    }
53
-}

+ 0
- 18
src/Auth/DataAccess/Models/LuticateUsers.php View File

@@ -1,18 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Auth\DataAccess\Models;
4
-
5
-use Luticate\Auth\DBO\LuticateUsersDbo;
6
-
7
-class LuticateUsers extends LuticateUsersModel
8
-{
9
-    public function permissions()
10
-    {
11
-        return $this->belongsToMany('Luticate\Auth\DataAccess\Models\LuticatePermissions', "luticate_permissions_users", "user_id", "name");
12
-    }
13
-
14
-    public function settings()
15
-    {
16
-        return $this->belongsToMany('Luticate\Auth\DataAccess\Models\LuticateSettings', "luticate_settings_users", "user_id", "name");
17
-    }
18
-}

+ 0
- 61
src/Auth/DataAccess/Models/LuticateUsersModel.php View File

@@ -1,61 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- * DO NOT DIRECTLY USE THIS FILE
7
- * USE LuticateUsers.php
8
- * TO MAKE YOUR CHANGES AND DATABASE ACCESS
9
-*/
10
-
11
-namespace Luticate\Auth\DataAccess\Models;
12
-
13
-use Luticate\Utils\LuModel;
14
-use Luticate\Auth\DBO\LuticateUsersDbo;
15
-
16
-class LuticateUsersModel extends LuModel
17
-{
18
-    function __construct()
19
-    {
20
-        parent::__construct();
21
-        $this->timestamps = false;
22
-    }
23
-
24
-    public function toDbo()
25
-    {
26
-        $dbo = new LuticateUsersDbo();
27
-
28
-        $dbo->setId($this->id);
29
-        $dbo->setUsername($this->username);
30
-        $dbo->setEmail($this->email);
31
-        $dbo->setPassword($this->password);
32
-        $dbo->setSalt($this->salt);
33
-        $dbo->setProfileId($this->profile_id);
34
-        $dbo->setFirstname($this->firstname);
35
-        $dbo->setLastname($this->lastname);
36
-
37
-        return $dbo;
38
-    }
39
-
40
-    /**
41
-     * @param $dbo LuticateUsersDbo
42
-     * @param $model LuModel|null
43
-     * @return LuticateUsers
44
-     */
45
-    public function fromDbo($dbo, $model = null)
46
-    {
47
-        if (is_null($model))
48
-            $model = new LuticateUsers();
49
-
50
-        $model->id = $dbo->getId();
51
-        $model->username = $dbo->getUsername();
52
-        $model->email = $dbo->getEmail();
53
-        $model->password = $dbo->getPassword();
54
-        $model->salt = $dbo->getSalt();
55
-        $model->profile_id = $dbo->getProfileId();
56
-        $model->firstname = $dbo->getFirstname();
57
-        $model->lastname = $dbo->getLastname();
58
-
59
-        return $model;
60
-    }
61
-}

+ 0
- 120
src/Auth/DataAccess/SP/SpLuGetAllUserPermission.php View File

@@ -1,120 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DataAccess\SP;
9
-
10
-use Luticate\Utils\LuSpDbo;
11
-use Luticate\Utils\LuMultipleDbo;
12
-use Luticate\Utils\LuStringUtils;
13
-use Illuminate\Support\Facades\DB;
14
-
15
-class SpLuGetAllUserPermission extends LuSpDbo {
16
-
17
-    /**
18
-    * @param $dam
19
-    * @return \Luticate\Auth\DataAccess\SP\SpLuGetAllUserPermission|null
20
-    */
21
-    protected static function damToDbo($dam)
22
-    {
23
-        if (is_null($dam))
24
-            return null;
25
-        $dbo = new SpLuGetAllUserPermission();
26
-
27
-        $dbo->setPermissonName(LuStringUtils::convertJsonString($dam->_permisson_name));
28
-        $dbo->setVal(LuStringUtils::convertJsonString($dam->val));
29
-
30
-        return $dbo;
31
-    }
32
-
33
-
34
-    /**
35
-    * @param $_user_id integer
36
-    * @return \Luticate\Auth\DataAccess\SP\SpLuGetAllUserPermission[];
37
-    */
38
-    public static function execute($_user_id)
39
-    {
40
-        $values = DB::select('SELECT to_json(data._permisson_name) AS _permisson_name, to_json(data.val) AS val FROM sp_lu_get_all_user_permission(:_user_id) data', array(":_user_id" => $_user_id));
41
-        $dboValues = array();
42
-        foreach ($values as $value)
43
-            $dboValues[] = self::damToDbo($value);
44
-        return $dboValues;
45
-    }
46
-
47
-    /**
48
-    * @param $_user_id integer
49
-    * @param $page int The page number, 0 based
50
-    * @param $perPage int The number of items per page
51
-    * @return \Luticate\Utils\LuMultipleDbo;
52
-    */
53
-    public static function getMultipleJson($_user_id, $page, $perPage)
54
-    {
55
-        $values = DB::select('SELECT (SELECT count(*) FROM sp_lu_get_all_user_permission(:_user_id)) as count, (SELECT json_agg(q) FROM (SELECT * FROM sp_lu_get_all_user_permission(:_user_id) OFFSET (:page::int * :perPage::int) LIMIT :perPage) q) as data',
56
-            array(":_user_id" => $_user_id, ":page" => $page, ":perPage" => $perPage));
57
-        $value = $values[0];
58
-        if (is_null($value->data))
59
-        {
60
-            $value->data = '[]';
61
-        }
62
-        $data = LuStringUtils::convertJsonString($value->data);
63
-        return new LuMultipleDbo($value->count, $data);
64
-    }
65
-
66
-    public function jsonSerialize()
67
-    {
68
-        return array(
69
-            "PermissonName" => $this->_PermissonName,
70
-            "Val" => $this->_val
71
-        );
72
-    }
73
-
74
-    public static function jsonDeserialize($json)
75
-    {
76
-        $dbo = new SpLuGetAllUserPermission();
77
-        if (isset($json["PermissonName"])) {
78
-            $dbo->setPermissonName($json["PermissonName"]);
79
-        }
80
-        if (isset($json["Val"])) {
81
-            $dbo->setVal($json["Val"]);
82
-        }
83
-        return $dbo;
84
-    }
85
-
86
-    public static function generateSample()
87
-    {
88
-        $dbo = new SpLuGetAllUserPermission();
89
-        $dbo->setPermissonName("sample string");
90
-        $dbo->setVal(true);
91
-        return $dbo;
92
-    }
93
-
94
-
95
-    /**
96
-    * @var string
97
-    */
98
-    protected $_PermissonName;
99
-    public function getPermissonName()
100
-    {
101
-        return $this->_PermissonName;
102
-    }
103
-    public function setPermissonName($value)
104
-    {
105
-        $this->_PermissonName = $value;
106
-    }
107
-
108
-    /**
109
-    * @var boolean
110
-    */
111
-    protected $_val;
112
-    public function getVal()
113
-    {
114
-        return $this->_val;
115
-    }
116
-    public function setVal($value)
117
-    {
118
-        $this->_val = $value;
119
-    }
120
-}

+ 0
- 101
src/Auth/DataAccess/SP/SpLuGetAllUserSettings.php View File

@@ -1,101 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DataAccess\SP;
9
-
10
-use Luticate\Utils\LuSpDbo;
11
-use Luticate\Utils\LuMultipleDbo;
12
-use Luticate\Utils\LuStringUtils;
13
-use Illuminate\Support\Facades\DB;
14
-
15
-class SpLuGetAllUserSettings extends LuSpDbo {
16
-
17
-    /**
18
-    * @param $dam
19
-    * @return \Luticate\Auth\DataAccess\SP\SpLuGetAllUserSettings|null
20
-    */
21
-    protected static function damToDbo($dam)
22
-    {
23
-        if (is_null($dam))
24
-            return null;
25
-        $dbo = new SpLuGetAllUserSettings();
26
-
27
-        $dbo->setSettings(LuStringUtils::convertJsonString($dam->_settings));
28
-
29
-        return $dbo;
30
-    }
31
-
32
-
33
-    /**
34
-    * @param $_user_id integer
35
-    * @return \Luticate\Auth\DataAccess\SP\SpLuGetAllUserSettings[];
36
-    */
37
-    public static function execute($_user_id)
38
-    {
39
-        $values = DB::select('SELECT to_json(data._settings) AS _settings FROM sp_lu_get_all_user_settings(:_user_id) data', array(":_user_id" => $_user_id));
40
-        $dboValues = array();
41
-        foreach ($values as $value)
42
-            $dboValues[] = self::damToDbo($value);
43
-        return $dboValues;
44
-    }
45
-
46
-    /**
47
-    * @param $_user_id integer
48
-    * @param $page int The page number, 0 based
49
-    * @param $perPage int The number of items per page
50
-    * @return \Luticate\Utils\LuMultipleDbo;
51
-    */
52
-    public static function getMultipleJson($_user_id, $page, $perPage)
53
-    {
54
-        $values = DB::select('SELECT (SELECT count(*) FROM sp_lu_get_all_user_settings(:_user_id)) as count, (SELECT json_agg(q) FROM (SELECT * FROM sp_lu_get_all_user_settings(:_user_id) OFFSET (:page::int * :perPage::int) LIMIT :perPage) q) as data',
55
-            array(":_user_id" => $_user_id, ":page" => $page, ":perPage" => $perPage));
56
-        $value = $values[0];
57
-        if (is_null($value->data))
58
-        {
59
-            $value->data = '[]';
60
-        }
61
-        $data = LuStringUtils::convertJsonString($value->data);
62
-        return new LuMultipleDbo($value->count, $data);
63
-    }
64
-
65
-    public function jsonSerialize()
66
-    {
67
-        return array(
68
-            "Settings" => $this->_Settings
69
-        );
70
-    }
71
-
72
-    public static function jsonDeserialize($json)
73
-    {
74
-        $dbo = new SpLuGetAllUserSettings();
75
-        if (isset($json["Settings"])) {
76
-            $dbo->setSettings($json["Settings"]);
77
-        }
78
-        return $dbo;
79
-    }
80
-
81
-    public static function generateSample()
82
-    {
83
-        $dbo = new SpLuGetAllUserSettings();
84
-        $dbo->setSettings("sample string");
85
-        return $dbo;
86
-    }
87
-
88
-
89
-    /**
90
-    * @var json
91
-    */
92
-    protected $_Settings;
93
-    public function getSettings()
94
-    {
95
-        return $this->_Settings;
96
-    }
97
-    public function setSettings($value)
98
-    {
99
-        $this->_Settings = $value;
100
-    }
101
-}

+ 0
- 81
src/Auth/DataAccess/SP/SpLuGetUserPermission.php View File

@@ -1,81 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DataAccess\SP;
9
-
10
-use Luticate\Utils\LuSpDbo;
11
-use Luticate\Utils\LuMultipleDbo;
12
-use Luticate\Utils\LuStringUtils;
13
-use Illuminate\Support\Facades\DB;
14
-
15
-class SpLuGetUserPermission extends LuSpDbo {
16
-
17
-    /**
18
-    * @param $dam
19
-    * @return \Luticate\Auth\DataAccess\SP\SpLuGetUserPermission|null
20
-    */
21
-    protected static function damToDbo($dam)
22
-    {
23
-        if (is_null($dam))
24
-            return null;
25
-        $dbo = new SpLuGetUserPermission();
26
-
27
-        $dbo->setVal(LuStringUtils::convertJsonString($dam->val));
28
-
29
-        return $dbo;
30
-    }
31
-
32
-
33
-    /**
34
-    * @param $_user_id integer
35
-    * @param $_permisson_name string
36
-    * @return \Luticate\Auth\DataAccess\SP\SpLuGetUserPermission;
37
-    */
38
-    public static function execute($_user_id, $_permisson_name)
39
-    {
40
-        $values = DB::select('SELECT to_json(data.val) AS val FROM sp_lu_get_user_permission(:_user_id, :_permisson_name) data', array(":_user_id" => $_user_id, ":_permisson_name" => $_permisson_name));
41
-        return self::damToDbo($values[0]);
42
-    }
43
-
44
-
45
-    public function jsonSerialize()
46
-    {
47
-        return array(
48
-            "Val" => $this->_val
49
-        );
50
-    }
51
-
52
-    public static function jsonDeserialize($json)
53
-    {
54
-        $dbo = new SpLuGetUserPermission();
55
-        if (isset($json["Val"])) {
56
-            $dbo->setVal($json["Val"]);
57
-        }
58
-        return $dbo;
59
-    }
60
-
61
-    public static function generateSample()
62
-    {
63
-        $dbo = new SpLuGetUserPermission();
64
-        $dbo->setVal(true);
65
-        return $dbo;
66
-    }
67
-
68
-
69
-    /**
70
-    * @var boolean
71
-    */
72
-    protected $_val;
73
-    public function getVal()
74
-    {
75
-        return $this->_val;
76
-    }
77
-    public function setVal($value)
78
-    {
79
-        $this->_val = $value;
80
-    }
81
-}

+ 0
- 81
src/Auth/DataAccess/SP/SpLuGetUserSetting.php View File

@@ -1,81 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * AUTO GENERATED BY LUTICATE GENERATOR
5
- * ANY CHANGES WILL BE OVERWRITTEN
6
- */
7
-
8
-namespace Luticate\Auth\DataAccess\SP;
9
-
10
-use Luticate\Utils\LuSpDbo;
11
-use Luticate\Utils\LuMultipleDbo;
12
-use Luticate\Utils\LuStringUtils;
13
-use Illuminate\Support\Facades\DB;
14
-
15
-class SpLuGetUserSetting extends LuSpDbo {
16
-
17
-    /**
18
-    * @param $dam
19
-    * @return \Luticate\Auth\DataAccess\SP\SpLuGetUserSetting|null
20
-    */
21
-    protected static function damToDbo($dam)
22
-    {
23
-        if (is_null($dam))
24
-            return null;
25
-        $dbo = new SpLuGetUserSetting();
26
-
27
-        $dbo->setSetting(LuStringUtils::convertJsonString($dam->setting));
28
-
29
-        return $dbo;
30
-    }
31
-
32
-
33
-    /**
34
-    * @param $_user_id integer
35
-    * @param $_setting_name string
36
-    * @return \Luticate\Auth\DataAccess\SP\SpLuGetUserSetting;
37
-    */
38
-    public static function execute($_user_id, $_setting_name)
39
-    {
40
-        $values = DB::select('SELECT to_json(data.setting) AS setting FROM sp_lu_get_user_setting(:_user_id, :_setting_name) data', array(":_user_id" => $_user_id, ":_setting_name" => $_setting_name));
41
-        return self::damToDbo($values[0]);
42
-    }
43
-
44
-
45
-    public function jsonSerialize()
46
-    {
47
-        return array(
48
-            "Setting" => $this->_setting
49
-        );
50
-    }
51
-
52
-    public static function jsonDeserialize($json)
53
-    {
54
-        $dbo = new SpLuGetUserSetting();
55
-        if (isset($json["Setting"])) {
56
-            $dbo->setSetting($json["Setting"]);
57
-        }
58
-        return $dbo;
59
-    }
60
-
61
-    public static function generateSample()
62
-    {
63
-        $dbo = new SpLuGetUserSetting();
64
-        $dbo->setSetting("sample string");
65
-        return $dbo;
66
-    }
67
-
68
-
69
-    /**
70
-    * @var json
71
-    */
72
-    protected $_setting;
73
-    public function getSetting()
74
-    {
75
-        return $this->_setting;
76
-    }
77
-    public function setSetting($value)
78
-    {
79
-        $this->_setting = $value;
80
-    }
81
-}

+ 0
- 2
src/Auth/DataAccess/SP/src/sp_lu_get_all_user_permission.sql View File

@@ -1,2 +0,0 @@
1
-
2
-	SELECT p.name, sp_lu_get_user_permission(_user_id, p.name) FROM luticate_permissions p ORDER bY p.name

+ 0
- 5
src/Auth/DataAccess/SP/src/sp_lu_get_all_user_settings.sql View File

@@ -1,5 +0,0 @@
1
-
2
-	SELECT sp_lu_get_user_setting(_user_id, s.name)
3
-	FROM luticate_settings s
4
-	WHERE NOT s.is_admin
5
-	ORDER BY s.name

+ 0
- 22
src/Auth/DataAccess/SP/src/sp_lu_get_user_permission.sql View File

@@ -1,22 +0,0 @@
1
-
2
-DECLARE
3
-groups int[];
4
-g INT;
5
-BEGIN
6
-    SELECT "value" INTO val FROM luticate_permissions_users WHERE "user_id" = _user_id AND "name" = _permisson_name;
7
-    IF val is null THEN
8
-	SELECT lpg."value" into val FROM luticate_permissions_groups lpg
9
-	INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
10
-	INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
11
-	WHERE lpg."name" = _permisson_name and lpg."value" = FALSE;
12
-	IF val is null then
13
-	    SELECT lpg."value" into val FROM luticate_permissions_groups lpg
14
-      	    INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
15
-	    INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
16
-	    WHERE lpg."name" = _permisson_name and lpg."value" = TRUE;
17
-	    IF val is null then
18
-		SELECT "value" INTO val FROM luticate_permissions WHERE "name" = _permisson_name;
19
-	    END IF;
20
-	end if;
21
-    END IF;
22
-END;

+ 0
- 18
src/Auth/DataAccess/SP/src/sp_lu_get_user_setting.sql View File

@@ -1,18 +0,0 @@
1
-
2
-DECLARE
3
-_setting luticate_settings;
4
-_setting_user luticate_settings_users;
5
-BEGIN
6
-    SELECT * INTO _setting FROM luticate_settings WHERE "name" = _setting_name AND NOT "is_admin";
7
-    IF _setting IS NULL THEN
8
-        setting := NULL;
9
-    ELSE
10
-        IF NOT _setting.is_blocked THEN
11
-            SELECT * INTO _setting_user FROM luticate_settings_users WHERE "user_id" = _user_id AND "name" = _setting_name;
12
-            IF _setting_user IS NOT NULL THEN
13
-                _setting.value := _setting_user.value;
14
-            END IF;
15
-        END IF;
16
-        setting := to_json(_setting);
17
-    END IF;
18
-END;

+ 36
- 0
src/Auth/DataAccess/Sp/SpLuGetUserPermissionById.php View File

@@ -0,0 +1,36 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 7/2/16
6
+ * Time: 5:32 PM
7
+ */
8
+
9
+namespace Luticate\Auth\DataAccess\Sp;
10
+
11
+use Luticate\Utils\DataAccess\LuStoredProcedure;
12
+use Luticate\Utils\Dbo\LuBoolDbo;
13
+
14
+class SpLuGetUserPermissionById extends LuStoredProcedure
15
+{
16
+    protected static $_connection = "luticatedb";
17
+    protected static $_storedProcedure = "sp_lu_get_user_permission_by_id";
18
+    protected static $_dboClass = LuBoolDbo::class;
19
+
20
+    /**
21
+     * @param $userId int
22
+     * @param $permissionId int
23
+     * @return bool
24
+     */
25
+    public static function getPermissionValue(int $userId, int $permissionId)
26
+    {
27
+        /**
28
+         * @var $val LuBoolDbo
29
+         */
30
+        $val = static::getSingle([$userId, $permissionId]);
31
+        if (!is_null($val)) {
32
+            return $val->getBool();
33
+        }
34
+        return null;
35
+    }
36
+}

+ 36
- 0
src/Auth/DataAccess/Sp/SpLuGetUserPermissionByName.php View File

@@ -0,0 +1,36 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 7/2/16
6
+ * Time: 5:32 PM
7
+ */
8
+
9
+namespace Luticate\Auth\DataAccess\Sp;
10
+
11
+use Luticate\Utils\DataAccess\LuStoredProcedure;
12
+use Luticate\Utils\Dbo\LuBoolDbo;
13
+
14
+class SpLuGetUserPermissionByName extends LuStoredProcedure
15
+{
16
+    protected static $_connection = "luticatedb";
17
+    protected static $_storedProcedure = "sp_lu_get_user_permission_by_name";
18
+    protected static $_dboClass = LuBoolDbo::class;
19
+
20
+    /**
21
+     * @param $userId int
22
+     * @param $permissionName string
23
+     * @return bool
24
+     */
25
+    public static function getPermissionValue(int $userId, string $permissionName)
26
+    {
27
+        /**
28
+         * @var $val LuBoolDbo
29
+         */
30
+        $val = static::getSingle([$userId, $permissionName]);
31
+        if (!is_null($val)) {
32
+            return $val->getBool();
33
+        }
34
+        return null;
35
+    }
36
+}

+ 77
- 0
src/Auth/Dbo/LuPermissionLite.php View File

@@ -0,0 +1,77 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 7/2/16
6
+ * Time: 5:37 PM
7
+ */
8
+
9
+namespace Luticate\Auth\Dbo;
10
+
11
+use Luticate\Utils\Dbo\LuDbo;
12
+
13
+class LuPermissionLite extends LuDbo
14
+{
15
+    /**
16
+     * @var $_id int
17
+     */
18
+    protected $_id;
19
+
20
+    /**
21
+     * @var $_name string
22
+     */
23
+    protected $_name;
24
+
25
+    /**
26
+     * @var $_value bool
27
+     */
28
+    protected $_value;
29
+
30
+    /**
31
+     * @return int
32
+     */
33
+    public function getId()
34
+    {
35
+        return $this->_id;
36
+    }
37
+
38
+    /**
39
+     * @param int $id
40
+     */
41
+    public function setId($id)
42
+    {
43
+        $this->_id = $id;
44
+    }
45
+
46
+    /**
47
+     * @return string
48
+     */
49
+    public function getName()
50
+    {
51
+        return $this->_name;
52
+    }
53
+
54
+    /**
55
+     * @param string $name
56
+     */
57
+    public function setName($name)
58
+    {
59
+        $this->_name = $name;
60
+    }
61
+
62
+    /**
63
+     * @return boolean
64
+     */
65
+    public function isValue()
66
+    {
67
+        return $this->_value;
68
+    }
69
+
70
+    /**
71
+     * @param boolean $value
72
+     */
73
+    public function setValue($value)
74
+    {
75
+        $this->_value = $value;
76
+    }
77
+}

+ 0
- 74
test/TestPermission.php View File

@@ -1,74 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * Created by PhpStorm.
5
- * User: robin
6
- * Date: 9/26/15
7
- * Time: 11:56 PM
8
- */
9
-
10
-
11
-require_once('../vendor/autoload.php');
12
-
13
-Dotenv::load("..");
14
-
15
-class TestPermission
16
-{
17
-    private $_pdo;
18
-
19
-    public function __construct()
20
-    {
21
-        $dsn = getenv("DB_CONNECTION") . ":dbname=" . getenv("DB_DATABASE") . ";host="
22
-            . getenv("DB_HOST") . ";port=" . getenv("DB_PORT");
23
-        $this->_pdo = new PDO($dsn, getenv("DB_USERNAME"), getenv("DB_PASSWORD"));
24
-    }
25
-
26
-    protected function printError($query, $message)
27
-    {
28
-        echo $message . "\n";
29
-        var_dump($query->errorInfo());
30
-        var_dump($this->_pdo->errorInfo());
31
-        return null;
32
-    }
33
-
34
-    public function getPermission($user_id, $name)
35
-    {
36
-        $req = $this->_pdo->prepare("SELECT * FROM sp_lu_get_user_permission(:user_id, :name)");
37
-        if ($req->execute(array(":user_id" => $user_id, ":name" => $name)))
38
-        {
39
-            return $req->fetchAll()[0][0];
40
-        }
41
-        else
42
-        {
43
-            $this->printError($req, "Failed to get permission");
44
-            return null;
45
-        }
46
-    }
47
-}
48
-
49
-$test = new TestPermission();
50
-
51
-$user_id = 1;
52
-$permissions = array(
53
-    "perm_1" => true,
54
-    "perm_2" => false,
55
-    "perm_3" => true,
56
-    "perm_4" => false,
57
-    "perm_5" => false,
58
-    "perm_6" => true,
59
-    "perm_7" => true,
60
-    "perm_8" => false
61
-);
62
-
63
-foreach ($permissions as $permission => $value)
64
-{
65
-    $p = $test->getPermission($user_id, $permission);
66
-    if ($p == $value)
67
-    {
68
-        echo "[ OK ] $permission\n";
69
-    }
70
-    else if ($p != null)
71
-    {
72
-        echo "[ERR ] $permission\n";
73
-    }
74
-}

+ 0
- 91
test/test_permissions.sql View File

@@ -1,101 +0,0 @@
1
---
2
---
3
-
4
-SET statement_timeout = 0;
5
-SET lock_timeout = 0;
6
-SET client_encoding = 'UTF8';
7
-SET standard_conforming_strings = on;
8
-SET check_function_bodies = false;
9
-SET client_min_messages = warning;
10
-
11
-SET search_path = public, pg_catalog;
12
-
13
---
14
---
15
-
16
-COPY luticate_groups (id, name) FROM stdin;
17
-1	test
18
-2	test2
19
-\.
20
-
21
-
22
---
23
---
24
-
25
-SELECT pg_catalog.setval('luticate_groups_id_seq', 2, true);
26
-
27
-
28
---
29
---
30
-
31
-COPY luticate_permissions (name, value) FROM stdin;
32
-perm_1	t
33
-perm_2	f
34
-perm_3	t
35
-perm_4	f
36
-perm_5	t
37
-perm_6	f
38
-perm_7	f
39
-perm_8	t
40
-\.
41
-
42
-
43
---
44
---
45
-
46
-COPY luticate_permissions_groups (name, value, group_id) FROM stdin;
47
-perm_3	t	1
48
-perm_4	f	1
49
-perm_5	t	1
50
-perm_5	f	2
51
-perm_6	t	1
52
-perm_6	t	2
53
-perm_7	f	1
54
-\.
55
-
56
-
57
---
58
---
59
-
60
-COPY luticate_users (id, username, email, password, salt) FROM stdin;
61
-1	test	test@test.test	test	test
62
-\.
63
-
64
-
65
---
66
---
67
-
68
-COPY luticate_permissions_users (name, value, user_id) FROM stdin;
69
-perm_7	t	1
70
-perm_8	f	1
71
-\.
72
-
73
-
74
---
75
---
76
-
77
-COPY luticate_users_groups (user_id, group_id) FROM stdin;
78
-1	1
79
-1	2
80
-\.
81
-
82
-
83
---
84
---
85
-
86
-SELECT pg_catalog.setval('luticate_users_id_seq', 1, true);
87
-
88
-
89
---
90
---
91
-

+ 68
- 0
tests/LuPermissionTest.php View File

@@ -0,0 +1,68 @@
1
+<?php
2
+use Luticate\Auth\DataAccess\Sp\SpLuGetUserPermissionById;
3
+use Luticate\Auth\DataAccess\Sp\SpLuGetUserPermissionByName;
4
+
5
+/**
6
+ * Created by PhpStorm.
7
+ * User: robin
8
+ * Date: 7/2/16
9
+ * Time: 5:26 PM
10
+ */
11
+class LuPermissionTest extends \PHPUnit_Framework_TestCase
12
+{
13
+    protected function permissionTest($expectedValue, string $permissionName, int $permissionId, int $userId)
14
+    {
15
+        $this->assertSame($expectedValue, SpLuGetUserPermissionByName::getPermissionValue($userId, $permissionName));
16
+        $this->assertSame($expectedValue, SpLuGetUserPermissionById::getPermissionValue($userId, $permissionId));
17
+    }
18
+
19
+    public function testPermission0True()
20
+    {
21
+        static::permissionTest(true, "LU_TEST_SIMPLE_TRUE", 3, 0);
22
+    }
23
+
24
+    public function testPermission0False()
25
+    {
26
+        static::permissionTest(false, "LU_TEST_SIMPLE_FALSE", 4, 0);
27
+    }
28
+
29
+    public function testPermission0DoesNotExist()
30
+    {
31
+        static::permissionTest(null, "LU_TEST_DOES_NOT_EXIST", 0, 0);
32
+    }
33
+
34
+    public function testPermissionGroup1True()
35
+    {
36
+        static::permissionTest(true, "LU_TEST_GROUP_1_TRUE", 5, 1);
37
+    }
38
+
39
+    public function testPermissionGroup1False()
40
+    {
41
+        static::permissionTest(false, "LU_TEST_GROUP_1_FALSE", 6, 1);
42
+    }
43
+
44
+    public function testPermissionGroup2MultipleGroupsTrue()
45
+    {
46
+        static::permissionTest(true, "LU_TEST_GROUP_2_TRUE", 7, 2);
47
+    }
48
+
49
+    public function testPermissionGroup3MultipleGroupsTrueFalse()
50
+    {
51
+        static::permissionTest(false, "LU_TEST_GROUP_3_FALSE", 8, 3);
52
+    }
53
+
54
+    public function testPermissionGroup4MultipleGroupsFalse()
55
+    {
56
+        static::permissionTest(false, "LU_TEST_GROUP_4_FALSE", 9, 4);
57
+    }
58
+
59
+    public function testPermissionUser5True()
60
+    {
61
+        static::permissionTest(true, "LU_TEST_USER_5_TRUE", 10, 5);
62
+    }
63
+
64
+    public function testPermissionUser6False()
65
+    {
66
+        static::permissionTest(false, "LU_TEST_USER_6_FALSE", 11, 6);
67
+    }
68
+}

+ 14
- 0
tests/bootstrap.php View File

@@ -0,0 +1,14 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 5/29/16
6
+ * Time: 2:59 PM
7
+ */
8
+
9
+use Luticate\Utils\Controller\LuticateApplication;
10
+
11
+$json = file_get_contents(__DIR__ . '/../config.json');
12
+$config = json_decode($json, true);
13
+$app = new LuticateApplication($config);
14
+$app->addDatabaseProvider(\Luticate\Utils\DataAccess\LuDataAccess::class);

Loading…
Cancel
Save