This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
memberdb/app/Http/Controllers/Auth/RegisterController.php

102 lines
2.5 KiB
PHP
Raw Normal View History

2016-10-13 04:56:01 +00:00
<?php
namespace App\Http\Controllers\Auth;
use App\Account;
2016-10-13 04:56:01 +00:00
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
use Clarkeash\Doorman\Facades\Doorman;
use clarkeash\Doorman\Exceptions\DoormanException;
2016-10-13 04:56:01 +00:00
/**
* Class RegisterController
* @package %%NAMESPACE%%\Http\Controllers\Auth
*/
2016-10-13 04:56:01 +00: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.
|
*/
2016-10-13 04:56:01 +00:00
use RegistersUsers;
2016-10-13 04:56:01 +00:00
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/home';
2016-10-13 04:56:01 +00:00
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
2016-10-13 04:56:01 +00: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, [
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'username' => 'sometimes|required|max:255|unique:users',
'email' => 'required|email|max:255|unique:account',
// 'token' => 'required|doorman:email',
'password' => 'required|min:6|confirmed',
'terms' => 'required',
]);
}
2016-10-13 04:56:01 +00:00
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return Account
*/
protected function create(array $data)
{
$fields = [
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'country_id' => 61, // @todo Need to add this to the registration form
];
if (config('auth.providers.users.field','email') === 'username' && isset($data['username'])) {
$fields['username'] = $data['username'];
}
if (config('auth.requiretoken'))
{
try {
Doorman::redeem($data['token'],$data['email']);
//@todo This is not working with AdminLTE - need to figure this out.
// Want to direct or display an appropriate error message (although the form validation does it anyway).
} catch (DoormanException $e) {
redirect('/error');
abort(403);
}
}
return Account::create($fields);
}
}