Skip to content

Commit

Permalink
add api for iyuu approve
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Sep 2, 2023
1 parent d4648cd commit b4d4d8f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ UID_STARTS=10001

PHP_PATH=
NAS_TOOLS_KEY=
IYUU_SECRET=

MEILISEARCH_SCHEME=http
MEILISEARCH_HOST=127.0.0.1
Expand Down
17 changes: 16 additions & 1 deletion app/Http/Controllers/AuthenticateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Validation\Rule;

class AuthenticateController extends Controller
{
Expand Down Expand Up @@ -80,5 +81,19 @@ public function nasToolsApprove(Request $request)
return $this->success($resource);
}


public function iyuuApprove(Request $request)
{
try {
$request->validate([
'token' => 'required|string',
'id' => 'required|integer',
'verity' => 'required|string',
'provider' => ["required", "string", Rule::in("iyuu")],
]);
$this->repository->iyuuApprove($request->token, $request->id, $request->verity);
return response()->json(["success" => true]);
} catch (\Exception $exception) {
return response()->json(["success" => false, "msg" => $exception->getMessage()]);
}
}
}
12 changes: 12 additions & 0 deletions app/Repositories/AuthenticateRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ public function nasToolsApprove(string $json)
$user->checkIsNormal();
return $user;
}

public function iyuuApprove($token, $id, $verity)
{
$secret = env('IYUU_SECRET');
$user = User::query()->findOrFail($id, User::$commonFields);
$user->checkIsNormal();
$encryptedResult = md5($token . $id . sha1($user->passkey) . $secret);
if ($encryptedResult != $verity) {
throw new \InvalidArgumentException("Invalid uid or passkey");
}
return true;
}
}
1 change: 1 addition & 0 deletions routes/third-party.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
use Illuminate\Support\Facades\Route;

Route::post('nastools/approve', [\App\Http\Controllers\AuthenticateController::class, 'nasToolsApprove']);
Route::GET('iyuu/approve', [\App\Http\Controllers\AuthenticateController::class, 'iyuuApprove']);

0 comments on commit b4d4d8f

Please sign in to comment.