mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
nastools approve
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Repositories;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\UnauthorizedException;
|
||||
|
||||
@@ -38,4 +39,25 @@ class AuthenticateRepository extends BaseRepository
|
||||
$result = $user->tokens()->delete();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function nasToolsApprove(string $json)
|
||||
{
|
||||
$key = env('NAS_TOOLS_KEY');
|
||||
$encrypter = new Encrypter($key);
|
||||
$decrypted = $encrypter->decryptString($json);
|
||||
$data = json_decode($decrypted, true);
|
||||
if (!is_array($data) || !isset($data['uid'], $data['passkey'])) {
|
||||
throw new \InvalidArgumentException("Invalid data format.");
|
||||
}
|
||||
$user = User::query()
|
||||
->where('id', $data['uid'])
|
||||
->where('passkey', $data['passkey'])
|
||||
->first()
|
||||
;
|
||||
if (!$user) {
|
||||
throw new \InvalidArgumentException("Invalid uid or passkey.");
|
||||
}
|
||||
$user->checkIsNormal();
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user