1
votes

I'm currently developing a website with Laravel, where users can register and afterwards login in order to do something on my page.

Now, I'm planning to introduce the possibility to proceed as a guest, so they can "Login as Guest" and then proceed like a normal user (but without the possibility to permanently save information they enter there). Also, they should be always able to change this Guest account to a permanent account by entering their mail-address as well as a password. I thought about simply creating a new user in db when clicking on login as guest, like a normal registered user and afterwards deleting it, but I'm not sure if that is possible to easy... Is there any way to "easily" do this or do you have any ideas on how to do it?

The registered user should be able to do lots of things like changing their addresses, informations, submit a ticket, sign up for newsletter, etc..., guests will only be able to put something in their shopping cart and buy it (and while buying they should be able to create a account as well..) Also I know that I might need to implement a custom guard to authentificate a guest user (because normally they will need a password, I only want them to enter their mail adress to "log in". But ofcourse I need a session key to be generated etc., so this is the guards part then... But what do I need to do to create such a custom guard that fullfills my issues? I found the laravel doc for this (https://laravel.com/docs/5.3/authentication#adding-custom-guards), but can't really combine it with my problem....

PS: I'm using Laratrust for different roles within the page, so with that I might be able to show different menus or other information for a guest user after logging in with their mail adress. But still, the question is how to do it... Thx for any help!

Edit: After thinking about it again, I want to get it a bit clearer. I basically plan to change the login page and add a button like "proceed as guest" and define a route like guestLogin for it. This route would point to a controller that somehow logs in using a (propably selfmade) auth. When clicking the button, a entry is added into the users table in my database, with only an idea and a remember token. Then, the guest user can place products in his shopping cart and can order something. In the order process, he needs to enter his personal information like his adress, email-adress, etc. He then also has the option check a checkbox to automatically register then by entering a password. Then his information is saved into the db as well (on the row created for the guest user).

PS: Again on Laratrust, I would create a guest role to show exactly the pages I want him to show, as well as custom checkout pages. So the only real problem is the login (by a custom auth guard, which I have no idea how to implement it) as well as later on registering for a user basically already existing (even if its just the ID in db so far).

I hope you got my idea.

1
I think it is not good to provide same flow of registered user to guest user there is adifference for guest and registered one..Soniya Basireddy
@Sona they won't have the same possibilites, the registered user should be able to do lots of things like changing their addresses, informations, submit a ticket, sign up for newsletter, etc..., guests will only be able to put something in their shopping cart and buy it (and while buying they should be able to create a account as well..)nameless
yeah based on requirement we need to restrict the guest ..Soniya Basireddy
maintain roleid for registered and guest user in the same table while registering based on that you can make an access to they people.Soniya Basireddy

1 Answers

1
votes

Authentication and Authorisation works around saving and remembering user who is requesting an resource from server. To be able to remember, you have to either use session or a database or any other storage mechanism.

You must be taking enough user information to identify the guest user, eg. email, as they are going to perform some operations and later, we have to find the user who has made changes in current state of the data/application.

Store this email or other information in database's 'user' table or create a guest role with Laratrust. It's just a simple guest role, who can perform operations with basic details, with out entering password.

See if this helps, otherwise we can dive into more detailed discussion.