Skip to content

Commit

Permalink
✨ major progress
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Aug 31, 2018
1 parent c5f3777 commit 6b7b82e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Guards/HumbleGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ public function check()
return true;
}


$token = false;
$token = request()->get('token') ?: request()->bearerToken() ?: request()->cookie('token') ?: false;

$this->session = Session::where('token', $token)->first();

if ($this->session == null) {
return false;
}

$user = User::where('id', $this->session->user_id)->first();

if ($this->session == null) {
Expand Down Expand Up @@ -69,7 +75,45 @@ public function logout()
$this->token = null;
}

public function attempt(Authenticatable $user)
{

$attempt = Session::create([
'token' => Session::hash(),
'user_id' => $user->id,
'source' => 'attempt',
'cookie' => Session::hash(),
'verified' => false,
'ip' => request()->ip(),
'agent' => request()->Header('User-Agent'),
]);

return $attempt;

}

public function verify(String $token, String $cookie)
{
$this->session = Session::orWhere([
['token', $token],
['verified', false],
['cookie', false]
])->orWhere([
['token', $token],
['verified',false],
['cookie', $cookie]
])->first();

if ($this->session != null) {
$this->session->verified = true;
$this->session->save();
$this->setUser(User::find($this->session->user_id));
return $this->session;
}

return false;

}

/**
* Determine if the current user is a guest.
Expand All @@ -90,6 +134,16 @@ public function user()
return $this->user;
}

/**
* Get the current session.
*
* @return \acidjazz\Humble\Models\Session|null
*/
public function session()
{
return $this->session;
}

/**
* Get the ID for the currently authenticated user.
*
Expand Down
6 changes: 6 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

namespace acidjazz\Humble;

use acidjazz\Humble\Guards\HumbleGuard;
use Illuminate\Support\Facades\Auth;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function boot()
{
Auth::extend('humble', function ($app, $name, array $config) {
return new HumbleGuard(Auth::createUserProvider($config['provider']));
});
}
}

0 comments on commit 6b7b82e

Please sign in to comment.