Skip to content

Commit

Permalink
Merge 8b19f79 into c1280c4
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleymilan committed Oct 1, 2014
2 parents c1280c4 + 8b19f79 commit b55495d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
composer.lock
composer.lock
.DS_Store
22 changes: 9 additions & 13 deletions src/Confide/UserValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\Facades\App as App;
use Illuminate\Support\Facades\Lang as Lang;
use Illuminate\Support\Facades\Config as Config;
use Illuminate\Support\MessageBag;

/**
Expand Down Expand Up @@ -41,18 +42,13 @@ class UserValidator implements UserValidatorInterface
*
* @var array
*/
public $rules = [
'create' => [
'username' => 'required|alpha_dash',
'email' => 'required|email',
'password' => 'required|min:4',
],
'update' => [
'username' => 'required|alpha_dash',
'email' => 'required|email',
'password' => 'required|min:4',
]
];
public $rules = array();

public function __construct()
{
//This provides you configure you validation rules directly in Config file
$this->rules = Config::get('confide::rules');
}

/**
* Validates the given user. Should check if all the fields are correctly.
Expand Down Expand Up @@ -160,7 +156,7 @@ public function validateAttributes(ConfideUserInterface $user, $ruleset = 'creat
// Force getting password since it may be hidden from array form
$attributes['password'] = $user->getAuthPassword();

$rules = $this->rules[$ruleset];
$rules = $this->rules[Config::get('confide::username_type')][$ruleset];

$validator = App::make('validator')
->make($attributes, $rules);
Expand Down
47 changes: 47 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

return array(

/*
|--------------------------------------------------------------------------
| Username type
|--------------------------------------------------------------------------
|
| You can use an alpha numeric username (alpha) or e-mail as username (email)
|
| Default: email
|
*/
'username_type' => 'email',

/*
|--------------------------------------------------------------------------
| Login Throttle
Expand Down Expand Up @@ -126,4 +138,39 @@
*/
'email_queue' => 'default',

/*
|--------------------------------------------------------------------------
| Validation Rules
|--------------------------------------------------------------------------
|
| Modify the lines below to customize your own User Model Validation with
| no needs to extend or overwrite the UserInterface of Confide
|
*/
'rules' => [
'alpha' => [
'create' => [
'username' => 'required|alpha_dash',
'email' => 'required|email',
'password' => 'required|min:4',
],
'update' => [
'username' => 'required|alpha_dash',
'email' => 'required|email',
'password' => 'required|min:4',
]
],
'email' => [
'create' => [
'username' => 'required|email|same:email',
'email' => 'required|email',
'password' => 'required|min:4',
],
'update' => [
'username' => 'required|email|same:email',
'email' => 'required|email',
'password' => 'required|min:4',
]
]
],
);

0 comments on commit b55495d

Please sign in to comment.