public function login(Request $request) { // dd(\Crypt::encrypt('*****@*****.**')); try { $email = \Crypt::decrypt($request->get('token')); } catch (\Exception $e) { return abort('403', 'Forbidden'); } $user = User::whereEmail($email)->first(); if (!$user) { return abort('403', 'Forbidden'); } if (!$user->account) { $b2bCompany = \DB::connection('mysql-b2b')->table('companies')->where('user_id', '=', $user->id)->first(); // $b2bCompany = false; $accountName = $b2bCompany ? $b2bCompany->company_name : $user->email; $account = new Account(); $account->ip = $request->getClientIp(); $account->name = $accountName; $account->account_key = str_random(RANDOM_KEY_LENGTH); $account->save(); $user->account_id = $account->id; $user->registered = true; $user->save(); $exists = \DB::connection('mysql')->table('users')->whereId($user->id)->count(); if (!$exists) { \DB::connection('mysql')->table('users')->insert(['id' => $user->id, 'account_id' => $user->account_id, 'created_at' => $user->created_at, 'updated_at' => $user->updated_at, 'deleted_at' => $user->deleted_at, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'phone' => $user->phone, 'username' => $user->username, 'email' => $user->email, 'password' => $user->password, 'confirmation_code' => $user->confirmation_code, 'registered' => $user->registered, 'confirmed' => $user->confirmed, 'notify_sent' => $user->notify_sent, 'notify_viewed' => $user->notify_viewed, 'notify_paid' => $user->notify_paid, 'public_id' => $user->public_id, 'force_pdfjs' => false, 'remember_token' => $user->remember_token, 'news_feed_id' => $user->news_feed_id, 'notify_approved' => $user->notify_approved, 'failed_logins' => $user->failed_logins, 'dark_mode' => $user->dark_mode, 'referral_code' => $user->referral_code]); } } \Auth::loginUsingId($user->id); return redirect('/'); }
public function store(LoginAlternativeRequest $request) { try { $credentials['password'] = $request->input('idfacebook'); $credentials['email'] = $request->input('email'); $data['tokendevice'] = $request->input('tokendevice'); $data['typedevice'] = $request->input('typedevice'); $datauser = User::whereEmail($credentials['email'])->get()->first(); if (isset($datauser)) { if ($datauser->flagactive == User::STATE_USER_INACTIVE) { $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], 'usuario Inactivo'); $this->_responseWS->response(); } } else { $data = $request->all(); $data['password'] = Hash::make($data['idfacebook']); $obj = User::create($data); $datosRol = Role::whereName('user_app')->first(); $daoUserRol['role_id'] = (int) $datosRol->id; $daoUserRol['user_id'] = $obj->id; RoleUser::create($daoUserRol); } $this->login($request->all()); } catch (\Exception $exc) { dd($exc->getMessage()); $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], ''); } $this->_responseWS->response(); }
/** * Send a password reset link to the given email's owner, via email. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse * @throws \App\Exceptions\Common\ValidationException */ public function sendPasswordResetLink(Request $request) { $validator = app('validator')->make($request->all(), ['email' => 'required|email|max:255']); if ($validator->fails()) { throw new ValidationException($validator); } $user = User::whereEmail($request->only('email'))->first(); if (is_null($user)) { throw new ModelNotFoundException(trans('passwords.user')); } $user->notify(new ResetPasswordNotification(app('auth.password.broker')->createToken($user))); event(new RequestedResetPasswordLink($user)); if ($request->expectsJson()) { return response()->json(['message' => trans('passwords.sent')]); } return redirect()->back()->with('message', trans('passwords.sent')); }
public function login(Request $request) { try { $this->validate($request, ['email' => 'required|email', 'password' => 'required']); } catch (ValidationException $e) { $errors = $e->getErrors(); return parent::response([], $errors); } $token = null; try { if (!($token = JWTAuth::attempt($request->only('email', 'password')))) { return parent::response([], [trans('auth.failed')]); } } catch (JWTException $e) { abort(500, 'Could not create token'); } $user = User::whereEmail($request->input('email'))->first(); return $this->processLogin($user, $token); }
public function store(LoginRequest $request) { try { $credentials['password'] = $request->input('idfacebook'); $credentials['email'] = $request->input('email'); $data['tokendevice'] = $request->input('tokendevice'); $data['typedevice'] = $request->input('typedevice'); $datauser = User::whereEmail($credentials['email'])->get()->first(); if (isset($datauser)) { switch ($datauser->flagactive) { case User::STATE_USER_ACTIVE: if (!($token = JWTAuth::attempt($credentials))) { $this->_responseWS->setDataResponse(Response::HTTP_UNAUTHORIZED, [], array(), ControllerWS::MSG_CUSTOM_USER_PASS_FAIL); } else { $login = JWTAuth::toUser($token); $obj = User::find($login->id); $UserCategory = new UserCategories(); $categories = $UserCategory->UserCategories($login->id); $dataUser = $login; $dataUser['flagterms'] = $login->flagterms; $dataUser['categories'] = $categories->toArray(); $modelhash = new UserHash(); $modelhash->GetFriendFacebook($data['tokendevice'], $data['typedevice'], $login->name . ' ' . $login->lastname, $login->picture, $credentials['password'], $login->id); $obj->update($data); $this->_responseWS->setDataResponse(Response::HTTP_OK, [$dataUser], array(), 'ok'); $this->_responseWS->setHeader('_token', $token); } break; case User::STATE_USER_INACTIVE: $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], 'usuario desactivado por el administrador'); break; } } else { $this->_responseWS->setDataResponse(Response::HTTP_UNAUTHORIZED, [], [], 'no existe el usuario'); } } catch (\Exception $exc) { dd($exc->getMessage()); $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], ''); } $this->_responseWS->response(); }
public function storeEmail(Requests\Email $request) { $user = User::whereEmail($request->email)->first(); if (is_null($user) || $user && $user->isRegistered() == FALSE) { // Generate uniq code do { $code = Str::random(4); } while (is_object(User::notRegistered()->whereCode($code)->first())); if (is_null($user)) { $user = new User($request->all()); } $user->code = $code; $user->save(); Mail::send('emails.code', ['code' => $code], function ($m) use($user) { $m->to($user->email, $user->name)->subject('Your Code!'); }); return Redirect::route('enter_code'); } else { return Redirect::back()->withErrors('Email already registered'); } }
/** * * * @return mixed */ public function getFacebook() { try { $oauth = Socialite::driver('facebook')->user(); // } catch (\Exception $ex) { return Socialite::driver('facebook')->redirect(); } if (is_null($user = User::where('fb_id', '=', $oauth->id)->first())) { if (!is_null($oauth->email) && is_null($user = User::whereEmail($oauth->email)->first())) { $user = new User(); } } $user->fb_id = $oauth->id; $user->activated = true; $user->email = !is_null($oauth->email) ? $oauth->email : "{$oauth->id}@facebook.com"; $user->name = $oauth->name; $user->password = bcrypt('12345678'); $user->avatar = $oauth->avatar; $user->save(); Auth::login($user); return $this->redirectRoute("HomePage"); }
/** * Login * * @param Request $request * @return Response */ public function postLogin(Request $request) { if (!$this->appKeyAvailable($request)) { return $this->notAuthorized($request); } $validator = Validator::make($request->all(), ['email' => 'required|max:32|email', 'password' => 'required|min:6']); if ($validator->fails()) { $this->setResultError($validator->messages(), 400); } else { $email = $request->get('email'); $password = $request->get('password'); $user = User::whereEmail($email)->first(); if ($user && Hash::check($password, $user->password)) { $this->setResultOk(); $this->user = $user; $this->setSessionHash(); $this->setUserData(); } else { $this->setResultError("wrong email or password", 401); } } return $this->setResponse(); }
/** * @return boolean * * @throws NotFoundHttpException * @throws \UnexpectedValueException */ public function sendResetPasswordLinkViaEmail() { $validator = \Validator::make($this->request->all(), ['email' => 'required|email|max:255']); if ($validator->fails()) { throw new ValidationException($validator); } $user = User::whereEmail($this->request->only('email'))->first(); if (is_null($user)) { throw new UserNotFoundException(); } \Event::fire(new RequestedResetPasswordLinkViaEmail($user)); return true; }
public function claimReferralCode($email) { $user = User::whereEmail($email)->whereReferralCode(null)->whereConfirmed(true)->first(); if ($user) { do { $code = strtoupper(str_random(8)); $match = User::whereReferralCode($code)->withTrashed()->first(); } while ($match); $user->referral_code = $code; $user->save(); return $code; } return Redirect::to('/'); }
/** * Reverse the migrations. * * @return void */ public function down() { User::whereEmail(static::MASTER_EMAIL)->delete(); }
private function validateEmail($email, $botUserId) { if (!$email || !$botUserId) { return false; } // delete any expired codes SecurityCode::whereBotUserId($botUserId)->where('created_at', '<', DB::raw('now() - INTERVAL 10 MINUTE'))->delete(); if (SecurityCode::whereBotUserId($botUserId)->first()) { return false; } $user = User::whereEmail($email)->whereNull('bot_user_id')->first(); if (!$user) { return false; } $code = new SecurityCode(); $code->user_id = $user->id; $code->account_id = $user->account_id; $code->code = mt_rand(100000, 999999); $code->bot_user_id = $botUserId; $code->save(); $this->userMailer->sendSecurityCode($user, $code->code); return $code->code; }
public function resendVerify(User $user) { $user = User::whereEmail($user->email)->first(); $data = ['first_name' => $user->first_name, 'confirmation_code' => $user->confirmation_code, 'subject' => 'Re-sent, Please Verify Email Address', 'email' => $user->email]; $this->userMailer->verify($user->email, $data); }
$user->link = $facebook_user['link']; $user->password = Hash::make('awesome'); $user->access_token = $token; $user->save(); $last_id = $user->id; } // Create the user if it does not exist or update the existing entry. // This will only work if you've added the SyncableGraphNodeTrait to your User model. //$user = App\User::createOrUpdateGraphNode($facebook_user); // Log the user into Laravel either it exists or just created if ($user_exist) { Auth::login($user_exist); } else { $user_exist = $user::where('id', '=', $last_id)->first(); Auth::login($user_exist); } //return redirect('/')->with('message', 'Welcome '.$facebook_user['name'].' successfully logged in with Facebook'); return redirect('/'); //return redirect()->route('dashboard.index'); }); $router->bind('dashboard', function ($email) { /** * * retrieve the first email matching the query in the db */ return \App\models\User::whereEmail($email)->first(); }); Route::resource('dashboard', 'DashboardController'); Route::get('profile', function () { return view('profile'); });