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

Upadate the key of table name of password #549

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "~4.2|~5.0"
"illuminate/support": "~5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.9",
"illuminate/auth": "~4.2",
"illuminate/console": "~4.2",
"illuminate/database": "~4.2",
"illuminate/console": "~5.0",
"illuminate/database": "~5.0",
"satooshi/php-coveralls": "~0.6"
},
"suggest": {
Expand All @@ -33,6 +32,9 @@
"src/migrations",
"src/commands"
],
"files": [
"tests/Confide/helpers.php"
],
"psr-4": {
"Zizaco\\Confide\\": "src/Confide/"
}
Expand Down
18 changes: 10 additions & 8 deletions src/Confide/CacheLoginThrottleService.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace Zizaco\Confide;

use Illuminate\Contracts\Foundation\Application;

/**
* The LoginThrottle is a service that Throttles login after
* too many failed attempts. This is a secure measure in
Expand All @@ -13,18 +15,18 @@ class CacheLoginThrottleService implements LoginThrottleServiceInterface
/**
* Laravel application.
*
* @var \Illuminate\Foundation\Application
* @var \Illuminate\Contracts\Foundation\Application
*/
public $app;

/**
* Create a new PasswordService.
*
* @param \Illuminate\Foundation\Application $app Laravel application object.
* @param \Illuminate\Contracts\Foundation\Application $app Laravel application object.
*/
public function __construct($app = null)
public function __construct(Application $app)
{
$this->app = $app ?: app();
$this->app = $app;
}

