mirror of
https://github.com/flarum/core.git
synced 2025-05-09 17:05:22 +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) {
|
saveAndDismissComposer: function(model) {
|
||||||
var composer = this.get('composer');
|
var composer = this.get('composer');
|
||||||
|
var controller = this;
|
||||||
composer.set('content.loading', true);
|
composer.set('content.loading', true);
|
||||||
this.get('alerts').send('clearAlerts');
|
this.get('alerts').send('clearAlerts');
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ class CreateUsersTable extends Migration {
|
|||||||
Schema::create('users', function(Blueprint $table)
|
Schema::create('users', function(Blueprint $table)
|
||||||
{
|
{
|
||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
$table->string('username');
|
$table->string('username')->unique();
|
||||||
$table->string('email');
|
$table->string('email')->unique();
|
||||||
$table->boolean('is_confirmed')->default(0);
|
$table->boolean('is_confirmed')->default(0);
|
||||||
$table->string('confirmation_token')->nullable();
|
$table->string('confirmation_token')->nullable();
|
||||||
$table->boolean('is_activated')->default(0);
|
$table->boolean('is_activated')->default(0);
|
||||||
|
@ -38,6 +38,20 @@ class Model extends Eloquent
|
|||||||
*/
|
*/
|
||||||
protected static $validator;
|
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.
|
* Define the relationship with the forum.
|
||||||
*
|
*
|
||||||
@ -87,7 +101,8 @@ class Model extends Eloquent
|
|||||||
*/
|
*/
|
||||||
public function assertValid()
|
public function assertValid()
|
||||||
{
|
{
|
||||||
if ($this->makeValidator()->fails()) {
|
$validation = $this->makeValidator();
|
||||||
|
if ($validation->fails()) {
|
||||||
throw (new ValidationFailureException)
|
throw (new ValidationFailureException)
|
||||||
->setErrors($validation->errors())
|
->setErrors($validation->errors())
|
||||||
->setInput($validation->getData());
|
->setInput($validation->getData());
|
||||||
@ -103,7 +118,7 @@ class Model extends Eloquent
|
|||||||
{
|
{
|
||||||
$rules = $this->expandUniqueRules(static::$rules);
|
$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
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $rules = [
|
public static $rules = [
|
||||||
'username' => 'required|username|unique',
|
'username' => 'required|unique',
|
||||||
'email' => 'required|email|unique',
|
'email' => 'required|email|unique',
|
||||||
'password' => 'required',
|
'password' => 'required',
|
||||||
'join_time' => 'date',
|
'join_time' => 'date',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user