Fix username validation and auto-generation, closes #927

This commit is contained in:
Dane Everitt 2018-02-11 16:39:50 -06:00
parent c3dc376c4c
commit bf537922a3
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
7 changed files with 159 additions and 41 deletions

View file

@ -4,6 +4,7 @@ namespace Pterodactyl\Models;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Validable;
use Pterodactyl\Rules\Username;
use Illuminate\Validation\Rules\In;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
@ -151,7 +152,7 @@ class User extends Model implements
'uuid' => 'string|size:36|unique:users,uuid',
'email' => 'email|unique:users,email',
'external_id' => 'nullable|string|max:255|unique:users,external_id',
'username' => 'alpha_dash|between:1,255|unique:users,username',
'username' => 'between:1,255|unique:users,username',
'name_first' => 'string|between:1,255',
'name_last' => 'string|between:1,255',
'password' => 'nullable|string',
@ -169,6 +170,7 @@ class User extends Model implements
{
$rules = self::eloquenceGatherRules();
$rules['language'][] = new In(array_keys((new self)->getAvailableLanguages()));
$rules['username'][] = new Username;
return $rules;
}
@ -188,9 +190,9 @@ class User extends Model implements
*
* @param string $value
*/
public function setUsernameAttribute($value)
public function setUsernameAttribute(string $value)
{
$this->attributes['username'] = strtolower($value);
$this->attributes['username'] = mb_strtolower($value);
}
/**