2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
use App\Facade\Theme;
|
2016-09-05 21:43:58 +01:00
|
|
|
use App\Facade\UserConfig;
|
2016-09-06 12:23:14 +01:00
|
|
|
use App\Helpers\MiscHelper;
|
2016-09-08 11:02:49 +01:00
|
|
|
use App\Helpers\RecaptchaHelper;
|
2016-09-06 12:23:14 +01:00
|
|
|
use App\Mail\UserActivationRequired;
|
2018-10-06 09:43:58 +01:00
|
|
|
use App\Traits\ActivatesUsers;
|
2016-09-01 16:23:39 +01:00
|
|
|
use App\User;
|
2016-09-06 12:23:14 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
2016-09-01 16:23:39 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
2016-09-06 14:45:51 +01:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
class RegisterController extends Controller
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Register Controller
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| This controller handles the registration of new users as well as their
|
|
|
|
| validation and creation. By default this controller uses a trait to
|
|
|
|
| provide this functionality without requiring any additional code.
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-10-06 09:43:58 +01:00
|
|
|
use RegistersUsers, ActivatesUsers;
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Where to redirect users after login / registration.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $redirectTo = '/';
|
|
|
|
|
2016-10-01 15:24:22 +01:00
|
|
|
public static function passwordRequirements()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'name' => 'required|max:255',
|
|
|
|
'email' => 'required|email|max:255|unique:users',
|
|
|
|
'password' => 'required|min:6|confirmed',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-09-01 16:23:39 +01:00
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('guest');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a validator for an incoming registration request.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @return \Illuminate\Contracts\Validation\Validator
|
|
|
|
*/
|
2016-09-08 11:02:49 +01:00
|
|
|
protected function validator(Request $request)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
2016-10-01 15:24:22 +01:00
|
|
|
return Validator::make($request->all(), self::passwordRequirements())
|
|
|
|
->after(function($validator) use ($request)
|
2016-09-08 11:02:49 +01:00
|
|
|
{
|
2016-10-01 15:24:22 +01:00
|
|
|
// reCAPTCHA validation
|
|
|
|
if (
|
|
|
|
UserConfig::get('recaptcha_enabled_registration') &&
|
|
|
|
!RecaptchaHelper::validateResponse($request->request->get('g-recaptcha-response'), $request->getClientIp())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
$validator->errors()->add('recaptcha', trans('auth.recaptcha_failed_message'));
|
|
|
|
}
|
|
|
|
});
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new user instance after a valid registration.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
protected function create(array $data)
|
|
|
|
{
|
2018-08-13 22:03:12 +01:00
|
|
|
if (!isset($data['is_activated']))
|
2016-09-06 12:23:14 +01:00
|
|
|
{
|
2018-08-13 22:03:12 +01:00
|
|
|
$data['is_activated'] = true;
|
|
|
|
|
|
|
|
if (UserConfig::get('require_email_verification'))
|
|
|
|
{
|
|
|
|
$data['is_activated'] = false;
|
|
|
|
$data['activation_token'] = MiscHelper::randomString();
|
|
|
|
}
|
2016-09-06 12:23:14 +01:00
|
|
|
}
|
|
|
|
|
2018-08-13 22:03:12 +01:00
|
|
|
$data['password'] = bcrypt($data['password']);
|
|
|
|
$data['is_admin'] = false;
|
|
|
|
unset($data['password_confirmation']);
|
|
|
|
|
|
|
|
return User::create($data);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
2016-09-02 10:42:05 +01:00
|
|
|
|
2016-09-05 21:43:58 +01:00
|
|
|
public function register(Request $request)
|
|
|
|
{
|
2016-09-06 12:23:14 +01:00
|
|
|
if (!UserConfig::get('allow_self_registration'))
|
|
|
|
{
|
|
|
|
return redirect(route('home'));
|
|
|
|
}
|
|
|
|
|
2016-09-08 11:02:49 +01:00
|
|
|
$this->validator($request)->validate();
|
2016-09-06 12:23:14 +01:00
|
|
|
|
2018-08-13 22:03:12 +01:00
|
|
|
$userData = $request->all();
|
|
|
|
|
|
|
|
// Social media login info
|
2018-08-15 14:22:13 +01:00
|
|
|
$registerData = $request->getSession()->get('ssoRegisterData');
|
2018-08-13 22:03:12 +01:00
|
|
|
if (!is_null($registerData))
|
|
|
|
{
|
|
|
|
$userData = array_merge($registerData, $userData);
|
2018-08-15 14:22:13 +01:00
|
|
|
$request->getSession()->remove('ssoRegisterData');
|
2018-08-13 22:03:12 +01:00
|
|
|
}
|
|
|
|
|
2016-09-06 12:23:14 +01:00
|
|
|
/** @var User $user */
|
2018-08-13 22:03:12 +01:00
|
|
|
$user = $this->create($userData);
|
2016-09-06 12:23:14 +01:00
|
|
|
|
|
|
|
if ($user->is_activated)
|
|
|
|
{
|
2018-11-19 13:26:44 +00:00
|
|
|
$this->logActivatedActivity($user);
|
2018-10-06 09:43:58 +01:00
|
|
|
$this->sendUserActivatedEmails($user);
|
2016-09-06 12:23:14 +01:00
|
|
|
$this->guard()->login($user);
|
|
|
|
}
|
|
|
|
else
|
2016-09-05 21:43:58 +01:00
|
|
|
{
|
2016-09-06 12:23:14 +01:00
|
|
|
// Send activation e-mail
|
|
|
|
Mail::to($user)->send(new UserActivationRequired($user));
|
2016-09-06 14:45:51 +01:00
|
|
|
$request->session()->flash('info', trans('auth.activation_required_message'));
|
2016-09-05 21:43:58 +01:00
|
|
|
}
|
|
|
|
|
2016-09-06 12:23:14 +01:00
|
|
|
return redirect($this->redirectPath());
|
2016-09-05 21:43:58 +01:00
|
|
|
}
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
/**
|
|
|
|
* Show the application registration form.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2018-08-13 22:03:12 +01:00
|
|
|
public function showRegistrationForm(Request $request)
|
2016-09-02 10:42:05 +01:00
|
|
|
{
|
2016-09-06 12:23:14 +01:00
|
|
|
if (!UserConfig::get('allow_self_registration'))
|
2016-09-05 21:43:58 +01:00
|
|
|
{
|
2016-09-06 12:23:14 +01:00
|
|
|
return redirect(route('home'));
|
2016-09-05 21:43:58 +01:00
|
|
|
}
|
|
|
|
|
2018-08-15 14:22:13 +01:00
|
|
|
return Theme::render('auth.v2_unified', [
|
|
|
|
'active_tab' => 'register',
|
|
|
|
'is_sso' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application registration form (for a social media-linked account).
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function showRegistrationFormSso(Request $request)
|
|
|
|
{
|
|
|
|
if (!UserConfig::get('allow_self_registration'))
|
|
|
|
{
|
|
|
|
return redirect(route('home'));
|
|
|
|
}
|
|
|
|
|
2018-08-13 22:03:12 +01:00
|
|
|
// Social media login info
|
2018-08-15 14:22:13 +01:00
|
|
|
$registerData = $request->getSession()->get('ssoRegisterData');
|
2018-08-13 22:03:12 +01:00
|
|
|
if (is_null($registerData))
|
|
|
|
{
|
2018-08-15 14:22:13 +01:00
|
|
|
// No SSO data in session, use the normal registration screen
|
|
|
|
return redirect(route('register'));
|
2018-08-13 22:03:12 +01:00
|
|
|
}
|
|
|
|
|
2017-03-23 04:29:29 +00:00
|
|
|
return Theme::render('auth.v2_unified', [
|
2018-08-13 22:03:12 +01:00
|
|
|
'active_tab' => 'register',
|
2018-08-15 14:22:13 +01:00
|
|
|
'is_sso' => true,
|
2018-08-13 22:03:12 +01:00
|
|
|
'register_data' => $registerData
|
2017-03-23 04:29:29 +00:00
|
|
|
]);
|
2016-09-02 10:42:05 +01:00
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|