validator registration fixed
This commit is contained in:
parent
0181349fc5
commit
c7577ef163
|
|
@ -139,9 +139,46 @@ public function login(Request $request){
|
|||
* )
|
||||
*/
|
||||
public function register(Request $request){
|
||||
$email_verification = Config::get('email_verification');
|
||||
try{
|
||||
$email_verification = Config::get('email_verification');
|
||||
|
||||
if($email_verification){
|
||||
$validatedData = request()->validate([
|
||||
'email' => 'required',
|
||||
'password' => 'required|min:6',
|
||||
'firstname' => 'required',
|
||||
'lastname' => 'required',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
// hashing client's passord
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
|
||||
$token = rand(1000, 9999);//generate code
|
||||
|
||||
$data['token'] = $token;
|
||||
$data['is_verified'] = 0;//is_verified is false until i checke the code sent to mail of the client
|
||||
|
||||
// set client's status to false (Admin will set the client's status from Admin Panel)
|
||||
$data['status'] = false;
|
||||
|
||||
$client = Client::where('email', $data['email'])->first();
|
||||
if($client){
|
||||
return response()->json([
|
||||
'error' => 'This email is already used'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$client = Client::create($data);
|
||||
Mail::to($request->email)->send(new EmailVerification($client->firstname, $token));
|
||||
|
||||
return response()->json([
|
||||
'message' => 'confirmation code sent',
|
||||
'email' => $client->email
|
||||
],200);
|
||||
}
|
||||
|
||||
if($email_verification){
|
||||
$validatedData = request()->validate([
|
||||
'email' => 'required',
|
||||
'password' => 'required|min:6',
|
||||
|
|
@ -154,11 +191,6 @@ public function register(Request $request){
|
|||
// hashing client's passord
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
|
||||
$token = rand(1000, 9999);//generate code
|
||||
|
||||
$data['token'] = $token;
|
||||
$data['is_verified'] = 0;//is_verified is false until i checke the code sent to mail of the client
|
||||
|
||||
// set client's status to false (Admin will set the client's status from Admin Panel)
|
||||
$data['status'] = false;
|
||||
|
||||
|
|
@ -170,45 +202,18 @@ public function register(Request $request){
|
|||
}
|
||||
|
||||
$client = Client::create($data);
|
||||
Mail::to($request->email)->send(new EmailVerification($client->firstname, $token));
|
||||
|
||||
return response()->json([
|
||||
'message' => 'confirmation code sent',
|
||||
'email' => $client->email
|
||||
],200);
|
||||
Auth::login($client);
|
||||
|
||||
// get new token
|
||||
$tokenResult = $client->createToken('auth_token');
|
||||
|
||||
// return token in json response
|
||||
return response()->json(['success' => ['token' => $tokenResult, 'client' => $client]], 200);
|
||||
}
|
||||
|
||||
$validatedData = request()->validate([
|
||||
'email' => 'required',
|
||||
'password' => 'required|min:6',
|
||||
'firstname' => 'required',
|
||||
'lastname' => 'required',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
// hashing client's passord
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
|
||||
// set client's status to false (Admin will set the client's status from Admin Panel)
|
||||
$data['status'] = false;
|
||||
|
||||
$client = Client::where('email', $data['email'])->first();
|
||||
if($client){
|
||||
return response()->json([
|
||||
'error' => 'This email is already used'
|
||||
], 401);
|
||||
catch(\Exveption $e){
|
||||
return response()->json(['error' => ['message' => $e->getMessage()]], 400);
|
||||
}
|
||||
|
||||
$client = Client::create($data);
|
||||
|
||||
Auth::login($client);
|
||||
|
||||
// get new token
|
||||
$tokenResult = $client->createToken('auth_token');
|
||||
|
||||
// return token in json response
|
||||
return response()->json(['success' => ['token' => $tokenResult, 'client' => $client]], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue