123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 9/30/15
- * Time: 7:04 PM
- */
-
- namespace Luticate\Auth\Business;
-
- use Luticate\Auth\DBO\LuticatePermissions;
- use Luticate\Auth\DBO\LuticateUsersDbo;
- use Luticate\Utils\LuRoute;
-
- class LuticateBusiness
- {
- /**
- * @var LuticateUsersDbo
- */
- private static $_currentUser;
-
- public static function getCurrentUser()
- {
- return self::$_currentUser;
- }
-
- public static function setCurrentUser($user)
- {
- self::$_currentUser = $user;
- }
-
- public static function setupAuth()
- {
- $route = LuRoute::getInstance();
- $route->addMiddleware('Luticate\Auth\Business\LuticateMiddleware');
- }
-
- /**
- * @param $prefix string
- */
- public static function setupRoutes($prefix = "/luticate")
- {
- $ns = 'Luticate\Auth\Controller\\';
-
- $int = "[0-9]+";
- $name = "[A-Z0-9_]+";
- $bool = "true|false";
-
- $group_id = "{group_id:$int}";
- $user_id = "{user_id:$int}";
- $permission_name = "{permission_name:$name}";
- $permission_value = "{permission_value:$bool}";
-
- $route = LuRoute::getInstance();
-
- $route->post("$prefix/users/login", "${ns}LuticateUsersController", "login");
- $route->post("$prefix/users/logout", "${ns}LuticateUsersController", "logout");
- $route->get("$prefix/users/$user_id", "${ns}LuticateUsersController", "getLightById", LuticatePermissions::USER_GET);
- $route->get("$prefix/users", "${ns}LuticateUsersController", "getAllLight", LuticatePermissions::USER_GET);
- $route->post("$prefix/users/add", "${ns}LuticateUsersController", "add",
- array(LuticatePermissions::USER_ADD, LuticatePermissions::USER_GET));
- $route->post("$prefix/users/$user_id/del", "${ns}LuticateUsersController", "del",
- array(LuticatePermissions::USER_DEL, LuticatePermissions::USER_GET));
- $route->post("$prefix/users/$user_id/edit", "${ns}LuticateUsersController", "edit",
- array(LuticatePermissions::USER_EDIT, LuticatePermissions::USER_GET));
- $route->post("$prefix/users/me/edit", "${ns}LuticateUsersController", "editMe",
- LuticatePermissions::USER_EDIT_ME);
- $route->post("$prefix/users/$user_id/setPassword", "${ns}LuticateUsersController", "setPassword",
- array(LuticatePermissions::USER_SET_PASSWORD, LuticatePermissions::USER_GET));
- $route->post("$prefix/users/me/setPassword", "${ns}LuticateUsersController", "setPasswordMe",
- LuticatePermissions::USER_SET_PASSWORD_ME);
-
-
- $route->get("$prefix/groups/$group_id", "${ns}LuticateGroupsController", "getById", LuticatePermissions::GROUP_GET);
- $route->get("$prefix/groups", "${ns}LuticateGroupsController", "getAll", LuticatePermissions::GROUP_GET);
- $route->post("$prefix/groups/add", "${ns}LuticateGroupsController", "add",
- array(LuticatePermissions::GROUP_ADD, LuticatePermissions::GROUP_GET));
- $route->post("$prefix/groups/$group_id/del", "${ns}LuticateGroupsController", "del",
- array(LuticatePermissions::GROUP_DEL, LuticatePermissions::GROUP_GET));
- $route->post("$prefix/groups/$group_id/edit", "${ns}LuticateGroupsController", "edit",
- array(LuticatePermissions::GROUP_EDIT, LuticatePermissions::GROUP_GET));
-
- $route->get("$prefix/groups/$group_id/users/", "${ns}LuticateGroupsController", "getUsers",
- LuticatePermissions::GROUP_GET);
- $route->post("$prefix/groups/$group_id/users/$user_id/add", "${ns}LuticateGroupsController", "addUser",
- array(LuticatePermissions::GROUP_USER_ADD, LuticatePermissions::GROUP_GET));
- $route->post("$prefix/groups/$group_id/users/$user_id/del", "${ns}LuticateGroupsController", "delUser",
- array(LuticatePermissions::GROUP_USER_DEL, LuticatePermissions::GROUP_GET));
-
-
- $route->get("$prefix/permissions/effective/$user_id/$permission_name", "${ns}LuticatePermissionsController",
- "getEffectivePermission", LuticatePermissions::PERM_EFFECTIVE_GET);
- $route->get("$prefix/permissions/effective/$user_id", "${ns}LuticatePermissionsController",
- "getAllEffectivePermission", LuticatePermissions::PERM_EFFECTIVE_GET);
- $route->get("$prefix/permissions/effective/me/$permission_name", "${ns}LuticatePermissionsController",
- "getEffectivePermissionMe");
- $route->get("$prefix/permissions/effective/me", "${ns}LuticatePermissionsController",
- "getAllEffectivePermissionMe");
-
- $route->get("$prefix/permissions/$permission_name", "${ns}LuticatePermissionsController", "get",
- LuticatePermissions::PERM_GET);
- $route->get("$prefix/permissions", "${ns}LuticatePermissionsController", "getAll",
- LuticatePermissions::PERM_GET);
- $route->post("$prefix/permissions/add/$permission_name/$permission_value", "${ns}LuticatePermissionsController",
- "add", array(LuticatePermissions::PERM_ADD, LuticatePermissions::PERM_GET));
- $route->post("$prefix/permissions/$permission_name/del", "${ns}LuticatePermissionsController", "del",
- array(LuticatePermissions::PERM_DEL, LuticatePermissions::PERM_GET));
- $route->post("$prefix/permissions/$permission_name/edit/$permission_value", "${ns}LuticatePermissionsController",
- "edit", array(LuticatePermissions::PERM_EDIT, LuticatePermissions::PERM_GET));
-
- $route->get("$prefix/permissions/group/$group_id/$permission_name", "${ns}LuticatePermissionsGroupsController",
- "get", LuticatePermissions::PERM_GROUP_GET);
- $route->get("$prefix/permissions/group/$group_id", "${ns}LuticatePermissionsGroupsController",
- "getAllByGroup", LuticatePermissions::PERM_GROUP_GET);
- $route->post("$prefix/permissions/group/$group_id/add/$permission_name/$permission_value",
- "${ns}LuticatePermissionsGroupsController", "add", array(LuticatePermissions::PERM_GROUP_ADD,
- LuticatePermissions::PERM_GROUP_GET));
- $route->post("$prefix/permissions/group/$group_id/$permission_name/del",
- "${ns}LuticatePermissionsGroupsController", "del", array(LuticatePermissions::PERM_GROUP_DEL,
- LuticatePermissions::PERM_GROUP_GET));
- $route->post("$prefix/permissions/group/$group_id/$permission_name/edit/$permission_value",
- "${ns}LuticatePermissionsGroupsController", "edit", array(LuticatePermissions::PERM_GROUP_EDIT,
- LuticatePermissions::PERM_GROUP_GET));
-
- $route->get("$prefix/permissions/user/$user_id/$permission_name", "${ns}LuticatePermissionsUsersController",
- "get", LuticatePermissions::PERM_USER_GET);
- $route->get("$prefix/permissions/user/$user_id", "${ns}LuticatePermissionsUsersController",
- "getAllByUser", LuticatePermissions::PERM_USER_GET);
- $route->post("$prefix/permissions/user/$user_id/add/$permission_name/$permission_value",
- "${ns}LuticatePermissionsUsersController", "add", array(LuticatePermissions::PERM_USER_ADD,
- LuticatePermissions::PERM_USER_GET));
- $route->post("$prefix/permissions/user/$user_id/$permission_name/del", "${ns}LuticatePermissionsUsersController",
- "del", array(LuticatePermissions::PERM_USER_DEL, LuticatePermissions::PERM_USER_GET));
- $route->post("$prefix/permissions/user/$user_id/$permission_name/edit/$permission_value",
- "${ns}LuticatePermissionsUsersController", "edit", array(LuticatePermissions::PERM_USER_EDIT,
- LuticatePermissions::PERM_USER_GET));
- }
- }
|