Backpack with Multi tenancy - laravel-backpack

i am creating an ERP system with multi tenant with different db and has sub-domain for tenants.
i am using the stancl\tenancy for the multi tenant package
I have a main domain for creating and adding companies
Normally, when i load users in my tenant's sub-domains ex.(foo.maindomain.com), it is only showing the users table in the tenant's db. But with the backpack dashboard in permission manager it is showing the Users in the main database instead of the user in the tenant's own database.
Is there someone who has experience this and can help me with this problem?
your help will be much appreciated, Thank you in advance

The docs for that tenancy package show that they use a various middlewares that set the tenant for the application. Based on your question, Ill assume you're using the Subdomain identification middleware in your app.
The issue is most likely that your Backpack permissions routes are not using this middleware.
If we look at Backpack's docs, they say this about the permissions routes:
If you need to modify how this works in a project:
create a routes/backpack/permissionmanager.php file; the package will see that, and load your routes file, instead of the one in the package;
To fix the issue, create a file at allin.com/routes/backpack/permissionmanager.php copy the contents from vendor/backpack/permissionmanager/src/routes/backpack/permissionmanager.php, paste that in the new file and add the middleware needed for the tenancy app, which should look something like:
Route::group([
'namespace' => 'Backpack\PermissionManager\app\Http\Controllers',
'prefix' => config('backpack.base.route_prefix', 'admin'),
'middleware' => ['web', InitializeTenancyBySubdomain::class, backpack_middleware()],
], function () {
Route::crud('permission', 'PermissionCrudController');
Route::crud('role', 'RoleCrudController');
Route::crud('user', 'UserCrudController');
});

Related

Giving no-admin users access to Template module

I'm setup a TYPO3 website and I need to give a user group the permission to view and edit to the Template module.
On the TYPO3 documentation I found this information :
If you cannot see the Template module, it may be that you are not
logged in as an administrator. Please change user and make sure you
use one with administrator rights.
There is no a work-around to give backend users access to the Template
module ?
No possibility except you xclass core methods.
Maybe there is another solution to your problem.
Please state why an editor should have access to the template module.
I was able to make the "Web -> Template" module accessible to non-administrators
typo3\sysext\frontend\Configuration\TCA\sys_template.php
Change line 16:
'adminOnly' => true,
to
'adminOnly' => false,
Now, you can Edit Backend usergroup and check the option Template [sys_template] on Tables (listing) and Tables (modify)

Slim Framework and Auth0

Not worked with PHP for close on 10 years now, so very out of touch. I have a a project I am working on that requires a web front end with secure authentication. There is no need for API's at all.
Auth0 meets the requirements from an authentication point of view, and provides a lot of options.
What I cant find is how to integrate this with Slim Framework, can anyone point me in the right direction?
Background on the app, I am collating information from multiple API sources into a database and want to display this out and add some more functionality. Currently most of this is displayed on Grafana dashboards around the office, but there are some new requirements for this which cant be solved with dashboards.
Slim looks like the right tool for me, I need something that allows me to create pages quite easily where I will be in effect displaying a few graphs but mostly tables and forms to interact with the data. If Slim is not the right fit, happy to look elsewhere.
Thanks
According to the official Auth0 documentation I would try a setup in Slim 3 like this:
Installation
composer require auth0/auth0-php
Container Setup
Add a new container factory entry:
use Auth0\SDK\Auth0;
use Psr\Container\ContainerInterface as Container;
//...
$container[Auth0::class] = function (Container $container) {
return new Auth0([
'domain' => 'YOUR_DOMAIN',
'client_id' => 'YOUR_CLIENT_ID',
'client_secret' => 'YOUR_CLIENT_SECRET',
'redirect_uri' => 'https://YOUR_APP/callback',
'audience' => 'https://YOUR_DOMAIN/userinfo',
'scope' => 'openid profile',
'persist_id_token' => true,
'persist_access_token' => true,
'persist_refresh_token' => true,
]);
};
Usage
The user's information is stored in the session. Each time you call getUser(), it retrieves the information from the session.
use Auth0\SDK\Auth0;
$auth0 = $container->get(Auth0::class);
$userInfo = $auth0->getUser();
if (!$userInfo) {
// We have no user info
// redirect to Login
} else {
// User is authenticated
// Say hello to $userInfo['name']
// print logout button
}
Note: Don't use the container directly. In reality it's better to use dependency injection.
"but mostly tables and forms to interact with the data"
aside from your graphs to be displayed if the above is the main requirement then I would also recommend you look at Yii Framework (a PHP framework)
In particular looking at Gii - a code generator that builds, exceptionally quickly, CRUD forms and tables...

