Skip to content

Commit

Permalink
Refactor auth component.
Browse files Browse the repository at this point in the history
Reorganize methods, refactor code, general cleaning.
  • Loading branch information
taylorotwell committed Dec 23, 2016
1 parent 87ae38c commit 7b48bfc
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 238 deletions.
11 changes: 1 addition & 10 deletions src/Illuminate/Auth/Events/Attempting.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@ class Attempting
*/
public $remember;

/**
* Indicates if the user should be authenticated if successful.
*
* @var bool
*/
public $login;

/**
* Create a new event instance.
*
* @param array $credentials
* @param bool $remember
* @param bool $login
*/
public function __construct($credentials, $remember, $login)
public function __construct($credentials, $remember)
{
$this->login = $login;
$this->remember = $remember;
$this->credentials = $credentials;
}
Expand Down
78 changes: 78 additions & 0 deletions src/Illuminate/Auth/Recaller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Illuminate\Auth;

use Illuminate\Support\Str;

class Recaller
{
/**
* The "recaller" / "remember me" cookie string.
*
* @var string
*/
protected $recaller;

/**
* Create a new recaller instance.
*
* @param string $recaller
* @return void
*/
public function __construct($recaller)
{
$this->recaller = $recaller;
}

/**
* Get the user ID from the recaller.
*
* @return string
*/
public function id()
{
return explode('|', $this->recaller, 2)[0];
}

/**
* Get the "remember token" token from the recaller.
*
* @return string
*/
public function token()
{
return explode('|', $this->recaller, 2)[1];
}

/**
* Determine if the recaller is valid.
*
* @return bool
*/
public function valid()
{
return $this->properString() && $this->hasBothSegments();
}

/**
* Determine if the recaller is an invalid string.
*
* @return bool
*/
protected function properString()
{
return is_string($this->recaller) && Str::contains($this->recaller, '|');
}

/**
* Determine if the recaller has both segments.
*
* @return bool
*/
protected function hasBothSegments()
{
$segments = explode('|', $this->recaller);

return count($segments) == 2 && trim($segments[0]) !== '' && trim($segments[1]) !== '';
}
}
4 changes: 3 additions & 1 deletion src/Illuminate/Auth/RequestGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function user()
return $this->user;
}

return $this->user = call_user_func($this->callback, $this->request);
return $this->user = call_user_func(
$this->callback, $this->request
);
}

/**
Expand Down
Loading

0 comments on commit 7b48bfc

Please sign in to comment.