I have a controller that displays a page depending on whether a user has already signed up for something when initially registering for the site.
If their organisation has already been registered, the page shows their profile which they can edit etc. (That bit works fine)
But if they haven't the page is supposed to show a registration page where they can sign up
I've done this using:
$this->call('\Controllers\RegisterOrgController');
The user has an option of a free basic package, or a premium/premium plus package, which will require the user to be redirected to a payment page. My problem is, while this does show the registration page, it just registers the organisation when they choose 'premium' or 'premium plus' and doesn't show a payment page.
I know that it would be best to extend the organisation registration page from the profile page to get it to use the functionality; however, as the organisation profile page is primarily supposed to display a profile, I have it extending its own controller (from my recollection, you can't extend two classes) and using the register organisation controller to display the form.
I've seen ways to redirect pages in javascript, angularJS asp.net/C# but none of them have worked so far when adapted for PHP
I was thinking of setting the header:
header('location: ' . [function to get URL for new location]);
But this wouldn't work as the path is a subpath (register/organisation) and 'register' cannot be viewed if the user is logged in and the organisation profile has its own path name (organisation-profile).
TL;DR: it there a way to display a page by calling a controller that does this from another controller and still have the functionality, despite having a different path
Any help would definitely be appreciated,
Thanks in advance!
Ok, so I figured out what I was doing wrong when it comes to the registration flow.
My idea was ok, but the execution was terrible, so I thought I'd share the solution just in case anyone was having a similar issue (although this may be statistically unlikely)
The Problem
The registration process allowed the user to register an organisation either when they initially registered for the site, or after they had signed up and had their account verified.
The registration page was not supposed to be view-able if the user was logged in; however, the organisation registration page stemmed from this page, which was causing a conflict as the paths were different.
The Solution
Change the organisation profile controller to redirect to the organisation registration page instead of calling the registration controller.
Change the registration controller to show the page even if the user is logged in to keep the registration flow
In the go() function check the subpath of the page and if it is 'register', run the unauthenticated function to make sure the registration form doesn't ever show when logged in. This will allow you to follow the registration flow for an organisation but not have the registration page appear.
Hope this helps anyone having a similar problem with their registration flow!
Related
I am making a small webpage with Laravel that has User and Admin roles.
My 'users' table consists of name, email, password and role value (0 for user, 1 for admin).
I dont need anything fancy so can I just make it so every time a normal user loads in a page that's meant for the administrator - he gets redirected?
To be more precise: How can I make it so whenever a new page loads, the users role gets checked and then my if or can statement checks if the users allowed to access the page?
For example I have a view:
results that displays all the match results(can be accessed by everyone) and I also have an admin/RESULTSadmin view, that should only be accessed by a user that has an admin role but the rest needs to get redirected. Thank you in advance!
You can make parent controller with method which should check what you need and extend your controller from that (kind of old way but most simplest)
Another option make some middleware to check access
Also please take a look on laravel auth mechanism : https://laravel.com/docs/9.x/authentication#password-confirmation-protecting-routes
E.g. My site has two subdomains : first_domain and second_domain.
And My site has three roles:admin, site-manager, editor.
I hope:
User with admin can login first_domain, can't login second_domain. (When user visit second_domain user status is not logined and not lost first_domain logined status)
User with site-manager can login second_domain, can't login first_domain.
User with editor can login first_domain and second_domain.
Does anyone have any solution?
Take a look at this module, i think it would help you, you might have to twist a configuration based on requirement but could be good base module.
https://www.drupal.org/project/domain_roles
You need to manage session in every domain and check that if one user is login in first domain and session is created then the second user redirects to a page where it say already login.
I cannot write a code here for you for making sessions. You can create session in php.
Let me know if you are not able to understand the logic.
I am stuck in a problem.
I have a Yii shopping cart only for registered users. I have added a facebook share button in it.
But when I am sharing any product, I am not able to get the product image or any details.
Instead I am getting the details from the login page.
I have checked the link in the facebook debug tool(https://developers.facebook.com/tools/debug).
It show
Fetched URL as original URL(URL for sharing and for fetching the
contents)
Canonical URL as /user/login
Seems like the product page is checked but was redirected to the login page from where the details like
og:url, og:type, og:title, og:image etc are called from the login page.
Is there any method to keep the authentication and allow the facebook to share the details?
I think the problem can be solved within the Yii coding itself.
Thanking you in advance.
This is how sharing on facebook works:
When you share a link on Facebook, Twitter or any such service, the service crawls the shared page URL for fetching the metadata.
When you share an URL that is only accessible for authenticated users, there is no way for the crawlers to reach your URL. In Yii Framework, the request is redirected automatically to Login Page which is what the crawlers will see in your case.
Here is how we solved it in one of our previous application:
Added a different action for guest view for the particular page and redirect any non authenticated requests from main action to the guest view action. The guest view action will be similar to the main action except that the user will not be able do any actions here.
Example:
public function actionView(){
if($isGues){
//redirect to public function actionGuestview(){}
}
// Your Existing code to render the view file.
}
public function actionGuestView(){
// Code to render the public view of the above action.
// Make sure that the user cannot perform any actions here.
}
I'm building a SaaS with Symfony 2. Currently I'm adding registration of users to the application, but I don't know how to start.
I have no problems with basic user registration and login, my problem is another: When a user logs into the system, he must fill his company information. Even if the user goes to another URL, he must be redirected to the company information screen and he can't continue until he fills the company data. And the truth is that I have no idea of how to do this.
Can you help me, please? I know that I can add some checks to all of the controllers, but this is just an ugly hack...
If the company information is important, add those fields to the register page. Don't create the account until all fields are filled.
Hard to answer without knowing anything about your application architecture. There's more than one way to do it.
One possible solution would be as long as the user did not fully fill out all the required information his account is locked, so whenever he tries to get onto another URL the access is denied (so essentially you've got three user states in your database or session storage or whatever) unless he enters his profile page and fills out all the requried information.
If he did so, his status changes to a "fully valid" user and he can login and browser the page however he likes.
So you don't have to check it on every page - just check if the user is logged in, locked or logged out.
If you have some kind of groups or roles in your application you could put your user into the "invalid" or "notcomplete" group which has basically no access to the application's pages.
I have created a login system (with help from people on this site) that redirects a logged in user to several pages that only they have access to based on their login information. When navigating the site they will also have access to other pages that all logged in users have access to.
This information is in a msql database and uses php redirect. The system has a small area to show a logged in users name and a logout option. Using sessions this is shown on whatever page the user views whether it is their personal page or a general page open to any logged in user. What I would like to do is to create a “go back to personal page” link (in the same panel as the logout and user name) so whoever is logged in will have a quick link back to their personal page.
I am quite new to PHP and I am sure there is a very simple way to uses the login information and the redirect function to create a clickable text link to achieve this but I have not found a way to do this. I would appreciate help from anyone who could point me in the right direction.
Depends on how the personal page is setup. But no matter what, you should need nothing more than a HTML link...
Go back to personal page
where personal.php is the name of the file that you want to send the user to. Now if you do things with the user's ID, you might have something like
Go back to personal page
where $userid is the variable that contains the user's ID.
So essentially, how do you currently view the user's profile? Put that link in an <a> tag.