Reputation: 31
I tried to make auth API, I am success registed. Than Signin can't success. Please help me ,thanks.
public function login(Request $request)
{
try
{
if (!$request->has('Account')
|| !$request->has('Password'))
{
throw new Exception('Parameter missing');
}
$checkUser = DB::table('Users')->where('Account',$request->Account)->first();
if(empty($checkUser))
{
throw new Exception('No Data');
}
$data = ([
'Account' => $request->Account,
'Password' => $request->Password,
]);
if(!Auth::attempt($data))
throw new Exception('Verification error');
this db info.
Upvotes: 1
Views: 73
Reputation: 1583
Try following for register need to hash password before save in database:
User::create([
'Account' => $request->Account,
'CreateDateTime' => date('Y-m-d'),
'UpdatedDateTime' => date('Y-m-d'),
'Password' => Hash::make($request->Password),
]);
Upvotes: 1
Reputation: 104
try this way it might helpful and evn ry validator also: and if not sure about pass word then first debug
$table->string('password', 60)->nullable();
----------------------------------------------------
return Validator::make($data, [
'email' => 'required|email',
'password' => 'required',
]);
-----------------------------------------------
$user_data=User::where('username','=',$request->username)->first();
$userScope=$user_data->scope;
Input::merge([
'client_id' => env('CLIENT_ID'),
'client_secret' => env('CLIENT_SECRET'),
'scope' => 'admin'
]);
$credentials = $request->only(['grant_type', 'username', 'password','scope']);
$validationRules = $this->getLoginValidationRules();
$credentials["client_id"] = env('CLIENT_ID');
$credentials["client_secret"] = env('CLIENT_SECRET');
$this->validateOrFail($credentials, $validationRules);
try {
if (!$accessToken = Authorizer::issueAccessToken()) {
return $this->response->errorUnauthorized();
}
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
throw $e;
return $this->response->error('could_not_create_token', 500);
}
$accessToken["groups"][] = $userScope;
return response()->json(compact('accessToken'));
Upvotes: 0