diff --git a/ember/app/mixins/use-composer.js b/ember/app/mixins/use-composer.js index 971a09ea3..2af36e73d 100644 --- a/ember/app/mixins/use-composer.js +++ b/ember/app/mixins/use-composer.js @@ -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'); diff --git a/migrations/2015_02_24_000000_create_users_table.php b/migrations/2015_02_24_000000_create_users_table.php index 58d4e7f3d..efb562258 100644 --- a/migrations/2015_02_24_000000_create_users_table.php +++ b/migrations/2015_02_24_000000_create_users_table.php @@ -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); diff --git a/src/Core/Models/Model.php b/src/Core/Models/Model.php index 5140902ce..7412858cb 100755 --- a/src/Core/Models/Model.php +++ b/src/Core/Models/Model.php @@ -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); } /** diff --git a/src/Core/Models/User.php b/src/Core/Models/User.php index 8bcd84285..c71e9b126 100755 --- a/src/Core/Models/User.php +++ b/src/Core/Models/User.php @@ -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',