Redirect dynamically created subdomains to main page in Laravel 5.3

I am working on multi-tenant approach. I created a new tenant with all its information in database including its sub-domain. My approach is separate database and separate sub-domains for each customer. So, I am creating a sub-domain on button click and saving it in database. Now, I am lost on my way how to redirect that sub-domain to main page. I just need to redirect it to main page nothing else, I will work on separate db connection later. I also created the wildcard subdomain entry from cpanel. I am working on wildcard domains for the first time and also I am on my way of learning laravel.
Here is my code:
routes/web.php
Route::group(array('domain' => '{account}.example.com/tracker'), function()
{
Route::get('/', 'HomeController#index');
});
HomeController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function index()
{
return view('welcome');
}
}
I know there are lot of things missing that's why its not working but I tried many solutions I found on google and stackoverflow but still I am unable to figure out what I am doing wrong. Please help me how to overcome this issue. Also, please if anyone have good tutorial on this topic, please share that with me.
Thank you
I solved my problem by using this solution on stackoverflow.
Allow multiple subdomain in laravel without making subdomain as route variable?
It worked like a charm. Hope it helps someone.
Thank you.

Set Site Permissions for a Role Programmatically Liferay 6.2

I am creating a startup hook script for liferay to add and preconfigure Roles for Liferay 6.2 behind the scenes.
Specifically I am looking to add the type of permissions that can be accessed through Control Panel > Roles > Actions> Define Permissions.
Currently I am able to add Liferay Roles, but have so far been unsuccessful in finding the correct way to add custom permissions to the Roles programmatically. I see there was a way to do this in prior Liferay versions, but do not see it here.
https://www.liferay.com/community/forums/-/message_boards/message/2965424
https://www.liferay.com/web/guest/community/forums/-/message_boards/message/124558
So far I have investigated RolePermissionUtil, RoleLocalServiceUtil, among other available services.
Let me know if this is available through the service to be added to a startup hook or if this can only be done in the UI.
It appears that the API has changed since these posts.
Thank you in advance for your help
Figured it out using ResourcePermissionLocalServiceUtil.setResourcePermissions and RoleLocalServiceUtil.
Eg.
RoleLocalServiceUtil.fetchRole(CompanyThreadLocal.getCompanyId(), "Role Name");
ResourcePermissionLocalServiceUtil.setResourcePermissions(CompanyThreadLocal.getCompanyId(), Role.class.getName(), ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(role.getRoleId()), role.getRoleId(), new String[] {ActionKeys.VIEW, ActionKeys.UPDATE, ActionKeys.DELETE});
I used CompanyThreadLocal to obtain the Company Id because I am using this in a hook not a portlet, where typically it would be accessed through the theme display. Here I am just adding access to Roles, but other class namespaces could be added. (eg. "com.liferay.portlet.dynamicdatalists.model.DDLRecordSet")

Zend Framework 2 Doctrine ORM Authentication

I'm developing my first real project with ZF2 and Doctrine ORM. And I cannot find any good example of user authentication through doctrine orm authentication adapter. Now I'm using standard Zend Db Adapter authentication. In addition, I use
$adapter->setIdentityColumn(filter_var($request->getPost('useremail'),FILTER_VALIDATE_EMAIL) ? 'useremail' : 'userlogin');
in my login controller to login either via email and login.
But I want to perform all job through doctrine ORM. Could someone show me a similar example with doctrine.authentication.orm_default and storing user identity data in session/storage to access in any controller or module.php? Is it possible to use two fields - userlogin or email for login?
Thank you in advance for your help.
Updated: I kept seaching and as a result this and this helped me so much
One problem, that i haven't solved yet. How can I check user status (activated or not) with doctrine adapter?
Like
$authAdapter = new AuthAdapter($dbAdapter,'user','username','password','MD5(?) AND status = 1');
You can use credential_callable option (Doctrine Module doc.). It can be any callable (PHP Manual), for example with closure:
'credential_callable' => function(User $user, $passwordGiven) {
return md5($passwordGiven) == $user->getPassword() && $user->isActive();
},
or with static class method:
'credential_callable' => 'Application\User\UserService::verifyUser'
What about an external module idea? If you are OK with that you can take a look at https://github.com/ZF-Commons/ZfcUser and https://github.com/SocalNick/ScnSocialAuth or the whole modules repositories http://modules.zendframework.com/?query=user. Even if you don't install just download and see what other people do stuff.