Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Guardians of the Kretschmar Elock System
Doorcode
Commits
7fc7ac8a
Commit
7fc7ac8a
authored
Dec 28, 2020
by
Jacob Priddy
👌
Browse files
flash users' doorcode to them when they update it
parent
9725d71b
Pipeline
#13236
failed with stages
in 1 minute and 15 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/backend/app/Http/Controllers/Web/MeController.php
View file @
7fc7ac8a
...
...
@@ -13,6 +13,7 @@ use Source\UseCases\Doors\GetDoors\GetDoorsUseCase;
use
Source\UseCases\Tokens\GetTokens\GetTokensUseCase
;
use
Source\UseCases\Users\UpdateUser\UpdateCurrentUser
;
use
Source\UseCases\Requests\GetRequest\GetRequestUseCase
;
use
Source\UseCases\Users\UpdateUser\DoorcodeWebPresenter
;
use
Source\UseCases\Requests\GetRequests\GetRequestsUseCase
;
use
Source\UseCases\Requests\CreateRequest\CreateRequestUseCase
;
use
Source\UseCases\Requests\DeleteRequest\DeleteRequestUseCase
;
...
...
@@ -21,6 +22,7 @@ use Source\UseCases\Requests\InteractWithRequest\InteractWithRequestUseCase;
use
Source\UseCases\Users\UpdateUser\WebPresenter
as
UpdateUserWebPresenter
;
use
Source\UseCases\Requests\GetRequests\WebPresenter
as
RequestsWebPresenter
;
use
Source\UseCases\Requests\DeleteRequest\WebPresenter
as
DeleteRequestWebPresenter
;
use
Source\UseCases\Users\UpdateUser\DoorcodeWebPresenter
as
UpdateUserDoorcodeWebPresenter
;
class
MeController
extends
Controller
{
...
...
@@ -38,7 +40,7 @@ class MeController extends Controller
'doorcode'
=>
'required|string|numeric|digits_between:4,248'
,
]);
$presenter
=
new
UpdateUser
WebPresenter
();
$presenter
=
new
Doorcode
WebPresenter
();
$userUpdate
->
update
(
$this
->
authorizer
->
getCurrentUserId
(),
...
...
src/backend/resources/views/doorcode.blade.php
View file @
7fc7ac8a
...
...
@@ -4,6 +4,9 @@
@
section
(
'content'
)
<
div
>
@
include
(
'partials.form-errors'
)
@
include
(
'partials.message'
)
<
p
>
Your
student
ID
will
automatically
be
prepended
to
the
code
you
set
on
this
page
.
For
example
,
if
your
student
ID
is
<
kbd
>
311546
</
kbd
>
,
and
you
...
...
@@ -15,9 +18,6 @@
If
you
do
not
have
a
student
ID
,
the
doorcode
entered
here
is
your
full
doorcode
.
</
small
>
@
include
(
'partials.form-errors'
)
@
include
(
'partials.message'
)
<
form
action
=
"{{ route('web.doorcode.change') }}"
method
=
"POST"
>
@
csrf
<
div
class
=
"form-group"
>
...
...
src/backend/src/UseCases/Users/UpdateUser/DoorcodeWebPresenter.php
0 → 100644
View file @
7fc7ac8a
<?php
namespace
Source\UseCases\Users\UpdateUser
;
use
Source\UseCases\BasePresenter
;
class
DoorcodeWebPresenter
extends
BasePresenter
implements
Presenter
{
protected
array
$viewModel
=
[];
/** @inheritDoc */
public
function
present
(
ResponseModel
$responseModel
):
void
{
$this
->
viewModel
[
'error'
]
=
$responseModel
->
hasError
();
$this
->
viewModel
[
'message'
]
=
$responseModel
->
getError
()
?:
'Successfully changed doorcode to '
.
$responseModel
->
getDoorcode
();
}
/** @inheritDoc */
public
function
getViewModel
():
array
{
return
$this
->
viewModel
;
}
}
src/backend/src/UseCases/Users/UpdateUser/ResponseModel.php
View file @
7fc7ac8a
...
...
@@ -14,6 +14,11 @@ class ResponseModel
*/
protected
?User
$user
=
null
;
/**
* @var string|null Users new doorcode
*/
protected
?string
$doorcode
=
null
;
/**
* @return User
*/
...
...
@@ -29,4 +34,20 @@ class ResponseModel
{
$this
->
user
=
$user
;
}
/**
* @param string $doorcode
*/
public
function
setDoorcode
(
string
$doorcode
):
void
{
$this
->
doorcode
=
$doorcode
;
}
/**
* @return string|null
*/
public
function
getDoorcode
():
?string
{
return
$this
->
doorcode
;
}
}
src/backend/src/UseCases/Users/UpdateUser/UpdateCurrentUser.php
View file @
7fc7ac8a
...
...
@@ -56,11 +56,11 @@ class UpdateCurrentUser implements UpdateUserUseCase
$doorcode
=
$attributes
[
'doorcode'
]
??
null
;
if
(
$doorcode
)
{
if
(
$user
->
getEmplid
())
{
$doorcode
=
$user
->
getEmplid
()
.
$doorcode
;
$doorcode
=
ltrim
(
$user
->
getEmplid
()
,
'0'
)
.
$doorcode
;
}
elseif
(
strlen
(
$doorcode
)
<
self
::
MIN_USER_SET_DOORCODE_LEN
)
{
$response
->
setError
(
'Doorcode must be at least '
.
self
::
MIN_USER_SET_DOORCODE_LEN
.
' digits long
s
inc
e you do not have an emplid
'
);
' digits long inc
luding the length of your student ID (leading 0\'s are stripped from your ID).
'
);
$presenter
->
present
(
$response
);
...
...
@@ -86,7 +86,7 @@ class UpdateCurrentUser implements UpdateUserUseCase
try
{
$returnedUser
=
$this
->
users
->
update
(
$user
->
getId
(),
$newUser
);
}
catch
(
EntityExistsException
$e
)
{
}
catch
(
EntityExistsException
)
{
//
}
...
...
@@ -94,6 +94,9 @@ class UpdateCurrentUser implements UpdateUserUseCase
$response
->
setError
(
'Unable to update user.'
);
}
else
{
$response
->
setUser
(
$returnedUser
);
if
(
$doorcode
)
{
$response
->
setDoorcode
(
$doorcode
);
}
}
$presenter
->
present
(
$response
);
...
...
src/backend/tests/Unit/Source/UseCases/Users/UpdateUser/CurrentUserUpdateUseCaseTest.php
View file @
7fc7ac8a
...
...
@@ -174,7 +174,7 @@ class CurrentUserUpdateUseCaseTest extends TestCase
self
::
assertTrue
(
$this
->
response
->
hasError
());
self
::
assertEquals
(
'Doorcode must be at least 11 digits long
s
inc
e you do not have an emplid
'
,
'Doorcode must be at least 11 digits long inc
luding the length of your student ID (leading 0\'s are stripped from your ID).
'
,
$this
->
response
->
getError
()
);
}
...
...
@@ -194,4 +194,20 @@ class CurrentUserUpdateUseCaseTest extends TestCase
self
::
assertFalse
(
$this
->
response
->
hasError
());
self
::
assertEquals
(
HashedSearchable
::
hash
(
''
,
'emplid1234'
),
$this
->
usersRepository
->
get
(
'69'
)
->
getDoorcode
());
}
/**
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityExistsException
*/
public
function
it_prepends_emplid_to_doorcode_without_leading_zeros
():
void
{
$user
=
new
User
(
69
,
''
,
''
,
''
,
''
,
'0000234'
);
$this
->
usersRepository
->
create
(
$user
);
$this
->
handleTest
(
'69'
,
[
'doorcode'
=>
'01234'
]);
self
::
assertFalse
(
$this
->
response
->
hasError
());
self
::
assertEquals
(
HashedSearchable
::
hash
(
''
,
'23401234'
),
$this
->
usersRepository
->
get
(
'69'
)
->
getDoorcode
());
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment