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

Feature/configurable credentials naming #27

Open
wants to merge 3 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
12 changes: 8 additions & 4 deletions src/Tappleby/AuthToken/AuthTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Request;
use Input;
use Validator;
use Config;

class AuthTokenController extends Controller {

Expand Down Expand Up @@ -67,15 +68,18 @@ public function store() {
$input = Input::all();

$validator = Validator::make(
$input,
array('username' => array('required'), 'password' => array('required'))
);
$input,
array(
Config::get('laravel-auth-token::login_credential') => Config::get('laravel-auth-token::login_credential_rules'),
Config::get('laravel-auth-token::password_credential') => Config::get('laravel-auth-token::password_credential_rules'),
)
);

if($validator->fails()) {
throw new NotAuthorizedException();
}

$creds = call_user_func($this->credentialsFormatter, $input['username'], $input['password']);
$creds = call_user_func($this->credentialsFormatter, $input[Config::get('laravel-auth-token::login_credential')], $input[Config::get('laravel-auth-token::password_credential')]);
$token = $this->driver->attempt($creds);

if(!$token) {
Expand Down
11 changes: 10 additions & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@
'email' => $username,
'password' => $password
);
}
},
/**
* Transforms login and password into fields that are received via POST
*
* Rules are also specified
*/
'login_credential' => 'username',
'login_credential_rules' => array('required'),
'password_credential' => 'password',
'password_credential_rules' => array('required'),
);