本文整理汇总了PHP中App\Http\Controllers\Auth::loginUsingId方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::loginUsingId方法的具体用法?PHP Auth::loginUsingId怎么用?PHP Auth::loginUsingId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Controllers\Auth
的用法示例。
在下文中一共展示了Auth::loginUsingId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleFacebookCallback
public function handleFacebookCallback()
{
//Since its the same callback function for registration & login. Check prev url and handle appropriately
$prevUrl = session()->previousUrl();
$facebookUser = Socialize::with('facebook')->user();
$appUser = User::whereEmail($facebookUser->getEmail())->get();
if (strpos($prevUrl, "register")) {
//If user is not already registered, register and login
if ($appUser->count() == 0) {
$user = User::create(['name' => $facebookUser->getName(), 'email' => $facebookUser->getEmail(), 'password' => str_random(8)]);
$user->verified = true;
$user->token = null;
$user->save();
session()->flash('message', 'You are now registered. Please update your account details.');
\Auth::loginUsingId($user->id);
return redirect('/myAccount');
} else {
return redirect()->back()->withErrors('User already exists');
}
} else {
if ($appUser->count() == 0) {
return redirect()->back()->withErrors('User not found');
}
$user = $appUser[0];
}
\Auth::loginUsingId($user->id);
return redirect()->intended('/dashboard');
}
示例2: handleCallback
public function handleCallback($driver, Request $req)
{
$socialuser = \Socialize::with($driver)->user();
$user = User::where('email', $socialuser->email)->first();
if (count($user) < 1) {
$user = new User();
$user->id = (string) Uuid::generate();
$user->email = $socialuser->email;
$user->name = $socialuser->name;
$user->avatar = $socialuser->avatar;
$user->save();
}
$user = \Auth::loginUsingId($user->id);
$authcookie = \Cookie::queue('authenticated', true, 20, null, "www.thinkmerit.in", false, false);
$username = \Cookie::queue('name', $user->name, 20, null, "www.thinkmerit.in", false, false);
$avatar = \Cookie::queue('avatar', $user->avatar, 20, null, "www.thinkmerit.in", false, false);
$email = \Cookie::queue('email', $user->email, 20, null, "www.thinkmerit.in", false, false);
if (app()->environment() == "production") {
return \Redirect::to("http://www.thinkmerit.in");
} else {
return \Redirect::to("http://www.dev.thinkmerit.in");
}
/* ->withCookie($authcookie)
->withCookie($username)
->withCookie($avatar)
->withCookie($email);*/
// ;
}
示例3: manualregister
public function manualregister(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
$arr = $request->all();
$arr['id'] = (string) Uuid::generate();
$arr['password'] = bcrypt($arr['password']);
$user = new User($arr);
$user->save();
\Auth::loginUsingId($user->id);
return Response::json(['msg' => 'Succsfully registered!'], 200);
}
示例4: authajax
public function authajax(Request $request)
{
$rules = array('email' => 'required|email', 'password' => 'required');
$validator = \Validator::make($request->all(), $rules);
if ($validator->fails()) {
return Response::json(array('result' => false, 'data' => $validator->errors()->all()));
}
$email = $request->input('email');
$password = $request->input('password');
$member = Member::whereRaw('email = ? and password = ? ', [$email, md5($password)])->first();
if ($member == null) {
return Response::json(array('result' => false, 'data' => 'กรุณาลองใหม่อีกครั้ง.'));
}
$result = \Auth::loginUsingId($member->id);
return Response::json(array('result' => true, 'data' => 'login success.'));
}
示例5: oauthCallback
public function oauthCallback(Request $request)
{
if ($request->get('state') == session('state')) {
$auth = new Auth(config('wechat.appid'), config('wechat.secret'));
$ouser = $auth->user();
if (!$ouser) {
abort('微信授权错误 #13101');
}
$sa = SocialAccount::where('openid', $ouser->get('openid'))->where('platform', 'wechat')->first();
if ($sa) {
\Auth::loginUsingId($ouser->user_id);
} else {
\DB::transaction(function () use($ouser, $auth) {
$user = User::create(['name' => $ouser->get('nickname', ''), 'username' => $ouser->get('platform') . '_' . $ouser->get('openid', ''), 'avatar' => $ouser->get('headimgurl')]);
SocialAccount::create(['user_id' => $user->id, 'access_token' => $auth->access_token, 'refresh_token' => $auth->refresh_token, 'platform' => 'wechat', 'openid' => $ouser->get('openid'), 'user_info' => json_encode($ouser), 'union_id' => $ouser->get('union_id', '')]);
\Auth::loginUsingId($user->id);
});
}
return redirect(route('home'));
} else {
abort('403', '服务器授权state不正确');
}
}