本文整理汇总了PHP中App\Http\Controllers\Auth::login方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::login方法的具体用法?PHP Auth::login怎么用?PHP Auth::login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Controllers\Auth
的用法示例。
在下文中一共展示了Auth::login方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callback
/**
* Callback action that should be called by auth0, logs the user in
*/
public function callback()
{
// Get a handle of the Auth0 service (we don't know if it has an alias)
$service = \App::make('auth0');
// Try to get the user information
$profile = $service->getUser();
// Get the user related to the profile
$auth0User = $this->userRepository->getUserByUserInfo($profile);
if ($auth0User) {
if (!str_contains($auth0User->name, '@')) {
$name = $auth0User->name;
} else {
$name = $auth0User->nickname;
}
// If we have a user, we are going to log him in, but if
// there is an onLogin defined we need to allow the Laravel developer
// to implement the user as he wants an also let him store it.
$flight = User::firstOrCreate(['github_id' => $auth0User->user_id, 'email' => $auth0User->email, 'picture' => $auth0User->picture, 'name' => $name]);
if ($service->hasOnLogin()) {
$user = $service->callOnLogin($auth0User);
} else {
// If not, the user will be fine
$user = $auth0User;
}
\Auth::login($user);
}
return \Redirect::intended('/');
}
示例2: login
public function login($redirect_path = null)
{
$redirect = '/';
if ($redirect_path) {
$redirect .= $redirect_path;
}
$user = null;
try {
$user = Socialize::with('facebook')->user();
} catch (ClientException $e) {
return $this->redirectToFacebook($redirect_path);
} catch (InvalidStateException $e) {
dd('stop');
}
$db_user = User::where('fb_id', $user->id)->first();
if (!$db_user) {
$db_user = new User();
}
$db_user->fb_id = $user->id;
$db_user->name = $user->name;
$db_user->email = $user->email;
$db_user->avatar = $user->avatar;
$db_user->token = $user->token;
$db_user->updated_time = $user->user['updated_time'];
$db_user->verified = $user->user['verified'];
$db_user->save();
\Auth::login($db_user, true);
return redirect($redirect);
}
示例3: handleProviderCallback
/**
* Obtain the user information from the Social Login Provider.
*
* @param string $provider
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
protected function handleProviderCallback($provider)
{
$user = $this->socialite->driver($provider)->user();
$user = \App\User::whereEmail($user->getEmail())->first() ?: \App\User::create(['name' => $user->getName(), 'email' => $user->getEmail()]);
\Auth::login($user, true);
flash(trans('auth.welcome', ['name' => $user->name]));
return redirect(route('home'));
}
示例4: github
public function github()
{
$user = Socialize::with('github')->user();
Auth::login($user);
// Do your stuff with user data.
print_r($user);
die;
Redirect::intended('home');
}
示例5: handleProviderCallback
/**
* Obtain the user information from $provider
*
* @return Response
*/
public function handleProviderCallback($provider)
{
$user = Socialite::driver($provider)->user();
$data = ['name' => $user->name, 'email' => 'info+' . $user->nickname . '@sapioweb.com', 'password' => bcrypt('oauthinstagram'), 'token' => $user->token, 'profile_id' => $user->id, 'avatar' => $user->avatar, 'username' => $user->nickname];
$authUser = CrudHelper::createOrUpdate(new \App\User(), 'profile_id', $user->id, $data)->first();
\Auth::login($authUser, true);
return redirect()->route('home');
// $user->token;
}
示例6: store
/**
* Store a newly created user in storage.
*
* @return Response
*/
public function store(CreateUserRequest $request)
{
$user = new User($request->all());
$user->password = \Hash::make($request->password);
$user->type = 'user';
$user->save();
\Auth::login($user);
\Session::put('auth_photo', '../default_avatar.jpg');
return redirect()->route('newaccount');
}
示例7: signin
public function signin(Request $request)
{
$user = User::where('email', trim($request->input('username')))->orWhere('username', trim($request->input('username')))->first();
if (!is_null($user)) {
if (\Hash::check($request->get('password'), $user->password)) {
\Auth::login($user);
return redirect()->route('tasks.index');
}
}
return redirect()->route('auth.login')->with("NOTIF_DANGER", 'Login Failed');
}
示例8: createAccount
/**
* A user tries to register a native account.
* S/he haven't logged in to the application with a social account before.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
protected function createAccount(Request $request)
{
$validator = \Validator::make($request->except('_token'), ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:6']);
if ($validator->fails()) {
return back()->withInput()->withErrors($validator);
}
$user = User::create($request->except('_token'));
\Auth::login($user);
flash(trans('auth.welcome', ['name' => $user->name]));
return redirect(route('home'));
}
示例9: store
/**
* Store a newly created resource in storage.
*
* @param AuthController $auth
* @internal param Request $request
* @return Response
*/
public function store(AuthController $auth)
{
$data = Input::all();
$valid = $auth->validator($data);
if ($valid->fails()) {
return redirect()->back()->withInput()->withErrors($valid);
}
$user = $auth->create($data);
Auth::login($user);
return redirect()->to('admin');
}
示例10: emailConfirmation
public function emailConfirmation($data)
{
$json = base64_decode($data);
$values = json_decode($json);
$user = User::where("confirmation_code", "=", $values->confirmation_code)->where("email", "=", $values->email)->first();
if (isset($user->id) && $user->id > 0) {
$user = User::find($user->id);
$user->update(["active" => 1]);
\Auth::login($user);
return redirect("/")->with("messages", "Welcome, you have been successfully registered!");
}
}
示例11: postLogin
public function postLogin()
{
$credentials = \Input::only('email', 'password');
$user = UserModel::where('email', \Input::get('email'))->first();
// dd($user);
if ($user and \Hash::check(\Input::get('password'), $user->password)) {
Auth::login($user);
flash('welcome in ' . auth()->user()->username, 'success');
return redirect('/user/');
} else {
flash('unable to login', 'danger');
return redirect('/user/login');
}
}
示例12: signup
public function signup()
{
$validation = User::validate(Input::all());
if ($validation->passes()) {
$user = array('fname' => Input::get('fname'), 'lname' => Input::get('lname'), 'year' => Input::get('year'), 'email' => Input::get('email'), 'password' => \Hash::make(Input::get('password')));
User::create($user);
$user_sign = User::whereemail(Input::get('email'))->first();
\Auth::login($user_sign);
Session::put('user_name', $user['email']);
$score = DB::table('users')->where('email', Session::get('user_name'))->pluck('points');
Session::put('pts', $score);
return Redirect::to('dashboard')->with('message', 'Successfully Registered! Now you are logged in!');
} else {
return Redirect::to('signup')->withErrors($validation->errors())->withInput();
}
}
示例13: postReset
/**
* Handle a POST request to reset a user's password.
*
* @return Response
*/
public function postReset()
{
$credentials = Input::only('email', 'password', 'password_confirmation', 'token');
$response = Password::reset($credentials, function ($user, $password) {
$user->password = Hash::make($password);
$user->save();
Auth::login($user);
});
switch ($response) {
case Password::INVALID_PASSWORD:
case Password::INVALID_TOKEN:
case Password::INVALID_USER:
return Redirect::back()->with('error', Lang::get($response));
case Password::PASSWORD_RESET:
return Redirect::to('users/dashboard');
}
}
示例14: postLogin
public function postLogin()
{
$postValue = \Input::get('User');
if ($this->loginService->checkLogin($postValue['email'], $postValue['password'])) {
$user = $this->loginService->loadUser($postValue['email']);
\Auth::login($user);
if ($this->loginService->isFirstLogin($user->email)) {
$response = route('profile.create');
} else {
$response = route('home');
}
$success = json_encode(['status' => 'success', 'response' => $response]);
return response($success);
}
$fail = json_encode(['status' => 'failed', 'response' => $this->alertDanger('Gagal login')]);
return response($fail);
}
示例15: login
public function login(Request $request)
{
if (!$request->has('email') || !$request->has('password')) {
return view('error')->with('error', 'Please provide all the fields.');
}
$input = $request->all();
$user = \App\User::where('email', '=', $input['email'])->get()->first();
if (count($user) != 1) {
return view('error')->with('error', 'Couldn\'t find the user.');
}
if (!\Hash::check($input['password'], $user->password)) {
return view('error')->with('error', 'Wrong password.');
}
\Auth::login($user);
// return response()->json(['id' => \Auth::id()]);
return redirect('/');
}