Skip to content

Commit

Permalink
weapp login
Browse files Browse the repository at this point in the history
  • Loading branch information
liyu001989 committed Aug 23, 2020
1 parent e0722e4 commit 140b98c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/Http/Controllers/Api/AuthorizationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function socialStore($type, SocialAuthorizationRequest $request)
break;
}

return response()->json(['token' => $user->id]);
$token = auth('api')->login($user);

return $this->respondWithToken($token)->setStatusCode(201);
Expand Down
13 changes: 13 additions & 0 deletions app/Http/Requests/Api/WeappAuthorizationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Requests\Api;

class WeappAuthorizationRequest extends FormRequest
{
public function rules()
{
return [
'code' => 'required|string',
];
}
}
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class User extends Authenticatable implements MustVerifyEmailContract, JWTSubjec

protected $fillable = [
'name', 'phone', 'email', 'password', 'introduction', 'avatar',
'weixin_openid', 'weixin_unionid', 'registration_id'
'weixin_openid', 'weixin_unionid', 'registration_id',
'weixin_session_key', 'weapp_openid',
];

protected $hidden = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddWeixinSessionKeyToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
//
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
}
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
// 登录
Route::post('authorizations', 'AuthorizationsController@store')
->name('api.authorizations.store');
// 小程序登录
Route::post('weapp/authorizations', 'AuthorizationsController@weappStore')
->name('weapp.authorizations.store');
// 刷新token
Route::put('authorizations/current', 'AuthorizationsController@update')
->name('authorizations.update');
Expand Down

0 comments on commit 140b98c

Please sign in to comment.