2015-07-08 03:34:58 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
|
|
|
use App\User;
|
|
|
|
use App\Http\Controllers\Controller;
|
2016-10-26 11:05:43 -04:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2016-08-19 16:38:49 -04:00
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2016-08-19 16:38:49 -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, [
|
2017-09-26 13:22:15 -04:00
|
|
|
'name' => 'required|string|max:255',
|
|
|
|
'email' => 'required|string|email|max:255|unique:users',
|
|
|
|
'password' => 'required|string|min:6|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)
|
|
|
|
{
|
2016-01-26 23:20:08 -05:00
|
|
|
if (env('REGISTRATION', false)) {
|
|
|
|
return User::create([
|
2016-08-19 16:38:49 -04:00
|
|
|
'name' => $data['name'],
|
|
|
|
'email' => $data['email'],
|
2016-01-26 23:20:08 -05:00
|
|
|
'password' => bcrypt($data['password']),
|
2017-11-21 23:12:31 -05:00
|
|
|
'api_token' => str_random(60)
|
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()
|
|
|
|
{
|
|
|
|
if (env('REGISTRATION', false)) {
|
|
|
|
return view('auth.register');
|
|
|
|
} else {
|
|
|
|
header('Location: /login');
|
|
|
|
}
|
|
|
|
}
|
2015-07-08 03:34:58 -04:00
|
|
|
}
|