<?php
-namespace Oxbow\Http\Controllers\Auth;
+namespace BookStack\Http\Controllers\Auth;
+use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\Request;
-use Oxbow\Exceptions\SocialSignInException;
-use Oxbow\Exceptions\UserRegistrationException;
-use Oxbow\Repos\UserRepo;
-use Oxbow\Services\EmailConfirmationService;
-use Oxbow\Services\SocialAuthService;
-use Oxbow\SocialAccount;
+use BookStack\Exceptions\SocialSignInException;
+use BookStack\Exceptions\UserRegistrationException;
+use BookStack\Repos\UserRepo;
+use BookStack\Services\EmailConfirmationService;
+use BookStack\Services\SocialAuthService;
+use BookStack\SocialAccount;
use Validator;
-use Oxbow\Http\Controllers\Controller;
+use BookStack\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
- protected $loginPath = '/login';
protected $redirectPath = '/';
protected $redirectAfterLogout = '/login';
+ protected $username = 'email';
+
protected $socialAuthService;
protected $emailConfirmationService;
$this->socialAuthService = $socialAuthService;
$this->emailConfirmationService = $emailConfirmationService;
$this->userRepo = $userRepo;
+ $this->username = config('auth.method') === 'standard' ? 'email' : 'username';
parent::__construct();
}
return $this->registerUser($userData);
}
+
+ /**
+ * Overrides the action when a user is authenticated.
+ * If the user authenticated but does not exist in the user table we create them.
+ * @param Request $request
+ * @param Authenticatable $user
+ * @return \Illuminate\Http\RedirectResponse
+ */
+ protected function authenticated(Request $request, Authenticatable $user)
+ {
+ // Explicitly log them out for now if they do no exist.
+ if (!$user->exists) auth()->logout($user);
+
+ if (!$user->exists && $user->email === null && !$request->has('email')) {
+ $request->flash();
+ session()->flash('request-email', true);
+ return redirect('/login');
+ }
+
+ if (!$user->exists && $user->email === null && $request->has('email')) {
+ $user->email = $request->get('email');
+ }
+
+ if (!$user->exists) {
+ $user->save();
+ $this->userRepo->attachDefaultRole($user);
+ auth()->login($user);
+ }
+
+ return redirect()->intended($this->redirectPath());
+ }
+
/**
* Register a new user after a registration callback.
* @param $socialDriver
* @param bool|false|SocialAccount $socialAccount
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws UserRegistrationException
- * @throws \Oxbow\Exceptions\ConfirmationEmailException
+ * @throws \BookStack\Exceptions\ConfirmationEmailException
*/
protected function registerUser(array $userData, $socialAccount = false)
{
return redirect('/register/confirm');
}
+ $newUser->email_confirmed = true;
+
auth()->login($newUser);
session()->flash('success', 'Thanks for signing up! You are now registered and signed in.');
return redirect($this->redirectPath());
}
/**
- * Show the page to tell the user to check thier email
+ * Show the page to tell the user to check their email
* and confirm their address.
*/
public function getRegisterConfirmation()
return view('auth/register-confirm');
}
+ /**
+ * View the confirmation email as a standard web page.
+ * @param $token
+ * @return \Illuminate\View\View
+ * @throws UserRegistrationException
+ */
+ public function viewConfirmEmail($token)
+ {
+ $confirmation = $this->emailConfirmationService->getEmailConfirmationFromToken($token);
+ return view('emails/email-confirmation', ['token' => $confirmation->token]);
+ }
+
/**
* Confirms an email via a token and logs the user into the system.
* @param $token
]);
$user = $this->userRepo->getByEmail($request->get('email'));
$this->emailConfirmationService->sendConfirmation($user);
- \Session::flash('success', 'Confirmation email resent, Please check your inbox.');
+ session()->flash('success', 'Confirmation email resent, Please check your inbox.');
return redirect('/register/confirm');
}
*/
public function getLogin()
{
-
- if (view()->exists('auth.authenticate')) {
- return view('auth.authenticate');
- }
-
$socialDrivers = $this->socialAuthService->getActiveDrivers();
- return view('auth.login', ['socialDrivers' => $socialDrivers]);
+ $authMethod = config('auth.method');
+ return view('auth/login', ['socialDrivers' => $socialDrivers, 'authMethod' => $authMethod]);
}
/**
}
/**
- * Redirect to the social site for authentication initended to register.
+ * Redirect to the social site for authentication intended to register.
* @param $socialDriver
* @return mixed
*/