summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-11 01:26:34 +0200
committermsquare <msquare@notrademark.de>2018-10-31 13:43:23 +0100
commit4e09ee3eb255160c88a378375d69123a3e000497 (patch)
treee4a03ff40c939473cc1278f8286675cfa31e4556 /src
parent7c6afc2bfe3263b91ecabf5530da57fe1162ea0b (diff)
Replaced more user related stuff
(Contains some buggy stuff too...)
Diffstat (limited to 'src')
-rw-r--r--src/Helpers/Authenticator.php51
-rw-r--r--src/Models/User/Contact.php6
-rw-r--r--src/Models/User/PasswordReset.php4
-rw-r--r--src/Models/User/Settings.php8
-rw-r--r--src/Models/User/State.php10
-rw-r--r--src/Models/User/User.php14
6 files changed, 65 insertions, 28 deletions
diff --git a/src/Helpers/Authenticator.php b/src/Helpers/Authenticator.php
index eee7b965..3061fbc1 100644
--- a/src/Helpers/Authenticator.php
+++ b/src/Helpers/Authenticator.php
@@ -2,33 +2,40 @@
namespace Engelsystem\Helpers;
-use Engelsystem\Models\BaseModel;
use Engelsystem\Models\User\User;
use Engelsystem\Models\User\User as UserRepository;
+use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\HttpFoundation\Session\Session;
class Authenticator
{
- /** @var UserRepository */
+ /** @var User */
protected $user = null;
+ /** @var ServerRequestInterface */
+ protected $request;
+
/** @var Session */
protected $session;
- /** @var BaseModel */
+ /** @var UserRepository */
protected $userRepository;
/**
- * @param Session $session
- * @param UserRepository $userRepository
+ * @param ServerRequestInterface $request
+ * @param Session $session
+ * @param UserRepository $userRepository
*/
- public function __construct(Session $session, UserRepository $userRepository)
+ public function __construct(ServerRequestInterface $request, Session $session, UserRepository $userRepository)
{
+ $this->request = $request;
$this->session = $session;
$this->userRepository = $userRepository;
}
/**
+ * Load the user from session
+ *
* @return User|null
*/
public function user()
@@ -51,6 +58,36 @@ class Authenticator
$this->user = $user;
- return $user;
+ return $this->user;
+ }
+
+ /**
+ * Get the user by his api key
+ *
+ * @param string $parameter
+ * @return User|null
+ */
+ public function apiUser($parameter = 'api_key')
+ {
+ if ($this->user) {
+ return $this->user;
+ }
+
+ $params = $this->request->getQueryParams();
+ if (!isset($params[$parameter])) {
+ return null;
+ }
+
+ $user = $this
+ ->userRepository
+ ->whereApiKey($params[$parameter])
+ ->first();
+ if (!$user) {
+ return $this->user();
+ }
+
+ $this->user = $user;
+
+ return $this->user;
}
}
diff --git a/src/Models/User/Contact.php b/src/Models/User/Contact.php
index 8adf9df7..23bc528c 100644
--- a/src/Models/User/Contact.php
+++ b/src/Models/User/Contact.php
@@ -7,9 +7,9 @@ namespace Engelsystem\Models\User;
* @property string $email
* @property string $mobile
*
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Contact whereDect($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Contact whereEmail($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Contact whereMobile($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Contact[] whereDect($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Contact[] whereEmail($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Contact[] whereMobile($value)
*/
class Contact extends HasUserModel
{
diff --git a/src/Models/User/PasswordReset.php b/src/Models/User/PasswordReset.php
index b65258c5..cd722aba 100644
--- a/src/Models/User/PasswordReset.php
+++ b/src/Models/User/PasswordReset.php
@@ -6,8 +6,8 @@ namespace Engelsystem\Models\User;
* @property string $token
* @property \Carbon\Carbon $created_at
*
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PasswordReset whereToken($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PasswordReset whereCreatedAt($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PasswordReset[] whereToken($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PasswordReset[] whereCreatedAt($value)
*/
class PasswordReset extends HasUserModel
{
diff --git a/src/Models/User/Settings.php b/src/Models/User/Settings.php
index 8f86e123..d062f902 100644
--- a/src/Models/User/Settings.php
+++ b/src/Models/User/Settings.php
@@ -8,10 +8,10 @@ namespace Engelsystem\Models\User;
* @property bool $email_human
* @property bool $email_shiftinfo
*
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Settings whereLanguage($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Settings whereTheme($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Settings whereEmailHuman($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Settings whereEmailShiftinfo($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Settings[] whereLanguage($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Settings[] whereTheme($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Settings[] whereEmailHuman($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\Settings[] whereEmailShiftinfo($value)
*/
class Settings extends HasUserModel
{
diff --git a/src/Models/User/State.php b/src/Models/User/State.php
index 6a1876ed..5651736d 100644
--- a/src/Models/User/State.php
+++ b/src/Models/User/State.php
@@ -9,11 +9,11 @@ namespace Engelsystem\Models\User;
* @property bool $got_shirt
* @property int $got_voucher
*
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State whereArrived($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State whereActive($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State whereForceActive($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State whereGotShirt($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State whereGotVoucher($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereArrived($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereActive($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereForceActive($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereGotShirt($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereGotVoucher($value)
*/
class State extends HasUserModel
{
diff --git a/src/Models/User/User.php b/src/Models/User/User.php
index d2a5129d..bc4ad015 100644
--- a/src/Models/User/User.php
+++ b/src/Models/User/User.php
@@ -21,13 +21,13 @@ use Illuminate\Database\Eloquent\Relations\HasOne;
* @property-read \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State $state
*
* @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User whereId($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User whereName($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User whereEmail($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User wherePassword($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User whereApiKey($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User whereLastLoginAt($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User whereCreatedAt($value)
- * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User whereUpdatedAt($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereName($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereEmail($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] wherePassword($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereApiKey($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereLastLoginAt($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereCreatedAt($value)
+ * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereUpdatedAt($value)
*/
class User extends BaseModel
{