You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuticateBusiness.php 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: robin
  5. * Date: 9/30/15
  6. * Time: 7:04 PM
  7. */
  8. namespace Luticate\Auth\Business;
  9. use Luticate\Auth\DBO\LuticatePermissions;
  10. use Luticate\Auth\DBO\LuticateUsersDbo;
  11. use Luticate\Utils\LuRoute;
  12. class LuticateBusiness
  13. {
  14. /**
  15. * @var LuticateUsersDbo
  16. */
  17. private static $_currentUser;
  18. public static function getCurrentUser()
  19. {
  20. return self::$_currentUser;
  21. }
  22. public static function setCurrentUser($user)
  23. {
  24. self::$_currentUser = $user;
  25. }
  26. public static function setupAuth()
  27. {
  28. $route = LuRoute::getInstance();
  29. $route->addMiddleware('Luticate\Auth\Business\LuticateMiddleware');
  30. }
  31. /**
  32. * @param $prefix string
  33. */
  34. public static function setupRoutes($prefix = "/luticate")
  35. {
  36. $ns = 'Luticate\Auth\Controller\\';
  37. $int = "[0-9]+";
  38. $name = "[A-Z0-9_]+";
  39. $bool = "true|false";
  40. $group_id = "{group_id:$int}";
  41. $user_id = "{user_id:$int}";
  42. $permission_name = "{permission_name:$name}";
  43. $permission_value = "{permission_value:$bool}";
  44. $route = LuRoute::getInstance();
  45. $route->post("$prefix/users/login", "${ns}LuticateUsersController", "login");
  46. $route->post("$prefix/users/logout", "${ns}LuticateUsersController", "logout");
  47. $route->get("$prefix/users/$user_id", "${ns}LuticateUsersController", "getLightById", LuticatePermissions::USER_GET);
  48. $route->get("$prefix/users", "${ns}LuticateUsersController", "getAllLight", LuticatePermissions::USER_GET);
  49. $route->post("$prefix/users/add", "${ns}LuticateUsersController", "add",
  50. array(LuticatePermissions::USER_ADD, LuticatePermissions::USER_GET));
  51. $route->post("$prefix/users/$user_id/del", "${ns}LuticateUsersController", "del",
  52. array(LuticatePermissions::USER_DEL, LuticatePermissions::USER_GET));
  53. $route->post("$prefix/users/$user_id/edit", "${ns}LuticateUsersController", "edit",
  54. array(LuticatePermissions::USER_EDIT, LuticatePermissions::USER_GET));
  55. $route->post("$prefix/users/me/edit", "${ns}LuticateUsersController", "editMe",
  56. LuticatePermissions::USER_EDIT_ME);
  57. $route->post("$prefix/users/$user_id/setPassword", "${ns}LuticateUsersController", "setPassword",
  58. array(LuticatePermissions::USER_SET_PASSWORD, LuticatePermissions::USER_GET));
  59. $route->post("$prefix/users/me/setPassword", "${ns}LuticateUsersController", "setPasswordMe",
  60. LuticatePermissions::USER_SET_PASSWORD_ME);
  61. $route->get("$prefix/groups/$group_id", "${ns}LuticateGroupsController", "getById", LuticatePermissions::GROUP_GET);
  62. $route->get("$prefix/groups", "${ns}LuticateGroupsController", "getAll", LuticatePermissions::GROUP_GET);
  63. $route->post("$prefix/groups/add", "${ns}LuticateGroupsController", "add",
  64. array(LuticatePermissions::GROUP_ADD, LuticatePermissions::GROUP_GET));
  65. $route->post("$prefix/groups/$group_id/del", "${ns}LuticateGroupsController", "del",
  66. array(LuticatePermissions::GROUP_DEL, LuticatePermissions::GROUP_GET));
  67. $route->post("$prefix/groups/$group_id/edit", "${ns}LuticateGroupsController", "edit",
  68. array(LuticatePermissions::GROUP_EDIT, LuticatePermissions::GROUP_GET));
  69. $route->get("$prefix/groups/$group_id/users/", "${ns}LuticateGroupsController", "getUsers",
  70. LuticatePermissions::GROUP_GET);
  71. $route->post("$prefix/groups/$group_id/users/$user_id/add", "${ns}LuticateGroupsController", "addUser",
  72. array(LuticatePermissions::GROUP_USER_ADD, LuticatePermissions::GROUP_GET));
  73. $route->post("$prefix/groups/$group_id/users/$user_id/del", "${ns}LuticateGroupsController", "delUser",
  74. array(LuticatePermissions::GROUP_USER_DEL, LuticatePermissions::GROUP_GET));
  75. $route->get("$prefix/permissions/effective/$user_id/$permission_name", "${ns}LuticatePermissionsController",
  76. "getEffectivePermission", LuticatePermissions::PERM_EFFECTIVE_GET);
  77. $route->get("$prefix/permissions/effective/$user_id", "${ns}LuticatePermissionsController",
  78. "getAllEffectivePermission", LuticatePermissions::PERM_EFFECTIVE_GET);
  79. $route->get("$prefix/permissions/effective/me/$permission_name", "${ns}LuticatePermissionsController",
  80. "getEffectivePermissionMe");
  81. $route->get("$prefix/permissions/effective/me", "${ns}LuticatePermissionsController",
  82. "getAllEffectivePermissionMe");
  83. $route->get("$prefix/permissions/$permission_name", "${ns}LuticatePermissionsController", "get",
  84. LuticatePermissions::PERM_GET);
  85. $route->get("$prefix/permissions", "${ns}LuticatePermissionsController", "getAll",
  86. LuticatePermissions::PERM_GET);
  87. $route->post("$prefix/permissions/add/$permission_name/$permission_value", "${ns}LuticatePermissionsController",
  88. "add", array(LuticatePermissions::PERM_ADD, LuticatePermissions::PERM_GET));
  89. $route->post("$prefix/permissions/$permission_name/del", "${ns}LuticatePermissionsController", "del",
  90. array(LuticatePermissions::PERM_DEL, LuticatePermissions::PERM_GET));
  91. $route->post("$prefix/permissions/$permission_name/edit/$permission_value", "${ns}LuticatePermissionsController",
  92. "edit", array(LuticatePermissions::PERM_EDIT, LuticatePermissions::PERM_GET));
  93. $route->get("$prefix/permissions/group/$group_id/$permission_name", "${ns}LuticatePermissionsGroupsController",
  94. "get", LuticatePermissions::PERM_GROUP_GET);
  95. $route->get("$prefix/permissions/group/$group_id", "${ns}LuticatePermissionsGroupsController",
  96. "getAllByGroup", LuticatePermissions::PERM_GROUP_GET);
  97. $route->post("$prefix/permissions/group/$group_id/add/$permission_name/$permission_value",
  98. "${ns}LuticatePermissionsGroupsController", "add", array(LuticatePermissions::PERM_GROUP_ADD,
  99. LuticatePermissions::PERM_GROUP_GET));
  100. $route->post("$prefix/permissions/group/$group_id/$permission_name/del",
  101. "${ns}LuticatePermissionsGroupsController", "del", array(LuticatePermissions::PERM_GROUP_DEL,
  102. LuticatePermissions::PERM_GROUP_GET));
  103. $route->post("$prefix/permissions/group/$group_id/$permission_name/edit/$permission_value",
  104. "${ns}LuticatePermissionsGroupsController", "edit", array(LuticatePermissions::PERM_GROUP_EDIT,
  105. LuticatePermissions::PERM_GROUP_GET));
  106. $route->get("$prefix/permissions/user/$user_id/$permission_name", "${ns}LuticatePermissionsUsersController",
  107. "get", LuticatePermissions::PERM_USER_GET);
  108. $route->get("$prefix/permissions/user/$user_id", "${ns}LuticatePermissionsUsersController",
  109. "getAllByUser", LuticatePermissions::PERM_USER_GET);
  110. $route->post("$prefix/permissions/user/$user_id/add/$permission_name/$permission_value",
  111. "${ns}LuticatePermissionsUsersController", "add", array(LuticatePermissions::PERM_USER_ADD,
  112. LuticatePermissions::PERM_USER_GET));
  113. $route->post("$prefix/permissions/user/$user_id/$permission_name/del", "${ns}LuticatePermissionsUsersController",
  114. "del", array(LuticatePermissions::PERM_USER_DEL, LuticatePermissions::PERM_USER_GET));
  115. $route->post("$prefix/permissions/user/$user_id/$permission_name/edit/$permission_value",
  116. "${ns}LuticatePermissionsUsersController", "edit", array(LuticatePermissions::PERM_USER_EDIT,
  117. LuticatePermissions::PERM_USER_GET));
  118. }
  119. }