Email verification added
This commit is contained in:
parent
ca9e516315
commit
0181349fc5
|
|
@ -208,9 +208,48 @@ public function register(Request $request){
|
|||
$tokenResult = $client->createToken('auth_token');
|
||||
|
||||
// return token in json response
|
||||
return response()->json(['success' => ['token' => $tokenResult]], 200);
|
||||
return response()->json(['success' => ['token' => $tokenResult, 'client' => $client]], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\POST(
|
||||
* path="/api/verify-email",
|
||||
* summary=" - Verify email of client",
|
||||
* tags = {"Authorization"},
|
||||
* @OA\RequestBody(
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(
|
||||
* @OA\Property(
|
||||
* property="email",
|
||||
* type="string",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="token",
|
||||
* type="string",
|
||||
* ),
|
||||
* example={"email": "ilmedovamahri@gmail.com", "token": "4515"}
|
||||
* )
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
* description="OK"
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="400",
|
||||
* description="Missing fields (email or token)"
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="404",
|
||||
* description="Client not found"
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="401",
|
||||
* description="Unauthorised. Tokens do not match"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function verifyEmail(Request $request){
|
||||
$data = $request->all();
|
||||
if(count($data) < 2){
|
||||
|
|
@ -218,7 +257,25 @@ public function verifyEmail(Request $request){
|
|||
'message' => 'Oops! Email or code missing'
|
||||
],400);
|
||||
}
|
||||
$client = Client::where('email', $data['email'])->first();
|
||||
|
||||
if($client){
|
||||
if($client->token == $data['token']){
|
||||
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);
|
||||
}
|
||||
else{
|
||||
return response()->json(['error' => ['message' => 'tokens don\'t match']], 401);
|
||||
}
|
||||
}
|
||||
else{
|
||||
return response()->json(['error' => ['message' => 'no such client']], 404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
Route::post('/login', [AuthController::class, 'login']);
|
||||
Route::post('/reset-password', [AuthController::class, 'updatePassword']);
|
||||
Route::post('/forgot-password', [AuthController::class, 'sendPasswordResetLinkEmail']);
|
||||
Route::post('/verify-email', [AuthController::class, 'verifyEmail']);
|
||||
Route::get('/users', [TestController::class, 'users']);
|
||||
|
||||
Route::middleware(['auth.client','auth:api'])->group(function () {
|
||||
|
|
|
|||
|
|
@ -89,6 +89,50 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/verify-email": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"Authorization"
|
||||
],
|
||||
"summary": " - Verify email of client",
|
||||
"operationId": "200ade402157108a4de2cc69e35ee0bf",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"example": {
|
||||
"email": "ilmedovamahri@gmail.com",
|
||||
"token": "4515"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"400": {
|
||||
"description": "Missing fields (email or token)"
|
||||
},
|
||||
"404": {
|
||||
"description": "Client not found"
|
||||
},
|
||||
"401": {
|
||||
"description": "Unauthorised. Tokens do not match"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/client": {
|
||||
"get": {
|
||||
"tags": [
|
||||
|
|
|
|||
Loading…
Reference in New Issue