Update RegisterController, validate username against restricted names

This commit is contained in:
Daniel Supernault 2018-04-29 10:29:38 -06:00
parent 594576185b
commit 91fd53a4be

View file

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth; namespace App\Http\Controllers\Auth;
use App\User; use App\User;
use App\Util\Lexer\RestrictedNames;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
@ -48,6 +49,8 @@ class RegisterController extends Controller
*/ */
protected function validator(array $data) protected function validator(array $data)
{ {
$this->validateUsername($data['username']);
return Validator::make($data, [ return Validator::make($data, [
'name' => 'required|string|max:255', 'name' => 'required|string|max:255',
'username' => 'required|alpha_dash|min:2|max:15|unique:users', 'username' => 'required|alpha_dash|min:2|max:15|unique:users',
@ -71,4 +74,13 @@ class RegisterController extends Controller
'password' => Hash::make($data['password']), 'password' => Hash::make($data['password']),
]); ]);
} }
public function validateUsername($username)
{
$restricted = RestrictedNames::get();
if(in_array($username, $restricted)) {
return abort(403);
}
}
} }