/ *注册用户* /
公共功能寄存器(请求$ request){
$user = User::create([
'username' => $request->input('username'),
'email' => $request->input('email'),
'api_token' => Str::random(50),
'password' => app('hash')->make($request->input('name'))
]);
return response()->json(['user' => $user], 200);
}
/ *用户登录* /
公共功能登录(请求$ request){
$user = User::where('email', $request->input('email'))
->first();
if(!$user){
return response()->json(['status' => 'error', 'message' => 'User not found!'], 401);
}
if(Hash::check($request->input('password'), $user->password)){
$user->update(['api_token' => Str::random(50)]);
return response()->json(['status' => 'success', 'message' => 'Logged in Successfully.'], 200);
}
return response()->json(['status' => 'error', 'message' => 'Credential Invalid!'], 401);
}