登录校验

This commit is contained in:
2022-11-01 13:28:08 +08:00
parent c23de98690
commit 719a9ff89d
8 changed files with 583 additions and 7 deletions

View File

@@ -4,15 +4,30 @@ namespace App\Api\Controllers;
use App\Api\Resources\AuthResource;
use App\Models\User;
use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress;
use BitWasp\Bitcoin\Key\Factory\HierarchicalKeyFactory;
use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39SeedGenerator;
use Illuminate\Http\Request;
class AuthController extends Controller
{
public function login(Request $request)
{
$address = $request->address;
$address = $request->address;
$mnemonic = $request->mnemonic;
$address = '12dUut3dG5xWi6JPDMjSSK6s2JPcfeKYL1';
// $address = '12dUut3dG5xWi6JPDMjSSK6s2JPcfeKYL1';
$seedGenerator = new Bip39SeedGenerator();
$seed = $seedGenerator->getSeed($mnemonic);
$hdFactory = new HierarchicalKeyFactory();
$master = $hdFactory->fromEntropy($seed);
$hardened = $master->derivePath("44'/13107'/0'/0/0");
$pubKey = new PayToPubKeyHashAddress($hardened->getPublicKey()->getPubKeyHash());
$verifyAddress = $pubKey->getAddress();
if ($verifyAddress != $address) {
return $this->failed('非法操作');
}
$user = User::where('username', $address)->first();

View File

@@ -46,4 +46,17 @@ class UserController extends Controller
return $this->success($user->privacy);
}
public function download(): JsonResponse
{
return $this->success('https://www.uzchain.tech?invite='.Api::user()->username);
}
public function email()
{
}
public function mobile()
{
}
}

View File

@@ -15,7 +15,9 @@ class AuthResource extends JsonResource
'user_info' => [
'user_id' => $this->id,
'username' => $this->username,
'privacy' => $this->privacy,
'mobile' => $this->mobile,
'email' => $this->email,
'privacy' => $this->privacy ?? true,
'nickname' => $this->info->nickname,
'avatar' => $this->info->avatar,
'address' => $this->username,

View File

@@ -10,4 +10,5 @@ Route::group([
$router->get('search', 'UserController@search');
$router->put('setting/{field}', 'UserController@setting');
$router->put('privacy', 'UserController@privacy');
$router->get('download', 'UserController@download');
});