/**
Expand Down Expand Up @@ -57,7 +59,7 @@ public function isThrottled($identity)
// Retuns the current count
$count = $this->countThrottle($identity, 0);

return $count >= $this->app['config']->get('confide::throttle_limit');
return $count >= $this->app->make('config')->get('confide::throttle_limit');
}

/**
Expand Down Expand Up @@ -97,14 +99,14 @@ protected function parseIdentity($identity)
*/
protected function countThrottle($identityString, $increments = 1)
{
$count = $this->app['cache']
$count = $this->app->make('cache')
->get('login_throttling:'.md5($identityString), 0);

$count = $count + $increments;

$ttl = $this->app['config']->get('confide::throttle_time_period');
$ttl = $this->app->make('config')->get('confide::throttle_time_period');

$this->app['cache']
$this->app->make('cache')
->put('login_throttling:'.md5($identityString), $count, $ttl);

return $count;
Expand Down
30 changes: 16 additions & 14 deletions src/Confide/Confide.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace Zizaco\Confide;

use Illuminate\Contracts\Foundation\Application;

/**
* This class is the main entry point to use the confide
* services. Usually this is the only service class that the
Expand All @@ -13,7 +15,7 @@ class Confide
/**
* Laravel application.
*
* @var \Illuminate\Foundation\Application
* @var \Illuminate\Contracts\Foundation\Application
*/
public $app;

Expand Down Expand Up @@ -44,20 +46,20 @@ class Confide
* @param \Zizaco\Confide\RepositoryInterface $repo
* @param \Zizaco\Confide\PasswordServiceInterface $passService
* @param \Zizaco\Confide\LoginThrottleServiceInterface $loginThrottler
* @param \Illuminate\Foundation\Application $app Laravel application object
* @param \Illuminate\Contracts\Foundation\Application $app Laravel application object
*
* @return void
*/
public function __construct(
RepositoryInterface $repo,
PasswordServiceInterface $passService,
LoginThrottleServiceInterface $loginThrottler,
$app = null
Application $app
) {
$this->repo = $repo;
$this->passService = $passService;
$this->loginThrottler = $loginThrottler;
$this->app = $app ?: app();
$this->app = $app;
}

/**
Expand All @@ -77,7 +79,7 @@ public function model()
*/
public function user()
{
return $this->app['auth']->user();
return $this->app->make('auth')->user();
}

/**
Expand Down Expand Up @@ -135,7 +137,7 @@ public function logAttempt(array $input, $mustBeConfirmed = true)
return false;
}

$correctPassword = $this->app['hash']->check(
$correctPassword = $this->app->make('hash')->check(
isset($input['password']) ? $input['password'] : false,
$user->password
);
Expand All @@ -144,7 +146,7 @@ public function logAttempt(array $input, $mustBeConfirmed = true)
return false;
}

$this->app['auth']->login($user, $remember);
$this->app->make('auth')->login($user, $remember);
return true;
}

Expand Down Expand Up @@ -199,7 +201,7 @@ protected function loginThrottling($identity)
$count = $this->loginThrottler
->throttleIdentity($identity);

if ($count >= $this->app['config']->get('confide::throttle_limit')) {
if ($count >= $this->app->make('config')->get('confide::throttle_limit')) {
return false;
}

Expand Down Expand Up @@ -280,7 +282,7 @@ public function userByResetPasswordToken($token)
*/
public function logout()
{
return $this->app['auth']->logout();
return $this->app->make('auth')->logout();
}

/**
Expand All @@ -290,7 +292,7 @@ public function logout()
*/
public function makeLoginForm()
{
return $this->app['view']->make($this->app['config']->get('confide::login_form'));
return $this->app->make('view')->make($this->app->make('config')->get('confide::login_form'));
}

/**
Expand All @@ -300,7 +302,7 @@ public function makeLoginForm()
*/
public function makeSignupForm()
{
return $this->app['view']->make($this->app['config']->get('confide::signup_form'));
return $this->app->make('view')->make($this->app->make('config')->get('confide::signup_form'));
}

/**
Expand All @@ -310,7 +312,7 @@ public function makeSignupForm()
*/
public function makeForgotPasswordForm()
{
return $this->app['view']->make($this->app['config']->get('confide::forgot_password_form'));
return $this->app->make('view')->make($this->app->make('config')->get('confide::forgot_password_form'));
}

/**
Expand All @@ -320,8 +322,8 @@ public function makeForgotPasswordForm()
*/
public function makeResetPasswordForm($token)
{
return $this->app['view']->make(
$this->app['config']->get('confide::reset_password_form'),
return $this->app->make('view')->make(
$this->app->make('config')->get('confide::reset_password_form'),
array('token' => $token)
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Confide/ConfideUserInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace Zizaco\Confide;

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
use Illuminate\Contracts\Auth\Authenticatable;

/**
* Interface that declares the methods that must be
Expand All @@ -14,7 +13,7 @@
* @license MIT
* @package Zizaco\Confide
*/
interface ConfideUserInterface extends UserInterface, RemindableInterface
interface ConfideUserInterface extends Authenticatable
{
/**
* Confirm the user (usually means that the user) email is valid.
Expand Down
35 changes: 18 additions & 17 deletions src/Confide/EloquentPasswordService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Zizaco\Confide;

use Illuminate\Auth\Reminders\RemindableInterface;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Foundation\Application;

/**
* A service that abstracts all user password management related methods.
Expand All @@ -13,30 +14,30 @@ class EloquentPasswordService implements PasswordServiceInterface
/**
* Laravel application.
*
* @var \Illuminate\Foundation\Application
* @var \Illuminate\Contracts\Foundation\Application
*/
public $app;

/**
* Create a new PasswordService.
*
* @param \Illuminate\Foundation\Application $app Laravel application object
* @param \Illuminate\Contracts\Foundation\Application $app Laravel application object
*/
public function __construct($app = null)
public function __construct(Application $app)
{
$this->app = $app ?: app();
$this->app = $app;
}

/**
* Generate a token for password change and saves it in
* the 'password_reminders' table with the email of the
* user.
*
* @param RemindableInterface $user An existent user.
* @param Authenticatable $user An existent user.
*
* @return string Password reset token.
*/
public function requestChangePassword(RemindableInterface $user)
public function requestChangePassword(Authenticatable $user)
{
$email = $user->getReminderEmail();
$token = $this->generateToken();
Expand All @@ -49,7 +50,7 @@ public function requestChangePassword(RemindableInterface $user)

$table = $this->getTable();

$this->app['db']
$this->app->make('db')
->connection($user->getConnectionName())
->table($table)
->insert($values);
Expand All @@ -72,7 +73,7 @@ public function getEmailByToken($token)
$connection = $this->getConnection();
$table = $this->getTable();

$email = $this->app['db']
$email = $this->app->make('db')
->connection($connection)
->table($table)
->select('email')
Expand All @@ -97,7 +98,7 @@ public function destroyToken($token)
$connection = $this->getConnection();
$table = $this->getTable();

$affected = $this->app['db']
$affected = $this->app->make('db')
->connection($connection)
->table($table)
->where('token', '=', $token)
Expand All @@ -115,7 +116,7 @@ public function destroyToken($token)
*/
protected function getConnection()
{
return $this->app['confide.repository']
return $this->app->make('confide.repository')
->model()->getConnectionName();
}

Expand All @@ -126,7 +127,7 @@ protected function getConnection()
*/
protected function getTable()
{
return $this->app['config']->get('auth.reminder.table');
return $this->app->make('config')->get('auth.reminder.table');
}

/**
Expand Down Expand Up @@ -168,10 +169,10 @@ protected function unwrapEmail($email)
*/
protected function sendEmail($user, $token)
{
$config = $this->app['config'];
$lang = $this->app['translator'];
$config = $this->app->make('config');
$lang = $this->app->make('translator');

$this->app['mailer']->queueOn(
$this->app->make('mailer')->queueOn(
$config->get('confide::email_queue'),
$config->get('confide::email_reset_password'),
compact('user', 'token'),
Expand All @@ -192,8 +193,8 @@ protected function getOldestValidDate()
{
// Instantiate a carbon object (that is a dependency of
// 'illuminate/database')
$carbon = $this->app['Carbon\Carbon'];
$config = $this->app['config'];
$carbon = $this->app->make('Carbon\Carbon');
$config = $this->app->make('config');

return $carbon->now()
->subHours($config->get('confide::confide.password_reset_expiration', 7))
Expand Down
16 changes: 9 additions & 7 deletions src/Confide/EloquentRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace Zizaco\Confide;

use Illuminate\Contracts\Foundation\Application;

/**
* A service that abstracts all database interactions that happens
* in Confide using Eloquent.
Expand All @@ -12,7 +14,7 @@ class EloquentRepository implements RepositoryInterface
/**
* Laravel application.
*
* @var \Illuminate\Foundation\Application
* @var \Illuminate\Contracts\Foundation\Application
*/
public $app;

Expand All @@ -28,11 +30,11 @@ class EloquentRepository implements RepositoryInterface
/**
* Create a new ConfideRepository
*
* @param \Illuminate\Foundation\Application $app Laravel application object
* @param \Illuminate\Contracts\Foundation\Application $app Laravel application object
*/
public function __construct($app = null)
public function __construct(Application $app)
{
$this->app = $app ?: app();
$this->app = $app;
}

/**
Expand All @@ -43,11 +45,11 @@ public function __construct($app = null)
public function model()
{
if (! $this->model) {
$this->model = $this->app['config']->get('auth.model');
$this->model = $this->app->make('config')->get('auth.model');
}

if ($this->model) {
return $this->app[$this->model];
return $this->app->make($this->model);
}

throw new \Exception("Wrong model specified in config/auth.php", 639);
Expand All @@ -66,7 +68,7 @@ public function getUserByIdentity($identity)
{
$user = $this->model();

$user = $user->where(function($user) use ($identity) {
$user = $user->where(function ($user) use ($identity) {
foreach ($identity as $attribute => $value) {
$user = $user->orWhere($attribute, '=', $value);
}
Expand Down
Loading