本文整理汇总了PHP中App\Http\Controllers\Auth\Auth::user方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::user方法的具体用法?PHP Auth::user怎么用?PHP Auth::user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Controllers\Auth\Auth
的用法示例。
在下文中一共展示了Auth::user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
public function login()
{
//echo "Came to validation part>>>!";
if (Auth::attempt(array('email' => Input::json('email'), 'password' => Input::json('password')))) {
return Response::json(Auth::user());
} else {
return Response::json(array('flash' => 'Invalid username or password'), 500);
}
}
示例2: __construct
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
if (\Auth::check()) {
$this->redirectTo = url(\Auth::user()->slug);
}
$this->middleware('guest', ['except' => 'logout']);
}
示例3: getLogout
/**
* Log the user out of the application.
*
* @return \Illuminate\Http\Response
*/
public function getLogout()
{
$user = Auth::user();
$user->status = 'unavailable';
$user->save();
return $this->logout();
}
示例4: facebookRedirect
public function facebookRedirect()
{
// Automatically log in existing users
// or create a new user if necessary.
SocialAuth::login('facebook', function ($user, $details) {
$existing_user = User::where('email', $details->email)->first();
if ($existing_user !== NULL) {
$existing_user->avatar = $details->avatar;
$existing_user->save();
return $existing_user;
// Tell the package to use this user instead of creating a new one.
}
$user->name = $details->full_name;
$user->avatar = $details->avatar;
$user->email = $details->email;
$user->save();
$roles_allowed = [2];
$user->syncRoles($roles_allowed);
});
// Current user is now available via Auth facade
$user = Auth::user();
if ($user->wasRecentlyCreated == TRUE) {
return redirect('payment')->with('message', 'Update Payment details!');
}
return redirect()->intended('/backend/home');
}
示例5: postRegister
public function postRegister(Request $request)
{
$validator = $this->registrar->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
$this->auth->login($this->registrar->create($request->all()));
$id = DB::getPdo()->lastInsertId();
$user = \Auth::user();
if (Input::get('state') === 'company') {
$user->isCompany = 1;
$user->save();
return Redirect('company/project');
} else {
if (Input::get('state') === 'student') {
$user->isStudent = True;
$user->save();
return Redirect('profile');
} else {
if (Input::get('state') === 'expertise') {
$user->isExpertise = True;
$user->save();
return Redirect('profile');
}
}
}
}
示例6: getLogout
/**
* Log the user out of the application.
*
* @return \Illuminate\Http\Response
*/
public function getLogout()
{
$user = \Auth::user()->name;
\Auth::logout();
\Session::flash('flash_message', $user . ': You have been logged out.');
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}
示例7: redirectPath
public function redirectPath()
{
if (\Auth::user()->isUser('user')) {
return '/home';
}
return '/dashboard';
}
示例8: postReset
/**
* Reset the given user's password.
*
* @param Request $request
* @return Response
*/
public function postReset(Request $request)
{
$this->validate($request, ['token' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed']);
$credentials = $request->only('email', 'password', 'password_confirmation', 'token');
// print_r($credentials);
// die;
$response = $this->passwords->reset($credentials, function ($user, $password) {
echo "reset password";
die;
$user->password = bcrypt($password);
$user->save();
$this->auth->login($user);
});
switch ($response) {
case PasswordBroker::PASSWORD_RESET:
$user = \Auth::user();
if ($user->email_activated != '1') {
$user->email_activated = '1';
$user->email_activated_at = new \DateTime();
$user->save();
}
return redirect($this->redirectPath());
default:
return redirect()->back()->withInput($request->only('email'))->withErrors(['email' => trans($response)]);
}
}
示例9: getRegister
public function getRegister()
{
if (\Auth::user()) {
return view('auth.register');
} else {
return redirect(url('/'));
}
}
示例10: redirectPath
public function redirectPath()
{
// Logic that determines where to send the user
if (\Auth::user()->type == 'admin') {
return '/admin';
}
return '/dashboard';
}
示例11: verify
public function verify($username, $password)
{
$credentials = ['email' => $username, 'password' => $password];
if (Auth::once($credentials)) {
return Auth::user()->id;
}
return false;
}
示例12: postIndex
public function postIndex(Request $req)
{
$username = \Auth::user()->username;
if (\Auth::attempt(['username' => $username, 'password' => $req->password])) {
$req->session()->forget('lock');
return redirect('/');
}
return redirect()->back()->withErr('* Kata sandi tidak cocok!');
}
示例13: getUser
public function getUser()
{
$responseData = \Auth::user()->toArray();
$responseData['pingBaseUrl'] = \App\Ping::baseUrl();
$responseData['avatar'] = \Gravatar::get($responseData['email']);
unset($responseData['id']);
unset($responseData['updated_at']);
return response($responseData, 200);
}
示例14: handleUserWasAuthenticated
protected function handleUserWasAuthenticated(Request $request, $throttles)
{
if ($throttles) {
$this->clearLoginAttempts($request);
}
if (method_exists($this, 'authenticated')) {
return $this->authenticated($request, Auth::user());
}
return redirect()->intended($this->redirectPath());
}
示例15: postLogin
public function postLogin(Request $request)
{
$auth = \Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')]);
if ($auth) {
\Session::set('user', \Auth::user());
return redirect("/home");
} else {
return redirect("/");
}
}