public function facebookCallback() { try { $facebook = Socialite::driver('facebook')->scopes(['email'])->user(); // 確認使用者有提供 Email if (null === $facebook->getEmail()) { throw new OAuthException(); } // 如果 Email 不存在,創見帳號,如 Email 已存在,則略過此步驟 if (null === ($account = Account::where('email', '=', $facebook->getEmail())->first(['id']))) { $account = Account::create(['email' => $facebook->getEmail(), 'password' => str_random(32)]); if (!$account->exists) { throw new ModelNotFoundException(); } $account->load(['user'])->getRelation('user')->update(['nickname' => $facebook->getName() . '@facebook']); } \Auth::loginUsingId($account->getAttribute('id'), true); return redirect()->route('home'); } catch (ClientException $e) { $data = ['您似乎並未允許本網站存取您的資料', false]; } catch (InvalidStateException $e) { $data = ['似乎出了點狀況,請嘗試重新登入', false]; } catch (ModelNotFoundException $e) { $data = ['網站似乎出了點狀況,請稍候再嘗試', false]; } catch (OAuthException $e) { $data = ['您似乎並未允許本網站存取您的信箱', true]; } catch (\Exception $e) { $data = ['網站似乎出了點狀況,請稍候再嘗試', false]; \Log::error('Non-catch exception.', ['code' => $e->getCode(), 'message' => $e->getMessage()]); } return view('errors.oauthFailed', ['message' => $data[0], 'invalidEmail' => $data[1]]); }
public function login(Request $request) { dd($request); Validator::make($request, ['email' => 'required|email|max:255', 'password' => 'required|min:6']); if (Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')])) { return 1; } }
public function accessFile($resource) { if (Auth::user()) { return $resource; } else { return $this->setStatusCode(403)->respondForbidden('You do not have permission to view that particular resource'); } }
/** * Store a newly created resource in storage. * * @param \App\Http\Requests\CreateTaskRequest $request * @return \Illuminate\Http\Response */ public function store(CreateTaskRequest $request) { $task = new Task(); $task->fill($request->all()); $task->created_by = \Auth::user()->id; $task->save(); Event::fire(new TaskAdded($task)); return $task->fresh(); }
public function checkNotifications() { Carbon::setLocale('ja'); $notifications = $this->getNotification(\Auth::user()->id); $notificationsTimeAgo = array_map(function ($e) { $h = Carbon::parse($e->notify_created_at); return $h->diffForHumans(); }, $notifications); return compact('notifications', 'notificationsTimeAgo'); }
public function login(Request $request) { $email = $request->get('email', ''); $password = $request->get('password', ''); if (\Auth::once(['email' => $email, 'password' => $password])) { return response()->json(['status' => 'success', 'message' => '', "data" => ['email' => $email, 'token' => \Auth::user()->token, 'name' => \Auth::user()->name]]); } else { return response()->json(['status' => 'error', 'message' => 'Email o contraseña incorrectos', "data" => ['email' => $email, 'password' => $password]]); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(CreateCommentRequest $request, $task_id) { $task = Task::findOrFail($task_id); $comment = new Comment(); $comment->fill($request->all()); $comment->task_id = $task->id; $comment->user_id = \Auth::user()->id; $comment->save(); $comment->user; return $comment; }
public function auth(Request $request) { $usernameinput = $request->email; $password = $request->pwd; $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'username'; if (\Auth::attempt(array($field => $usernameinput, 'password' => $password), false)) { $user = \Auth::user(); return response()->json($user); } else { return response()->json(array('msg' => 'user not found', 'status' => 0)); } }
public function upload() { $repository = new \App\Repositories\Files(); try { $input = Input::all(); $input['user_id'] = \Auth::user()->id; $response = $repository->handle($input); } catch (Exception $e) { return \Response::make($e->getMessage(), $e->getCode()); } return $this->setStatusCode(200)->respond($response); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($slug) { $event = Event::findBySlug($slug); $chair_id = (int) \Request::get('chair_id'); if (\Auth::id() === $chair_id) { $result = $event->update(array('chair_id' => $chair_id)); } if ($result) { return response('Event chair updated!'); } else { abort(409, 'There was an issue updating the registration.'); } }
public function authenticate(Request $request) { \R::setup('mysql:host=localhost;dbname=gazingle', 'root', ''); $redis = Redis::connection(); $user = \R::getRow('select * from users where email = "' . $request->email . '"'); //return $user; if ($request->password === \Crypt::decrypt($user['password'])) { \Auth::loginUsingId($user['id']); $redis->set(\Crypt::encrypt($request->email), $user['id']); return $redis->get($request->email); } return response('Unauthorized.', 401); }
public function auth(Request $request) { $device_id = $request->device_id; $usernameinput = $request->email; $password = $request->pwd; $version = $request->version; // dd($request); $field = $usernameinput ? 'email' : 'username'; if (\Auth::attempt(array('username' => $usernameinput, 'password' => $password), false)) { $user = \Auth::user(); $device = Device::where('device_id', $device_id)->first(); if ($request->has('version')) { if (!empty($device)) { $device->version = $version; $device->username = $usernameinput; $device->update(); } else { Device::create(['device_id' => $device_id, 'version' => $version, 'username' => $usernameinput]); } } if ($user->log_status == 0 || $user->device_id == $device_id) { $user->log_status = 1; $user->device_id = $device_id; $user->last_login = date('Y-m-d H:i:s'); $user->update(); $hash = UpdateHash::find(1); $user->hash = $hash->hash; return response()->json($user); } else { $t1 = StrToTime(date('Y-m-d H:i:s')); $t2 = StrToTime($user->last_login); $diff = ($t1 - $t2) / (60 * 60); if ($diff >= 24) { $user->log_status = 1; $user->device_id = $device_id; $user->last_login = date('Y-m-d H:i:s'); $user->update(); $hash = UpdateHash::find(1); $user->hash = $hash->hash; return response()->json($user); } else { return response()->json(array('msg' => 'User already logged on another device.', 'status' => 0, 'hr' => $diff)); } } } else { return response()->json(array('msg' => 'user not found', 'status' => 0)); } }
/** * API Login, on success return JWT Auth token * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function login(Request $request) { $credentials = $request->only('email', 'password'); try { // attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return response()->json(['error' => 'could_not_create_token'], 500); } // all good so return the token $user = \Auth::user(); return response()->json(compact('token', 'user')); }
public function postCancelWarn(Request $request) { $id = !empty($request->input('id')) ? $request->input('id') : null; $mark = !empty($request->input('mark')) ? $request->input('mark') : null; $act = !empty($request->input('act')) ? $request->input('act') : null; $wlogid = !empty($request->input('wlogid')) ? $request->input('wlogid') : null; if ($act == 'cancel') { if ($id === null) { $rs['sucess'] = false; $rs['data'] = "数据提交失败,请稍后重试!"; $rs['id'] = $id; } else { $warnInfo = DB::connection('mysql_old')->select('select c_type,userid from jl_data_warn where userid="' . $id . '"'); if ($warnInfo[0]->c_type != 1) { $rs['sucess'] = false; $rs['data'] = "请先对报警进行处理!"; $rs['id'] = $id; return response()->json($rs); } $warnId = DB::connection('mysql_old')->select('select id from jl_data_warn_save where userid="' . $id . '" order by id desc limit 1'); $data = array(); $data['wid'] = $warnId[0]->id; $data['time'] = time(); $data['admin'] = \Auth::user()->email; $data['mark'] = $mark; $data['type'] = 0; $in_flag = DB::connection('mysql_old')->insert('insert into jl_warn_log set userid=' . $id . ',wid=' . $data['wid'] . ',time=' . $data['time'] . ',admin="' . $data['admin'] . '",mark="' . $data['mark'] . '",type=' . $data['type']); if ($in_flag !== true) { $rs['sucess'] = false; $rs['data'] = "数据提交失败,请稍后重试!"; $rs['id'] = $id; } else { $up_flag = DB::connection('mysql_old')->update('update jl_data_warn set c_type=0,time2=' . $data['time'] . ' where userid="' . $id . '"'); $rs['sucess'] = true; $rs['data'] = "提交成功!"; $rs['id'] = $id; } } return response()->json($rs); } else { if ($act == 'solve') { if ($id === null) { $rs['sucess'] = false; $rs['data'] = "数据提交失败,请稍后重试!"; $rs['id'] = $id; } else { $warnId = DB::connection('mysql_old')->select('select id from jl_data_warn_save where userid="' . $id . '" order by id desc limit 1'); $data = array(); $data['wid'] = $warnId[0]->id; $data['time'] = time(); $data['admin'] = \Auth::user()->email; $data['mark'] = $mark; $data['type'] = 1; $in_flag = DB::connection('mysql_old')->insert('insert into jl_warn_log set userid=' . $id . ',wid=' . $data['wid'] . ',time=' . $data['time'] . ',admin="' . $data['admin'] . '",mark="' . $data['mark'] . '",type=' . $data['type']); if ($in_flag !== true) { $rs['sucess'] = false; $rs['data'] = "数据提交失败,请稍后重试!"; $rs['id'] = $id; } else { $up_flag = DB::connection('mysql_old')->update('update jl_data_warn set c_type=1 where userid="' . $id . '"'); $rs['sucess'] = true; $rs['data'] = "提交成功!"; $rs['id'] = $id; } } return response()->json($rs); } } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($slug, $id) { $event = Event::findBySlug($slug); if ($id == 'self') { if (\Auth::check()) { EventRegistration::where('user_id', '=', \Auth::id())->where('event_id', '=', $event->id)->delete(); } } else { EventRegistration::destroy($id); } }
public function postLogin() { // change the following paths if necessary $provider = Input::get('provider'); if ($provider == 'traditional') { $email = Input::get('email'); $password = Input::get('password'); if (\Auth::attempt(['email' => $email, 'password' => $password])) { return ['user' => \Auth::user()]; } else { \Response::json(['error' => 'The email and password are not correct'], 401); } } else { $token = Input::get('token'); $exploded = explode(' ', $token); $secret = count($exploded) == 2 ? explode(' ', $token)[1] : null; $token = explode(' ', $token)[0]; $result = SocialLoginManager::login($provider, $token, $secret); } if (array_key_exists('error', $result)) { return \Response::json(['error' => $result['error']], 401); } else { return \Response::json(['user' => $result['user']]); } }
/** * @author LAHAXE Arnaud * * Add a criteria on repository if the user is not admin and * the model is implementing UserRestrictionInterface * * @return bool */ protected function addUserCriteria() { $model = $this->repository->getModel(); if (!$model instanceof UserRestrictionInterface) { return true; } /** @var \App\User $user */ $user = \Auth::user(); // no current user and no user given, no access if (is_null($user)) { return false; } if ($user->isSuperAdmin()) { return true; } $this->repository->addCriteria(new User($user)); }