登录校验
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Jobs\SyncUserInfo;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@@ -11,6 +10,7 @@ use Illuminate\Notifications\Notifiable;
|
||||
use Jason\Api\Api;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Tencent\TLSSigAPIv2;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@@ -54,6 +54,16 @@ class User extends Authenticatable
|
||||
return Api::login($this);
|
||||
}
|
||||
|
||||
public function setPasswordAttribute($value): void
|
||||
{
|
||||
$this->attributes['password'] = bcrypt($value);
|
||||
}
|
||||
|
||||
public function setMnemonicAttribute($value): void
|
||||
{
|
||||
$this->attributes['mnemonic'] = Crypt::encrypt($value);
|
||||
}
|
||||
|
||||
public function info(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserInfo::class);
|
||||
|
||||
Reference in New Issue
Block a user