问一下大家,关于非LARAVEL默认加密方式登录dingo的$token生成问题
教程里边的 $token 是这样子生成的,使用的是 LARAVEL 默认的加密校验,是可以这样子的生成 $token 的
//登录获取token
public function login()
{
$credentials = request(['email', 'password']);
if (!$token = auth('api')->attempt($credentials)) {
return $this->response->errorUnauthorized('帐号或密码错误');
}
return $this->respondWithToken($token);
}
但是我是二次开发,之前用是 dx 论坛的登录加密码方式,这样子是无法登录成功取得 token 的,请问一下大家怎么修改,谢谢。
比如以下,密码账号验证通过后,怎么生成 token
$ytuser = YtUser::query()->where(['username' => $data['username'], 'password' => $data['password'], 'user_status' => '1'])->first();
if (is_null($ytuser)) {
return $this->response->errorUnauthorized('帐号或密码错误');
}
//以上通过验证,下边怎么成生token,这里怎么写
$token = auth('api')->??????;
return $this->respondWithToken($token);
//获取用户资料
public function me()
{
return response()->json(auth('api')->user());
}
//销毁token
public function logout()
{
auth('api')->logout();
return response()->json(['message' => 'Successfully logged out']);
}
//刷新token
public function refresh()
{
return $this->respondWithToken(auth('api')->refresh());
}
//响应token
protected function respondWithToken($token)
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth('api')->factory()->getTTL() * 60,
]);
}
推荐文章: