2018-04-22 22:37:09 -04:00
|
|
|
<?php namespace App\Http\Controllers\Auth;
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2019-10-31 17:24:53 -04:00
|
|
|
use App\Http\Controllers\Controller;
|
2015-07-08 03:34:58 -04:00
|
|
|
use App\User;
|
2018-04-25 21:22:39 -04:00
|
|
|
use App\Dashboard;
|
2019-10-31 17:24:53 -04:00
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
2018-03-05 18:45:02 -05:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
2016-10-26 11:05:43 -04:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2018-04-22 22:37:09 -04:00
|
|
|
class RegisterController extends Controller {
|
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
2016-08-19 16:38:49 -04:00
|
|
|
| Register Controller
|
2015-07-08 03:34:58 -04:00
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
2016-08-19 16:38:49 -04:00
|
|
|
| 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.
|
2015-07-08 03:34:58 -04:00
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-08-19 16:38:49 -04:00
|
|
|
use RegistersUsers;
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2015-12-01 01:07:03 -05:00
|
|
|
/**
|
2017-01-26 19:17:37 -05:00
|
|
|
* Where to redirect users after registration.
|
2016-01-03 23:55:13 -05:00
|
|
|
*
|
|
|
|
* @var string
|
2015-12-01 01:07:03 -05:00
|
|
|
*/
|
2016-01-03 23:55:13 -05:00
|
|
|
protected $redirectTo = '/dashboard';
|
2015-12-01 01:07:03 -05:00
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
/**
|
2016-08-19 16:38:49 -04:00
|
|
|
* Create a new controller instance.
|
2015-07-08 03:34:58 -04:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2016-08-19 16:38:49 -04:00
|
|
|
$this->middleware('guest');
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
/**
|
|
|
|
* Get a validator for an incoming registration request.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @return \Illuminate\Contracts\Validation\Validator
|
|
|
|
*/
|
|
|
|
protected function validator(array $data)
|
|
|
|
{
|
|
|
|
return Validator::make($data, [
|
2018-11-02 18:12:07 -04:00
|
|
|
'name' => ['required', 'string', 'max:255'],
|
|
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
2019-03-19 17:40:13 -04:00
|
|
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
2015-07-08 03:34:58 -04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new user instance after a valid registration.
|
|
|
|
*
|
|
|
|
* @param array $data
|
2017-09-26 13:22:15 -04:00
|
|
|
* @return \App\User
|
2015-07-08 03:34:58 -04:00
|
|
|
*/
|
|
|
|
protected function create(array $data)
|
|
|
|
{
|
2018-04-25 21:22:39 -04:00
|
|
|
if (Dashboard::canRegister()) {
|
2016-01-26 23:20:08 -05:00
|
|
|
return User::create([
|
2016-08-19 16:38:49 -04:00
|
|
|
'name' => $data['name'],
|
|
|
|
'email' => $data['email'],
|
2018-03-05 18:45:02 -05:00
|
|
|
'password' => Hash::make($data['password']),
|
2017-11-21 23:12:31 -05:00
|
|
|
'api_token' => str_random(60)
|
2016-01-26 23:20:08 -05:00
|
|
|
]);
|
2018-04-25 21:22:39 -04:00
|
|
|
} else {
|
|
|
|
abort(404);
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
2015-07-08 03:34:58 -04:00
|
|
|
}
|
2016-08-19 16:38:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application registration form.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function showRegistrationForm()
|
|
|
|
{
|
2018-04-25 21:22:39 -04:00
|
|
|
if (Dashboard::canRegister()) {
|
2016-08-19 16:38:49 -04:00
|
|
|
return view('auth.register');
|
|
|
|
} else {
|
|
|
|
header('Location: /login');
|
|
|
|
}
|
|
|
|
}
|
2018-04-22 22:37:09 -04:00
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
}
|