mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
add api for iyuu approve
This commit is contained in:
@@ -81,6 +81,7 @@ UID_STARTS=10001
|
||||
|
||||
PHP_PATH=
|
||||
NAS_TOOLS_KEY=
|
||||
IYUU_SECRET=
|
||||
|
||||
MEILISEARCH_SCHEME=http
|
||||
MEILISEARCH_HOST=127.0.0.1
|
||||
|
||||
@@ -13,6 +13,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AuthenticateController extends Controller
|
||||
{
|
||||
@@ -80,5 +81,19 @@ class AuthenticateController extends Controller
|
||||
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()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,4 +60,16 @@ class AuthenticateRepository extends BaseRepository
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user