generated from panliang/owl-admin-starter
50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\PartyUser;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class AuthController extends Controller
|
|
{
|
|
public function login(Request $request)
|
|
{
|
|
$request->validate([
|
|
'username' => 'required',
|
|
'password' => 'required',
|
|
]);
|
|
|
|
$user = PartyUser::where('username', $request->input('username'))->first();
|
|
if (!Hash::check($request->input('password'), $user->password)) {
|
|
throw new BaseException('用户名或密码错误');
|
|
}
|
|
// 更新第三方账户
|
|
// $openid = $request->input('openid');
|
|
// $open_type = $request->input('open_type');
|
|
// if ($openid && $open_type) {
|
|
// $this->updateUserSocialite($user, $openid, SocialiteType::from($open_type));
|
|
// }
|
|
$token = $user->createToken('client')->plainTextToken;
|
|
return $this->response()->success(['token' => $token, 'user' => $user]);
|
|
}
|
|
|
|
// protected function updateUserSocialite($user, $openid, $type)
|
|
// {
|
|
// // 清空以前绑定的
|
|
// UserSocialite::where([
|
|
// 'type' => $type,
|
|
// 'user_type' => $user->getMorphClass(),
|
|
// 'user_id' => $user->id,
|
|
// ])->update(['user_id' => null]);
|
|
// UserSocialite::updateOrCreate([
|
|
// 'type' => $type,
|
|
// 'user_type' => $user->getMorphClass(),
|
|
// 'openid' => $openid,
|
|
// ], [
|
|
// 'user_id' => $user->id,
|
|
// ]);
|
|
// }
|
|
}
|