hypothetical/app/Http/Controllers/Auth/RegisterController.php

89 lines
2.2 KiB
PHP
Raw Normal View History

<?php namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
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;
2016-08-19 16:38:49 -04:00
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller {
/*
|--------------------------------------------------------------------------
2016-08-19 16:38:49 -04:00
| Register Controller
|--------------------------------------------------------------------------
|
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.
|
*/
2016-08-19 16:38:49 -04:00
use RegistersUsers;
/**
2017-01-26 19:17:37 -05:00
* Where to redirect users after registration.
2016-01-03 23:55:13 -05:00
*
* @var string
*/
2016-01-03 23:55:13 -05:00
protected $redirectTo = '/dashboard';
/**
2016-08-19 16:38:49 -04:00
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
2016-08-19 16:38:49 -04:00
$this->middleware('guest');
}
/**
* 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, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
if (env('REGISTRATION', false)) {
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']),
'api_token' => str_random(60)
]);
}
}
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');
}
}
}