OctoberCMS User Plugin How to Deny Reserved Names
Ad
I'm using the User plugin.
Here is my previous question on how to Deny Username Change.
I have a list of Reserved Names I don't want people to use (such as admin, anonymous, guest) I need to put in an array and deny upon register.
My Custom Component's Plugin.php
public function boot() {
\RainLab\User\Models\User::extend(function($model) {
$model->bindEvent('model.beforeSave', function() use ($model) {
// Reserved Names List
// Deny Registering if Name in List
});
});
}
How would I do that using the Validator?
Ad
Answer
Ad
You can throw an exception to do that
public function boot() {
\RainLab\User\Models\User::extend(function($model) {
$model->bindEvent('model.beforeSave', function() use ($model) {
$reserved = ['admin','anonymous','guest'];
if(in_array($model->username,$reserved)){
throw new \October\Rain\Exception\ValidationException(['username' => \Lang::get('You can't use a reserved word as username')]);
}
});
});
}
Ad
source: stackoverflow.com
Related Questions
Ad
- → OctoberCMS Backend Loging Hash Error
- → "failed to open stream" error when executing "migrate:make"
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Create plugin that makes objects from model in back-end
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → How to install console for plugin development in October CMS
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → October CMS - Conditionally Load a Different Page
Ad