Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
Doorcode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Guardians of the Kretschmar Elock System
Doorcode
Commits
b67776c7
Commit
b67776c7
authored
Mar 08, 2020
by
Jacob Priddy
👌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
big boy refactors
parent
e9f4ccb6
Changes
48
Hide whitespace changes
Inline
Side-by-side
Showing
48 changed files
with
397 additions
and
303 deletions
+397
-303
src/web/backend/app/Http/Controllers/UsersController.php
src/web/backend/app/Http/Controllers/UsersController.php
+10
-2
src/web/backend/database/seeds/UsersSeeder.php
src/web/backend/database/seeds/UsersSeeder.php
+1
-1
src/web/backend/src/Entities/Doorcode.php
src/web/backend/src/Entities/Doorcode.php
+57
-0
src/web/backend/src/Entities/Password.php
src/web/backend/src/Entities/Password.php
+60
-0
src/web/backend/src/Entities/User.php
src/web/backend/src/Entities/User.php
+48
-27
src/web/backend/src/Gateways/Users/DatabaseUsersRepository.php
...eb/backend/src/Gateways/Users/DatabaseUsersRepository.php
+10
-53
src/web/backend/src/Gateways/Users/InMemoryUsersRepository.php
...eb/backend/src/Gateways/Users/InMemoryUsersRepository.php
+2
-15
src/web/backend/src/Gateways/Users/LocalUsersRepository.php
src/web/backend/src/Gateways/Users/LocalUsersRepository.php
+5
-5
src/web/backend/src/Gateways/Users/UsersRepository.php
src/web/backend/src/Gateways/Users/UsersRepository.php
+3
-11
src/web/backend/src/UseCases/Users/Authenticate/Authenticate.php
.../backend/src/UseCases/Users/Authenticate/Authenticate.php
+5
-3
src/web/backend/src/UseCases/Users/CreateUser/CreateUser.php
src/web/backend/src/UseCases/Users/CreateUser/CreateUser.php
+6
-4
src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCase.php
...ckend/src/UseCases/Users/CreateUser/CreateUserUseCase.php
+1
-0
src/web/backend/src/UseCases/Users/UpdateUser/UpdateUser.php
src/web/backend/src/UseCases/Users/UpdateUser/UpdateUser.php
+8
-5
src/web/backend/src/UseCases/Users/UpdateUser/UpdateUserUseCase.php
...ckend/src/UseCases/Users/UpdateUser/UpdateUserUseCase.php
+1
-0
src/web/backend/tests/Database/GroupUserDatabaseTest.php
src/web/backend/tests/Database/GroupUserDatabaseTest.php
+1
-1
src/web/backend/tests/Database/TokenDatabaseTest.php
src/web/backend/tests/Database/TokenDatabaseTest.php
+1
-1
src/web/backend/tests/Database/UserDatabaseTest.php
src/web/backend/tests/Database/UserDatabaseTest.php
+41
-37
src/web/backend/tests/Doubles/InMemoryUsersRepositoryStub.php
...web/backend/tests/Doubles/InMemoryUsersRepositoryStub.php
+2
-9
src/web/backend/tests/Feature/Api/Auth/AuthControllerTest.php
...web/backend/tests/Feature/Api/Auth/AuthControllerTest.php
+2
-2
src/web/backend/tests/Feature/Api/Groups/GetUsersForGroupApiTest.php
...kend/tests/Feature/Api/Groups/GetUsersForGroupApiTest.php
+1
-1
src/web/backend/tests/Feature/Api/Users/AddUserToGroupApiTest.php
...backend/tests/Feature/Api/Users/AddUserToGroupApiTest.php
+1
-1
src/web/backend/tests/Feature/Api/Users/CreateUserApiTest.php
...web/backend/tests/Feature/Api/Users/CreateUserApiTest.php
+19
-9
src/web/backend/tests/Feature/Api/Users/DeleteUserApiTest.php
...web/backend/tests/Feature/Api/Users/DeleteUserApiTest.php
+1
-1
src/web/backend/tests/Feature/Api/Users/GetAllUsersApiTest.php
...eb/backend/tests/Feature/Api/Users/GetAllUsersApiTest.php
+1
-1
src/web/backend/tests/Feature/Api/Users/GetGroupsForUserApiTest.php
...ckend/tests/Feature/Api/Users/GetGroupsForUserApiTest.php
+1
-1
src/web/backend/tests/Feature/Api/Users/GetUserApiTest.php
src/web/backend/tests/Feature/Api/Users/GetUserApiTest.php
+1
-1
src/web/backend/tests/Feature/Api/Users/RemoveUserFromGroupApiTest.php
...nd/tests/Feature/Api/Users/RemoveUserFromGroupApiTest.php
+1
-1
src/web/backend/tests/Feature/Api/Users/UpdateUserApiTest.php
...web/backend/tests/Feature/Api/Users/UpdateUserApiTest.php
+17
-7
src/web/backend/tests/Feature/AuthenticatesWithApplicationTestCase.php
...nd/tests/Feature/AuthenticatesWithApplicationTestCase.php
+1
-1
src/web/backend/tests/Unit/Guards/ApiGuardTest.php
src/web/backend/tests/Unit/Guards/ApiGuardTest.php
+2
-2
src/web/backend/tests/Unit/Source/Authorizer/AuthorizerTest.php
...b/backend/tests/Unit/Source/Authorizer/AuthorizerTest.php
+1
-4
src/web/backend/tests/Unit/Source/UseCases/GroupUser/AddUserToGroup/UseCaseTest.php
.../Source/UseCases/GroupUser/AddUserToGroup/UseCaseTest.php
+0
-6
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetGroupUsers/PresenterTest.php
...Source/UseCases/GroupUser/GetGroupUsers/PresenterTest.php
+1
-1
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetGroupUsers/UseCaseTest.php
...t/Source/UseCases/GroupUser/GetGroupUsers/UseCaseTest.php
+0
-3
src/web/backend/tests/Unit/Source/UseCases/GroupUser/GetUserGroups/UseCaseTest.php
...t/Source/UseCases/GroupUser/GetUserGroups/UseCaseTest.php
+0
-3
src/web/backend/tests/Unit/Source/UseCases/GroupUser/RemoveUserFromGroup/UseCaseTest.php
...ce/UseCases/GroupUser/RemoveUserFromGroup/UseCaseTest.php
+0
-6
src/web/backend/tests/Unit/Source/UseCases/Users/Authenticate/AttemptUseCaseTest.php
...Source/UseCases/Users/Authenticate/AttemptUseCaseTest.php
+10
-1
src/web/backend/tests/Unit/Source/UseCases/Users/Authenticate/PresenterTest.php
...Unit/Source/UseCases/Users/Authenticate/PresenterTest.php
+19
-36
src/web/backend/tests/Unit/Source/UseCases/Users/Authenticate/SamlUseCaseTest.php
...it/Source/UseCases/Users/Authenticate/SamlUseCaseTest.php
+1
-1
src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/PresenterTest.php
...s/Unit/Source/UseCases/Users/CreateUser/PresenterTest.php
+5
-3
src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/UseCaseTest.php
...sts/Unit/Source/UseCases/Users/CreateUser/UseCaseTest.php
+4
-3
src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/UseCaseTest.php
...sts/Unit/Source/UseCases/Users/DeleteUser/UseCaseTest.php
+4
-4
src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/PresenterTest.php
.../Unit/Source/UseCases/Users/GetAllUsers/PresenterTest.php
+5
-3
src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/UseCaseTest.php
...ts/Unit/Source/UseCases/Users/GetAllUsers/UseCaseTest.php
+2
-2
src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/PresenterTest.php
...ests/Unit/Source/UseCases/Users/GetUser/PresenterTest.php
+5
-3
src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/UseCaseTest.php
.../tests/Unit/Source/UseCases/Users/GetUser/UseCaseTest.php
+3
-3
src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/PresenterTest.php
...s/Unit/Source/UseCases/Users/UpdateUser/PresenterTest.php
+5
-3
src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/UseCaseTest.php
...sts/Unit/Source/UseCases/Users/UpdateUser/UseCaseTest.php
+22
-16
No files found.
src/web/backend/app/Http/Controllers/UsersController.php
View file @
b67776c7
...
...
@@ -85,7 +85,11 @@ class UsersController extends ApiController
$presenter
=
new
CreateUserAPIPresenter
();
$createUser
->
create
(
$this
->
request
->
all
(),
$presenter
);
$attributes
=
$this
->
request
->
all
();
$attributes
[
'salt'
]
=
config
(
'app.key'
);
$createUser
->
create
(
$attributes
,
$presenter
);
return
$this
->
respondWithData
(
$presenter
->
getViewModel
());
}
...
...
@@ -115,7 +119,11 @@ class UsersController extends ApiController
$presenter
=
new
UpdateUserAPIPresenter
();
$updateUser
->
update
(
$userId
,
$this
->
request
->
all
(),
$presenter
);
$attributes
=
$this
->
request
->
all
();
$attributes
[
'salt'
]
=
config
(
'app.key'
);
$updateUser
->
update
(
$userId
,
$attributes
,
$presenter
);
if
(
$presenter
->
hasError
())
{
return
$this
->
respondWithError
(
$presenter
->
getViewModel
()[
'message'
]);
...
...
src/web/backend/database/seeds/UsersSeeder.php
View file @
b67776c7
...
...
@@ -26,8 +26,8 @@ class UsersSeeder extends Seeder
'admin'
,
''
,
'Admin User'
,
null
,
'admin@admin.user'
,
null
,
'Default Admin Password'
,
null
));
...
...
src/web/backend/src/Entities/Doorcode.php
0 → 100644
View file @
b67776c7
<?php
namespace
Source\Entities
;
class
Doorcode
{
/**
* @var string
*/
protected
string
$hash
;
/**
* Construct from existing Doorcode hash
*
* @param string $hash
*/
public
function
__construct
(
string
$hash
)
{
$this
->
hash
=
$hash
;
}
/**
* @param string $salt
* @param string|null $plaintext
* @return static|null
*/
public
static
function
hash
(
string
$salt
,
?string
$plaintext
):
?self
{
if
(
!
$plaintext
)
{
return
null
;
}
// Two rounds of sha512 each salted
// As of PHP 7 the salt parameter to password_hash has been depreciated.
// As we need to be able to search for users by doorcode they either all need to have the same salt
// or no salt (I'd prefer a salt). This way the doorcode can be hashed and
// then easily searched for in the database without having to check against every user and rehash every
// time with the new salt. As such it is not as easy to use BCRYPT :(
// So I'll just shred it twice using sha512 with with (probably) the application key.
return
new
static
(
hash
(
'sha512'
,
hash
(
'sha512'
,
$plaintext
.
$salt
)
.
$salt
)
);
}
/**
* @return string
*/
public
function
getHash
():
string
{
return
$this
->
hash
;
}
}
src/web/backend/src/Entities/Password.php
0 → 100644
View file @
b67776c7
<?php
namespace
Source\Entities
;
class
Password
{
protected
const
HASH_ALGORITHM
=
PASSWORD_BCRYPT
;
/**
* @var string
*/
protected
string
$hash
;
/**
* Construct from existing password hash.
*
* @param string $hash
*/
public
function
__construct
(
string
$hash
)
{
$this
->
hash
=
$hash
;
}
/**
* @param string $plaintext
* @return static
*/
public
static
function
hash
(
?string
$plaintext
):
?self
{
if
(
!
$plaintext
)
{
return
null
;
}
$hashed
=
password_hash
(
$plaintext
,
self
::
HASH_ALGORITHM
);
return
new
static
(
$hashed
);
}
/**
* @param string|null $plaintext
* @return bool
*/
public
function
matches
(
?string
$plaintext
):
bool
{
// If either is null, they do not match
if
(
!
$plaintext
||
!
$this
->
hash
)
{
return
false
;
}
return
password_verify
(
$plaintext
,
$this
->
hash
);
}
/**
* @return string
*/
public
function
getHash
():
string
{
return
$this
->
hash
;
}
}
src/web/backend/src/Entities/User.php
View file @
b67776c7
...
...
@@ -38,14 +38,14 @@ class User
protected
string
$email
;
/**
* @var
string
|null
* @var
\Source\Entities\Password
|null
*/
protected
?
string
$password
;
protected
?
Password
$password
;
/**
* @var
string
|null
* @var
\Source\Entities\Doorcode
|null
*/
protected
?
string
$doorcode
;
protected
?
Doorcode
$doorcode
;
/**
* @var Carbon|null
...
...
@@ -63,27 +63,27 @@ class User
protected
?Carbon
$updatedAt
;
/**
* @param int $id
* @param string $firstName
* @param string $lastName
* @param string $displayName
* @param string
|null $emplid
* @param string
$email
* @param
string
|null $password
* @param
string
|null $doorcode
* @param Carbon|null $expiresAt
* @param Carbon|null $createdAt
* @param Carbon|null $updatedAt
* @param int
$id
* @param string
$firstName
* @param string
$lastName
* @param string
$displayName
* @param string
$email
* @param string
|null $emplid
* @param
\Source\Entities\Password
|null $password
* @param
\Source\Entities\Doorcode
|null $doorcode
* @param Carbon|null
$expiresAt
* @param Carbon|null
$createdAt
* @param Carbon|null
$updatedAt
*/
public
function
__construct
(
int
$id
,
string
$firstName
,
string
$lastName
,
string
$displayName
,
?string
$emplid
,
string
$email
,
?string
$password
,
?string
$doorcode
,
?string
$emplid
=
null
,
?Password
$password
=
null
,
?Doorcode
$doorcode
=
null
,
?Carbon
$expiresAt
=
null
,
?Carbon
$createdAt
=
null
,
?Carbon
$updatedAt
=
null
...
...
@@ -186,13 +186,18 @@ class User
$this
->
id
=
$id
;
}
/**
* @param string|null $email
* @param string|null $password
* @return bool
*/
public
function
matchCredentials
(
?string
$email
,
?string
$password
):
bool
{
if
(
!
$
password
||
!
$email
)
{
if
(
!
$
this
->
password
)
{
return
false
;
}
return
$this
->
getEmail
()
===
$email
&&
$this
->
getPassword
()
===
$password
;
return
$this
->
hasEmailOf
(
$email
)
&&
$this
->
password
->
matches
(
$password
)
;
}
/**
...
...
@@ -204,9 +209,9 @@ class User
}
/**
* @return
string
|null
* @return
\Source\Entities\Password
|null
*/
public
function
getPassword
():
?
string
public
function
getPassword
():
?
Password
{
return
$this
->
password
;
}
...
...
@@ -215,28 +220,40 @@ class User
* @param string $doorcode
* @return bool
*/
public
function
hasDoorcodeOf
(
?
string
$doorcode
):
bool
public
function
hasDoorcodeOf
(
?
Doorcode
$doorcode
):
bool
{
if
(
!
$doorcode
)
{
if
(
!
$doorcode
||
!
$this
->
getDoorcode
()
)
{
return
false
;
}
return
$this
->
getDoorcode
()
===
$doorcode
;
return
$this
->
getDoorcode
()
->
getHash
()
===
$doorcode
;
}
/**
* @return
string
|null
* @return
\Source\Entities\Doorcode
|null
*/
public
function
getDoorcode
():
?
string
public
function
getDoorcode
():
?
Doorcode
{
return
$this
->
doorcode
;
}
/**
* @param string|null $email
* @return bool
*/
public
function
hasEmailOf
(
?string
$email
):
bool
{
if
(
!
$email
)
{
return
false
;
}
return
$this
->
getEmail
()
===
strtolower
(
$email
);
}
/**
* @param string|null $name
* @return bool
*/
public
function
hasFirstNameOf
(
?string
$name
):
bool
{
if
(
!
$name
)
{
...
...
@@ -246,6 +263,10 @@ class User
return
$this
->
getFirstName
()
===
$name
;
}
/**
* @param \Source\Entities\User|null $user
* @return bool
*/
public
function
is
(
?User
$user
):
bool
{
if
(
!
$user
)
{
...
...
src/web/backend/src/Gateways/Users/DatabaseUsersRepository.php
View file @
b67776c7
...
...
@@ -4,6 +4,8 @@
namespace
Source\Gateways\Users
;
use
Source\Entities\User
;
use
Source\Entities\Doorcode
;
use
Source\Entities\Password
;
class
DatabaseUsersRepository
implements
UsersRepository
{
...
...
@@ -32,10 +34,10 @@ class DatabaseUsersRepository implements UsersRepository
$user
->
first_name
,
$user
->
last_name
,
$user
->
display_name
,
$user
->
emplid
,
$user
->
email
,
$user
->
password
,
$user
->
doorcode
,
$user
->
emplid
,
$user
->
password
===
null
?
null
:
new
Password
(
$user
->
password
),
$user
->
doorcode
===
null
?
null
:
new
Doorcode
(
$user
->
doorcode
),
$user
->
expires_at
,
$user
->
created_at
,
$user
->
updated_at
...
...
@@ -82,41 +84,12 @@ class DatabaseUsersRepository implements UsersRepository
$dbUser
->
emplid
=
$user
->
getEmplid
();
$dbUser
->
email
=
$user
->
getEmail
();
$dbUser
->
expires_at
=
$user
->
getExpiresAt
();
// If the password exists and is the same as provided, don't change
// Else regenerate
if
(
!
isset
(
$dbUser
->
password
)
||
(
isset
(
$dbUser
->
password
)
&&
$dbUser
->
password
!==
$user
->
getPassword
()))
{
$dbUser
->
password
=
bcrypt
(
$user
->
getPassword
());
}
// If the doorcode exists and is the same as provided, don't change
// Else regenerate
if
(
!
isset
(
$dbUser
->
doorcode
)
||
(
isset
(
$dbUser
->
doorcode
)
&&
$dbUser
->
doorcode
!==
$user
->
getDoorcode
()))
{
$dbUser
->
doorcode
=
self
::
secureDoorcode
(
$user
->
getDoorcode
());
}
$dbUser
->
password
=
$user
->
getPassword
()
===
null
?
null
:
$user
->
getPassword
()
->
getHash
();
$dbUser
->
doorcode
=
$user
->
getDoorcode
()
===
null
?
null
:
$user
->
getDoorcode
()
->
getHash
();
return
$dbUser
;
}
/**
* @param string|null $doorcode
* @return string|null
*/
public
static
function
secureDoorcode
(
?string
$doorcode
):
?string
{
if
(
!
$doorcode
)
{
return
null
;
}
// As of PHP 7 the salt parameter to password_hash has been depreciated.
// As we need to be able to search for users by doorcode they either all need to have the same salt
// (in this case, the app key) or no salt (I'd prefer a salt). This way the doorcode can be hashed and
// then easily searched for in the database without having to check against every user and rehash every
// time with the new salt. As such it is not as easy to use BCRYPT :(
// So I'll just shred it twice using sha512 with with the application key.
return
hash
(
'sha512'
,
hash
(
'sha512'
,
$doorcode
.
config
(
'app.key'
)));
}
/**
* @inheritDoc
*/
...
...
@@ -154,29 +127,13 @@ class DatabaseUsersRepository implements UsersRepository
/**
* @inheritDoc
*/
public
function
findBy
Credentials
(
string
$email
,
string
$password
):
?User
public
function
findBy
Doorcode
(
?Doorcode
$doorcode
):
?User
{
$user
=
\
App\User
::
where
(
'email'
,
$email
)
->
first
();
if
(
!
$user
)
{
return
null
;
}
if
(
!
password_verify
(
$password
,
$user
->
password
))
{
if
(
!
$doorcode
)
{
return
null
;
}
return
self
::
makeUserFromDbUser
(
$user
);
}
/**
* @inheritDoc
*/
public
function
findByDoorcode
(
string
$doorcode
):
?User
{
$doorcodeSearch
=
self
::
secureDoorcode
(
$doorcode
);
$user
=
\
App\User
::
where
(
'doorcode'
,
$doorcodeSearch
)
->
first
();
$user
=
\
App\User
::
where
(
'doorcode'
,
$doorcode
->
getHash
())
->
first
();
if
(
!
$user
)
{
return
null
;
...
...
src/web/backend/src/Gateways/Users/InMemoryUsersRepository.php
View file @
b67776c7
...
...
@@ -4,6 +4,7 @@
namespace
Source\Gateways\Users
;
use
Source\Entities\User
;
use
Source\Entities\Doorcode
;
class
InMemoryUsersRepository
implements
UsersRepository
{
...
...
@@ -97,21 +98,7 @@ class InMemoryUsersRepository implements UsersRepository
/**
* @inheritDoc
*/
public
function
findByCredentials
(
string
$email
,
string
$password
):
?User
{
foreach
(
$this
->
users
as
$user
)
{
if
(
$user
->
matchCredentials
(
$email
,
$password
))
{
return
$user
;
}
}
return
null
;
}
/**
* @inheritDoc
*/
public
function
findByDoorcode
(
string
$doorcode
):
?User
public
function
findByDoorcode
(
?Doorcode
$doorcode
):
?User
{
foreach
(
$this
->
users
as
$user
)
{
if
(
$user
->
hasDoorcodeOf
(
$doorcode
))
{
...
...
src/web/backend/src/Gateways/Users/LocalUsersRepository.php
View file @
b67776c7
...
...
@@ -32,8 +32,8 @@ class LocalUsersRepository extends InMemoryUsersRepository
'Sheev'
,
'Palpatine'
,
'The Emperor'
,
'execute order 66'
,
'sithL0rd@senate.com'
,
'execute order 66'
,
'I am the senate'
,
'123456'
,
Carbon
::
now
()
->
addDays
(
3
),
...
...
@@ -53,13 +53,13 @@ class LocalUsersRepository extends InMemoryUsersRepository
'Kobe'
,
'Bryant'
,
'Cobain Bryant'
,
'299012'
,
'he ded'
,
'299012'
,
'kobe didn\' miss his last shot'
,
'12453'
,
new
Carbon
(
'2020-01-26 09:06:00'
),
null
,
null
,
null
);
}
...
...
@@ -74,8 +74,8 @@ class LocalUsersRepository extends InMemoryUsersRepository
'Jacob'
,
'Priddy'
,
'JD Priddy'
,
'201565'
,
'email idk'
,
'201565'
,
'not gonna be plaintext just placeholder here'
,
'123866'
,
null
,
...
...
@@ -95,8 +95,8 @@ class LocalUsersRepository extends InMemoryUsersRepository
'Jarod'
,
'Owen'
,
'JJ Obob'
,
'177013'
,
'jarod.owen@wallawalla.edu'
,
'177013'
,
'not rlly plaintext password'
,
'42069'
,
null
,
...
...
src/web/backend/src/Gateways/Users/UsersRepository.php
View file @
b67776c7
...
...
@@ -4,6 +4,7 @@
namespace
Source\Gateways\Users
;
use
Source\Entities\User
;
use
Source\Entities\Doorcode
;
interface
UsersRepository
{
...
...
@@ -43,22 +44,13 @@ interface UsersRepository
*/
public
function
exists
(
string
$userId
):
bool
;
/**
* Find a user by username and password
*
* @param string $email
* @param string $password
* @return User|null
*/
public
function
findByCredentials
(
string
$email
,
string
$password
):
?User
;
/**
* Find a user by doorcode
*
* @param
string
$doorcode
* @param
\Source\Entities\Doorcode|null
$doorcode
* @return User|null
*/
public
function
findByDoorcode
(
string
$doorcode
):
?User
;
public
function
findByDoorcode
(
?Doorcode
$doorcode
):
?User
;
/**
* Find a user by email
...
...
src/web/backend/src/UseCases/Users/Authenticate/Authenticate.php
View file @
b67776c7
...
...
@@ -52,9 +52,11 @@ class Authenticate implements AuthenticateUseCase
throw
new
AuthenticationException
();
}
$user
=
$this
->
users
->
findBy
Credentials
(
strtolower
(
$email
),
$password
);
$user
=
$this
->
users
->
findBy
Email
(
strtolower
(
$email
)
);
if
(
!
$user
)
{
if
(
!
$user
||
!
$user
->
getPassword
()
||
!
$user
->
getPassword
()
->
matches
(
$password
))
{
throw
new
AuthenticationException
();
}
...
...
@@ -103,8 +105,8 @@ class Authenticate implements AuthenticateUseCase
$samlUser
->
getFirstName
(),
$samlUser
->
getLastName
(),
$samlUser
->
getDisplayName
(),
$samlUser
->
getEmplid
(),
$samlUser
->
getEmail
(),
$samlUser
->
getEmplid
(),
null
,
null
)
...
...
src/web/backend/src/UseCases/Users/CreateUser/CreateUser.php
View file @
b67776c7
...
...
@@ -5,6 +5,8 @@ namespace Source\UseCases\Users\CreateUser;
use
Exception
;
use
Carbon\Carbon
;
use
Source\Entities\User
;
use
Source\Entities\Doorcode
;
use
Source\Entities\Password
;
use
Source\Gateways\Users\UsersRepository
;
use
Source\Exceptions\EntityExistsException
;
...
...
@@ -40,13 +42,13 @@ class CreateUser implements CreateUserUseCase
$attributes
[
'first_name'
],
$attributes
[
'last_name'
],
$attributes
[
'display_name'
],
$emplid
,
$attributes
[
'email'
],
$password
,
$attributes
[
'doorcode'
],
$emplid
,
Password
::
hash
(
$password
),
Doorcode
::
hash
(
$attributes
[
'salt'
],
$attributes
[
'doorcode'
]),
$expires
,
null
,
null
,
null
);
...
...
src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCase.php
View file @
b67776c7
...
...
@@ -15,6 +15,7 @@ interface CreateUserUseCase
* email
* password
* doorcode
* salt (The salt to hash the doorcode with)
* Optional attributes
* emplid
* expires_at
...
...
src/web/backend/src/UseCases/Users/UpdateUser/UpdateUser.php
View file @
b67776c7
...
...
@@ -5,6 +5,8 @@ namespace Source\UseCases\Users\UpdateUser;
use
Exception
;
use
Carbon\Carbon
;
use
Source\Entities\User
;
use
Source\Entities\Doorcode
;
use
Source\Entities\Password
;
use
Source\Authorization\Authorizer
;
use
Source\Gateways\Users\UsersRepository
;
use
Source\Exceptions\EntityNotFoundException
;
...
...
@@ -22,7 +24,8 @@ class UpdateUser implements UpdateUserUseCase
protected
Authorizer
$authorizer
;
/**
* @param UsersRepository $usersRepository
* @param \Source\Authorization\Authorizer $authorizer
* @param \Source\Gateways\Users\UsersRepository $usersRepository
*/
public
function
__construct
(
Authorizer
$authorizer
,
UsersRepository
$usersRepository
)
{
...
...
@@ -54,13 +57,13 @@ class UpdateUser implements UpdateUserUseCase
$attributes
[
'first_name'
],
$attributes
[
'last_name'
],