I have a two tables in database
1. users(default user table)
2. suspend_users(only two column:- id, email)
now i want to first check in the "suspend_user" table user email exist or not if user email exist in the "suspend table" authentication failed message shows.
now i do not understand that how to check second table(suspend_users) first and how to check multiple table authenticate
I dont understand exactly what you mean, you can check first if the mail exists on the suspend_table and after check login:
example:
if (SuspendedUser::findBy(['email' => $user_email])) {
// go back to what else... throw expetion etc....
}
if (Auth::attempt(email, pass)) {} // check login
you can easily authenticate multiple table in laravel 5.1 and above.
http://blog.sarav.co/multiple-authentication-in-laravel/
Related
I am trying to set up RLS to a table in Supabase that will only allow the authenticated user to UPDATE their row on users table. I have opted to use Supabase on my server rather than the front-end. My current workflow is as follows:
Client requests a OTP via email
User is emailed an OTP
OTP is entered into the Client
OTP is verified on the server
If verified UPDATE the users row in the users table with new session details
Return the current user details to the Client
Here is the code that is failing:
const { error } = await supabase
.from('users')
.update({
access_token: session.access_token,
refresh_token: session.refresh_token,
expires_at: session?.expires_at || 0
})
.eq('user_id', user.id)
.single();
Here is the table structure:
When I run const user = supabase.auth.user(); I am showing the correct user that has a user.id that matches the rows user_id column of the row I want to UPDATE.
Without RLS set up this workflow is working perfectly. Anything I try fails. Below are the three RLS that I have tried that should work.
Checking if user exists WHERE auth.uid() = users.user_id in both USING and CHECK
Added auth.uid() = user_id in both USING and CHECK
The weirdest one of the all, set true in both USING and CHECK
Here are screen shots of the uuid on the auth.users table and user_id on the users table:
Attempted this from one of the answers and it is still failing:
Here is the error response I am receiving from Supabase:
This is not very well documented yet, but signed in users have authenticated role, and not anon role, so changing the target role to authenticated should fix it. When in doubt, just leave the target roles blank, which will apply the RLS on all roles.
I am new to laravel and do not have much experience with using ORM. I am building a system in which I need build functionality to allow user to switch clients with another user. I am not sure what is the best method to achieve this.
Currently client belongs to user, do I need another association for client and user model using different foreign key ?
public function clients()
{
return $this->hasMany('App\Client');
}
public function user()
{
return $this->belongsTo('App\User');
}
Even though a client can only have one user switch request I would like to track all the requests so for example if user A makes request to switch client Test with user B and then make another request to switch the same client with user C I would like to soft delete the first record and create new record for new request. Once the other user accepts the request we change the primary key for client Test in the clients table. Will this be a One To Many / Many To Many relationship ?
What table naming conventions do I need to follow ? Any help will be much appreciated.
If I understand you correctly, you would like to temporarily switch clients for one user to another. What you should do is have another table say switched-clients that holds records for the switches with columns user1 and user2. When you want to retrieve clients, your controller checks this table first and if the record exists where('user1', 'user A') (according to your example), then you retrieve the clients for user2.
I would like to ask about logging in to Laravel but in a different way:
User information including the password but not the email will be stored in users table, while email_address will be stored in a email_addresses table with a boolean field called is_default.
So the user can have several emails, but he can log in with only one email that has the is_default is true. and he could change his default email through his profile.
So, how can I make the login process through the Auth::login() facade.
I was able to register the user by storing the information in a users table and store his email_address and is_default = true in the email_addresses table.
It can be a little tricky. Auth::login() just needs to fetch email and password, so if you can trick the model into thinking it has an email field accessible via $user->email, things will work out:
public function getEmailAttribute()
{
return DB::table('email_addresses')->whhere('default', 1)->where('user_id', $this->id)->first()->toArray()['email'];
}
I have used laravel boilerplate for login.
I have worked using virtual host and put information on basis of virtualhost.
I have 2 tables:
1. users
2. social_logins
Actually i am authenticating from users table. I need to store information in users and then link it with social_logins user_id i.e, store information in table 2.
The main problem here is it doesn't store data in table. This line is not working:
return $this->getAuthorizationFirst($provider);
I have put redirect so it will redirect to given route but doesn't store data in database.
if I catch callback in controller I can catch the information.
$user = Socialite::driver('facebook')->user();
I have done normally using Socialite plugin in normal laravel, but i don't have any idea in Boilerplate.
Actual lifecycle of this loginThirdParty trait is:
1 The first time this is hit, request is empty
2 It's redirected to the provider and then back here, where request is populated
3 So it then continues creating the user
So If the provider is not an acceptable, this trait kick back. Hopefully you need to recheck your .env for FACEBOOK_CLIENT_ID, FACEBOOK_CLIENT_SECRET and CALLBACK_URL.
I have created a joomla component where we can upload the csv file which contain the user name and email of many users.I have written query for inserting the data to the jos_users table.The password in auto generated and i have encrypted the password using
$crypt = JUserHelper::getCryptedPassword("blabla", $salt);
I haven't inserted anything in the activation field.
But due to some reasons I cannot login using the username and the password.Should I do any thing else for this ?
Thanks Brent for your time.I have found the answer and is explained below.
For creating new user accounts by script you need to execute three queries.
1)
insert into jos_users (id,name,username,email,password,usertype,block,sendEmail,gid,registerDate,lastvisitDate) values (NULL,'name','username','email','password','Registered','0','0','18','date','date2')
2)
insert into jos_core_acl_aro (id,section_value,value,name) values (NULL, 'users', '(insertid of the above query)', 'name')
3)
insert into jos_core_acl_groups_aro_map (group_id,section_value,aro_id) values (18, '', '(insertid of the above query)')
This worked for me.
In order for a user to be able to log in -
activation field must be blank
user must be enabled
user must be a member of a group