Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding and loading options from config #427

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be included. It should be part of your global system ignore file, not a project ignore file.

11 changes: 8 additions & 3 deletions src/Confide/EloquentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,18 @@ public function getUserByEmailOrUsername($emailOrUsername)
*
* @param string $code
*
* @return bool Success
* @return bool Success or Null for nothing affected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return bool|void Success or null for nothing affected

*/
public function confirmByCode($code)
{
$identity = ['confirmation_code' => $code];

$user = $this->getUserByIdentity($identity);

if ($user) {
if ($user->confirmed == null) {
return $this->confirmUser($user);
} else if ($user) {
return null;
} else {
return false;
}
Expand All @@ -143,7 +145,10 @@ public function confirmByCode($code)
*/
protected function confirmUser($user)
{
$user->confirmed = true;
$date = new \DateTime();
$date->setTimezone(new \DateTimeZone('UTC'));

$user->confirmed = $date->format('Y-m-d H:i:s');

return $user->save();
}
Expand Down
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using as here? Surely we can ditch that totally?

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',
]
]
],
);