Last active
April 19, 2020 20:15
-
-
Save tobyokeke/a438d190e0bbf4215c65acdac5dd03db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function signIn(Request $request) | |
{ | |
$email = $request->input('email'); | |
$password = $request->input('password'); | |
$rules = [ | |
'email' => 'required|email:rfc,dns|max:255', | |
'password' => ['required'], | |
]; | |
$validator = Validator::make($request->all(), $rules,$this->validationMessages()); | |
if ($validator->fails()) {return response()->json(["message" => $validator->errors()->first()],400);} | |
if(customer::where('email',$email)->count() <= 0 ) return response( array( "message" => "Email number does not exist" ), 400 ); | |
$customer = customer::where('email',$email)->first(); | |
if(password_verify($password,$customer->password)){ | |
$customer->last_login = Carbon::now(); | |
$customer->save(); | |
return response( array( "message" => "Sign In Successful", "data" => [ | |
"customer" => $customer, | |
// Below the customer key passed as the second parameter sets the role | |
// anyone with the auth token would have only customer access rights | |
"token" => $customer->createToken('Personal Access Token',['customer'])->accessToken | |
] ), 200 ); | |
} else { | |
return response( array( "message" => "Wrong Credentials." ), 400 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment