Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Decoupling improvements #5

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
526c352
Larval 5.1 Branch
Dec 2, 2016
54c1424
replace resource_path
Dec 2, 2016
ec88389
added Html package v5.1
Dec 4, 2016
6b73d63
Blade updates
Dec 4, 2016
6b90705
Merge branch 'master' into lvl51
tiagoalves Dec 14, 2016
99af026
Fixed some Laravel 5.1 compatibilities, made the modle less opinionated.
tiagoalves Dec 14, 2016
5893f2d
Decoupled the `user` object view/presentation.
tiagoalves Dec 15, 2016
c969c65
Added possibility to configure module through env vars.
tiagoalves Dec 15, 2016
99b2d7f
Showing the correct error message on authentication errors
tiagoalves Dec 20, 2016
a6bec94
Added a custom package-level exception handler
tiagoalves Dec 21, 2016
8a29ce0
Using the custom exception handler only for the view-related endpoints.
tiagoalves Dec 21, 2016
5ef6951
Several improvements including decoupling from internal transport req…
tiagoalves Dec 21, 2016
142b89b
Merge branch 'lvl51' into feature/decoupling-improvements
tiagoalves Dec 21, 2016
0ce11b7
Fixed login issue related to the decoupling.
tiagoalves Dec 21, 2016
e0f7291
Added info to README about the Laravel 5.1 maintenance branch and tags.
tiagoalves Jan 10, 2017
147442c
Merge branch 'lvl51' into feature/decoupling-improvements
tiagoalves Jan 10, 2017
344e2dd
Improved README again for the laravel 5.1 maintenance branch.
tiagoalves Jan 10, 2017
13fb0a4
Merge branch 'lvl51' into feature/decoupling-improvements
tiagoalves Jan 10, 2017
2cb1dcf
Providing a more explicit error message for `InvalidParameterExceptio…
tiagoalves Jan 30, 2017
0514a5b
Merge branch 'lvl51' into feature/decoupling-improvements
tiagoalves Jan 30, 2017
6f22481
Reverted a Laravel 5.1 compatibility change.
tiagoalves Mar 20, 2017
764b9e9
Merge branch 'master' into feature/decoupling-improvements
tiagoalves Mar 20, 2017
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
Prev Previous commit
Next Next commit
Fixed login issue related to the decoupling.
Now the module uses its own User trait as well.
tiagoalves committed Dec 21, 2016
commit 0ce11b78d4ac0c40ea2f5e1595b0216d5078aeee
21 changes: 6 additions & 15 deletions src/Cloudoki/OaStack/Controllers/OAuth2Controller.php
Original file line number Diff line number Diff line change
@@ -50,24 +50,15 @@ public static function login ($payload)
throw new \Cloudoki\InvalidParameterException ('Invalid e-mail.');
}

$userModelClass = config ('oastack.user_model', null);
$userModelClass = config ('oastack.user_model', User::class);

if ($userModelClass != null) {
// We have to use the base app's user model and authentication strategy
$userModel = app()->make($userModelClass);
// We have to use the base app's user model and authentication strategy
$userModel = app()->make($userModelClass);

$user = call_user_func(array($userModel, 'findByLoginId'), $payload->email);
$user = call_user_func(array($userModel, 'findByLoginId'), $payload->email);

if (!isset($user) || !$user->checkPassword ($payload->password)) {
throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.');
}
} else {
// We're allowed to use our own `user` model and authentication strategy
$user = User::email ($payload->email)->first ();

if (!isset($user) || !$user->checkPassword ($payload->password)) {
throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.');
}
if (!isset($user) || !$user->checkPassword ($payload->password)) {
throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.');
}

# Validate Authorization
58 changes: 10 additions & 48 deletions src/Cloudoki/OaStack/Models/User.php
Original file line number Diff line number Diff line change
@@ -5,14 +5,17 @@
use Cloudoki\OaStack\Models\Oauth2Authorization;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Hash;
use Cloudoki\OaStack\Traits\User as UserTrait;

/**
* User Model
* Add the namespace if you want to extend your custom User model with this one.
*/
class User extends BaseModel
{
use SoftDeletes;

use UserTrait;

/**
* The model type.
*
@@ -40,36 +43,6 @@ public function accounts ()
return $this->belongsToMany ('Cloudoki\OaStack\Models\Account')->withPivot ('invitation_token');
}

/**
* Acces Token relationship
*
* @return hasMany
*/
public function oauth2accesstokens ()
{
return $this->hasMany('Cloudoki\OaStack\Models\Oauth2AccessToken');
}

/**
* Authorisations relationship
*
* @return hasMany
*/
public function oauth2authorizations ()
{
return $this->hasMany('Cloudoki\OaStack\Models\Oauth2Authorization');
}

/**
* Clients relationship
*
* @return hasMany
*/
public function oauth2clients ()
{
return $this->hasMany('Cloudoki\OaStack\Models\Oauth2Client');
}

/**
* Get Accounts
* All accounts related to the user.
@@ -127,7 +100,7 @@ public function getFirstName ()
public function setFirstName ($firstname)
{
$this->firstname = $firstname;

return $this;
}

@@ -149,10 +122,10 @@ public function getLastName ()
public function setLastName ($name)
{
$this->lastname = $name;

return $this;
}

/**
* Get user name
*
@@ -181,7 +154,7 @@ public function getEmail ()
public function setEmail ($email)
{
$this->email = $email;

return $this;
}

@@ -194,19 +167,8 @@ public function setEmail ($email)
public function setPassword($value)
{
$this->password = Hash::make ($value);

return $this;
}

/**
* Check password
*
* @param string $value
* @return bool
*/
public function checkPassword ($value)
{
return Hash::check ($value, $this->password);
return $this;
}

/**
@@ -243,7 +205,7 @@ public function makeToken ()

return md5 (uniqid ( $rand[rand (0, 9)] . ' ' . $rand[rand (0, 9)], true));
}

/**
* Set Reset Token
*