Esempio n. 1
0
 /**
  * Login user
  *
  * @param \Illuminate\Http\Request           $request
  * @param \Tajrish\Services\UserTokenHandler $tokenHandler
  * @param \Illuminate\Auth\Guard             $auth
  * @return \Illuminate\Http\JsonResponse
  */
 public function postLogin(Request $request, UserTokenHandler $tokenHandler, Guard $auth)
 {
     $this->validate($request, ['email' => 'required|email', 'password' => 'required|string']);
     // @FIXME Remove extra user call
     if ($auth->attempt($request->only(['email', 'password']))) {
         $user = User::where('email', $request['email'])->first();
         $token = $tokenHandler->createAndGetTokenForUser($user);
         return response()->json(['user' => $user, 'found' => true, 'token_entity' => $token, 'message' => trans('messages.successful_login')]);
     }
     return response()->json(['found' => false, 'message' => trans('messages.invalid_credentials')]);
 }
Esempio n. 2
0
 public function postFinishProvince($token, $provinceId, UserTokenHandler $tokenHandler)
 {
     $user = $tokenHandler->getUserFromToken($token, true);
     Province::findOrFail($provinceId);
     $visit = Visit::where('user_id', $user['id'])->where('province_id', $provinceId)->whereNull('finished_at')->first();
     if ($visit) {
         $visit->update(['finished_at' => Carbon::now()]);
     }
     return response()->json(['successful' => true]);
 }