Skip to content

Commit

Permalink
Merge branch 'release/2.0.0b1a'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew13 committed Oct 17, 2013
2 parents 4430df5 + 5edd1e5 commit 81ae05c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
14 changes: 6 additions & 8 deletions README.md
Expand Up @@ -268,19 +268,15 @@ See [Entrust](https://github.com/Zizaco/entrust)

#### Redirecting to previous route after login

When defining your filter you should set the `'loginRedirect'` session variable. For example:
When defining your filter you should use the Redirect::guest('user/login') within your auth filter. For example:

// filters.php

Route::filter('auth', function()
{
if ( Auth::guest() ) // If the user is not logged in
{
// Set the loginRedirect session variable
Session::put( 'loginRedirect', Request::url() );

// Redirect back to user login
return Redirect::to( 'user/login' );
return Redirect::guest('user/login');
}
});

Expand All @@ -293,9 +289,11 @@ or, if you are using [Entrust](https://github.com/Zizaco/entrust) ;)
// filters.php

Entrust::routeNeedsRole( 'admin*', 'Admin', function(){
Session::put( 'loginRedirect', Request::url() );
return Redirect::to( 'user/login' );
return Redirect::guest('user/login');
} );

Finally, it'll auto redirect if your controller's user/login function uses Redirect:intended('a/default/url/here') after a successful login.
The [generated controller](https://github.com/Zizaco/confide/blob/master/src/views/generators/controller.blade.php) does exactly this.

#### Validating a route

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -17,7 +17,7 @@
"require": {
"php": ">=5.3.0",
"illuminate/support": "*",
"laravelbook/ardent": "1.1.x"
"laravelbook/ardent": "2.1.x"
},
"require-dev": {
"mockery/mockery": "0.7.2",
Expand Down
1 change: 0 additions & 1 deletion src/Zizaco/Confide/Confide.php
Expand Up @@ -290,7 +290,6 @@ protected function attemptCacheKey( $credentials )
{
return 'confide_flogin_attempt_'
.$this->app['request']->server('REMOTE_ADDR')
.$this->app['request']->server('HTTP_X_FORWARDED_FOR')
.$credentials['email'];
}

Expand Down
6 changes: 6 additions & 0 deletions src/Zizaco/Confide/ConfideEloquentRepository.php
Expand Up @@ -273,4 +273,10 @@ public function confirmUser( $user )

return true;
}

public function validate(array $rules = array(), array $customMessages = array())
{
return $this->model()->validate($rules, $customMessages);
}

}
2 changes: 2 additions & 0 deletions src/Zizaco/Confide/ConfideRepository.php
Expand Up @@ -99,4 +99,6 @@ public function userExists( $user );
* @return boolean Success
*/
public function confirmUser( $user );

public function validate(array $rules, array $customMessages);
}
8 changes: 5 additions & 3 deletions src/Zizaco/Confide/ConfideUser.php
Expand Up @@ -181,6 +181,7 @@ public function save( array $rules = array(), array $customMessages = array(), a
}
else
{
static::$app['confide.repository']->validate();
$this->validationErrors->add(
'duplicated',
static::$app['translator']->get('confide::confide.alerts.duplicated_credentials')
Expand Down Expand Up @@ -270,11 +271,12 @@ protected function real_save( array $rules = array(), array $customMessages = ar
/*
* This will make sure that a non modified password
* will not trigger validation error.
* @fixed Pull #110
*/
if( empty($rules) && $this->password == $this->getOriginal('password') )
if( isset($rules['password']) && $this->password == $this->getOriginal('password') )
{
$rules = static::$rules;
$rules['password'] = 'required';
unset($rules['password']);
unset($rules['password_confirmation']);
}

return parent::save( $rules, $customMessages, $options, $beforeSave, $afterSave );
Expand Down
15 changes: 5 additions & 10 deletions src/views/generators/controller.blade.php
Expand Up @@ -103,16 +103,11 @@ public function {{ (! $restful) ? 'do_login' : 'postLogin' }}()
// Get the value from the config file instead of changing the controller
if ( Confide::logAttempt( $input, Config::get('confide::signup_confirm') ) )
{
// If the session 'loginRedirect' is set, then redirect
// to that route. Otherwise redirect to '/'
$r = Session::get('loginRedirect');
if (!empty($r))
{
Session::forget('loginRedirect');
return Redirect::to($r);
}
return Redirect::to('/'); // change it to '/admin', '/dashboard' or something
// Redirect the user to the URL they were trying to access before
// caught by the authentication filter IE Redirect::guest('user/login').
// Otherwise fallback to '/'
// Fix pull #145
return Redirect::intended('/'); // change it to '/admin', '/dashboard' or something
}
else
{
Expand Down
8 changes: 6 additions & 2 deletions tests/ConfideTest.php
Expand Up @@ -120,6 +120,10 @@ public function testShouldThrottleLogAttempt()
{
$tries = 15;

$this->confide->app['request'] = m::mock( 'Request' );
$this->confide->app['request']->shouldReceive('server')
->andReturn( '12.34.56.78' );

$confide_user = $this->mockConfideUser();
$confide_user->shouldReceive('get','first')
->andReturn( null );
Expand All @@ -132,7 +136,7 @@ public function testShouldThrottleLogAttempt()
$this->confide->app['hash']->shouldReceive('check')
->andReturn( false );

for ($i=0; $i < $tries; $i++) {
for ($i=0; $i < $tries; $i++) {

// Simulates cache values
$this->useCacheForThrottling($i);
Expand Down Expand Up @@ -341,7 +345,7 @@ private function useCacheForThrottling( $value )
{
$cache = m::mock('Illuminate\Cache\Store');
$cache->shouldReceive('put')
->with( "confide_flogin_attempt_wrong", $value+1, 2 )
->with( "confide_flogin_attempt_12.34.56.78wrong", $value+1, 2 )
->once();
$cache->shouldReceive('get')
->andReturn( $value );
Expand Down
4 changes: 4 additions & 0 deletions tests/ConfideUserTest.php
Expand Up @@ -121,6 +121,10 @@ public function testShouldNotSaveDuplicated()
->andReturn( 1 )
->once();

ConfideUser::$app['confide.repository']->shouldReceive('validate')
->andReturn( true )
->once();

$this->populateUser();
$this->confide_user->confirmation_code = '';
$this->confide_user->confirmed = false;
Expand Down

0 comments on commit 81ae05c

Please sign in to comment.