mirror of
https://github.com/flarum/core.git
synced 2025-05-06 15:35:38 +02:00
Add model validation back in
This commit is contained in:
parent
cfb89de251
commit
074b4d0989
@ -12,6 +12,7 @@ export default Ember.Mixin.create({
|
||||
|
||||
saveAndDismissComposer: function(model) {
|
||||
var composer = this.get('composer');
|
||||
var controller = this;
|
||||
composer.set('content.loading', true);
|
||||
this.get('alerts').send('clearAlerts');
|
||||
|
||||
|
@ -15,8 +15,8 @@ class CreateUsersTable extends Migration {
|
||||
Schema::create('users', function(Blueprint $table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->string('username');
|
||||
$table->string('email');
|
||||
$table->string('username')->unique();
|
||||
$table->string('email')->unique();
|
||||
$table->boolean('is_confirmed')->default(0);
|
||||
$table->string('confirmation_token')->nullable();
|
||||
$table->boolean('is_activated')->default(0);
|
||||
|
@ -38,6 +38,20 @@ class Model extends Eloquent
|
||||
*/
|
||||
protected static $validator;
|
||||
|
||||
/**
|
||||
* Validate the model on save.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::saving(function ($model) {
|
||||
$model->assertValid();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the forum.
|
||||
*
|
||||
@ -87,7 +101,8 @@ class Model extends Eloquent
|
||||
*/
|
||||
public function assertValid()
|
||||
{
|
||||
if ($this->makeValidator()->fails()) {
|
||||
$validation = $this->makeValidator();
|
||||
if ($validation->fails()) {
|
||||
throw (new ValidationFailureException)
|
||||
->setErrors($validation->errors())
|
||||
->setInput($validation->getData());
|
||||
@ -103,7 +118,7 @@ class Model extends Eloquent
|
||||
{
|
||||
$rules = $this->expandUniqueRules(static::$rules);
|
||||
|
||||
return $this->validator->make($this->attributes, $rules, static::$messages);
|
||||
return static::$validator->make($this->attributes, $rules);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@ class User extends Model
|
||||
* @var array
|
||||
*/
|
||||
public static $rules = [
|
||||
'username' => 'required|username|unique',
|
||||
'username' => 'required|unique',
|
||||
'email' => 'required|email|unique',
|
||||
'password' => 'required',
|
||||
'join_time' => 'date',
|
||||
|
Loading…
x
Reference in New Issue
Block a user