Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchParapheur
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchParapheur
Commits
ba1a174e
Verified
Commit
ba1a174e
authored
3 years ago
by
Florian Azizian
Browse files
Options
Downloads
Patches
Plain Diff
FEAT #16831 TIME 1:45 Can set/get x509Fingerprint in users API + doc
parent
51577494
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/user/controllers/UserController.php
+25
-2
25 additions, 2 deletions
src/app/user/controllers/UserController.php
src/app/user/models/UserModel.php
+3
-2
3 additions, 2 deletions
src/app/user/models/UserModel.php
with
28 additions
and
4 deletions
src/app/user/controllers/UserController.php
+
25
−
2
View file @
ba1a174e
...
@@ -46,7 +46,7 @@ class UserController
...
@@ -46,7 +46,7 @@ class UserController
{
{
$queryParams
=
$request
->
getQueryParams
();
$queryParams
=
$request
->
getQueryParams
();
$select
=
[
'id'
,
'firstname'
,
'lastname'
,
'substitute'
];
$select
=
[
'id'
,
'firstname'
,
'lastname'
,
'substitute'
,
'x509_fingerprint'
];
$where
=
[];
$where
=
[];
$queryData
=
[];
$queryData
=
[];
if
(
empty
(
$queryParams
[
'mode'
]))
{
if
(
empty
(
$queryParams
[
'mode'
]))
{
...
@@ -65,8 +65,14 @@ class UserController
...
@@ -65,8 +65,14 @@ class UserController
'orderBy'
=>
[
'lastname'
,
'firstname'
]
'orderBy'
=>
[
'lastname'
,
'firstname'
]
]);
]);
$currentUser
=
UserModel
::
getById
([
'select'
=>
[
'"isRest"'
],
'id'
=>
$GLOBALS
[
'id'
]]);
foreach
(
$users
as
$key
=>
$user
)
{
foreach
(
$users
as
$key
=>
$user
)
{
$users
[
$key
][
'substitute'
]
=
!
empty
(
$user
[
'substitute'
]);
$users
[
$key
][
'substitute'
]
=
!
empty
(
$user
[
'substitute'
]);
if
(
$currentUser
[
'isRest'
])
{
$users
[
$key
][
'x509Fingerprint'
]
=
$users
[
$key
][
'x509_fingerprint'
];
}
unset
(
$users
[
$key
][
'x509_fingerprint'
]);
}
}
return
$response
->
withJson
([
'users'
=>
$users
]);
return
$response
->
withJson
([
'users'
=>
$users
]);
...
@@ -125,6 +131,8 @@ class UserController
...
@@ -125,6 +131,8 @@ class UserController
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body lastname is empty or not a string'
]);
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body lastname is empty or not a string'
]);
}
elseif
(
empty
(
$body
[
'email'
])
||
!
filter_var
(
$body
[
'email'
],
FILTER_VALIDATE_EMAIL
)
||
!
Validator
::
stringType
()
->
notEmpty
()
->
length
(
1
,
128
)
->
validate
(
$body
[
'email'
]))
{
}
elseif
(
empty
(
$body
[
'email'
])
||
!
filter_var
(
$body
[
'email'
],
FILTER_VALIDATE_EMAIL
)
||
!
Validator
::
stringType
()
->
notEmpty
()
->
length
(
1
,
128
)
->
validate
(
$body
[
'email'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body email is empty or not a valid email'
]);
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body email is empty or not a valid email'
]);
}
elseif
(
!
empty
(
$body
[
'x509Fingerprint'
])
&&
!
Validator
::
stringType
()
->
validate
(
$body
[
'x509Fingerprint'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body x509Fingerprint is not a string'
]);
}
}
$body
[
'login'
]
=
strtolower
(
$body
[
'login'
]);
$body
[
'login'
]
=
strtolower
(
$body
[
'login'
]);
...
@@ -132,6 +140,8 @@ class UserController
...
@@ -132,6 +140,8 @@ class UserController
if
(
!
empty
(
$existingUser
))
{
if
(
!
empty
(
$existingUser
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Login already exists'
,
'lang'
=>
'userLoginAlreadyExists'
]);
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Login already exists'
,
'lang'
=>
'userLoginAlreadyExists'
]);
}
}
$body
[
'x509_fingerprint'
]
=
$body
[
'x509Fingerprint'
];
if
(
!
empty
(
$body
[
'isRest'
]))
{
if
(
!
empty
(
$body
[
'isRest'
]))
{
$body
[
'"isRest"'
]
=
true
;
$body
[
'"isRest"'
]
=
true
;
...
@@ -191,6 +201,8 @@ class UserController
...
@@ -191,6 +201,8 @@ class UserController
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body lastname is empty or not a string'
]);
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body lastname is empty or not a string'
]);
}
elseif
(
empty
(
$body
[
'email'
])
||
!
filter_var
(
$body
[
'email'
],
FILTER_VALIDATE_EMAIL
)
||
!
Validator
::
stringType
()
->
notEmpty
()
->
length
(
1
,
128
)
->
validate
(
$body
[
'email'
]))
{
}
elseif
(
empty
(
$body
[
'email'
])
||
!
filter_var
(
$body
[
'email'
],
FILTER_VALIDATE_EMAIL
)
||
!
Validator
::
stringType
()
->
notEmpty
()
->
length
(
1
,
128
)
->
validate
(
$body
[
'email'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body email is empty or not a valid email'
]);
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body email is empty or not a valid email'
]);
}
elseif
(
!
empty
(
$body
[
'x509Fingerprint'
])
&&
!
Validator
::
stringType
()
->
validate
(
$body
[
'x509Fingerprint'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body x509Fingerprint is not a string'
]);
}
}
$user
=
UserModel
::
getById
([
'id'
=>
$args
[
'id'
],
'select'
=>
[
1
]]);
$user
=
UserModel
::
getById
([
'id'
=>
$args
[
'id'
],
'select'
=>
[
1
]]);
...
@@ -205,6 +217,11 @@ class UserController
...
@@ -205,6 +217,11 @@ class UserController
'signature_modes'
=>
[]
'signature_modes'
=>
[]
];
];
$currentUser
=
UserModel
::
getById
([
'select'
=>
[
'"isRest"'
],
'id'
=>
$GLOBALS
[
'id'
]]);
if
(
$currentUser
[
'isRest'
])
{
$set
[
'x509_fingerprint'
]
=
$body
[
'x509Fingerprint'
];
}
if
(
!
empty
(
$body
[
'signatureModes'
]))
{
if
(
!
empty
(
$body
[
'signatureModes'
]))
{
if
(
!
Validator
::
arrayType
()
->
validate
(
$body
[
'signatureModes'
]))
{
if
(
!
Validator
::
arrayType
()
->
validate
(
$body
[
'signatureModes'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body signatureModes is not an array'
]);
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body signatureModes is not an array'
]);
...
@@ -710,7 +727,7 @@ class UserController
...
@@ -710,7 +727,7 @@ class UserController
ValidatorModel
::
notEmpty
(
$args
,
[
'id'
]);
ValidatorModel
::
notEmpty
(
$args
,
[
'id'
]);
ValidatorModel
::
intVal
(
$args
,
[
'id'
]);
ValidatorModel
::
intVal
(
$args
,
[
'id'
]);
$user
=
UserModel
::
getById
([
'select'
=>
[
'id'
,
'login'
,
'email'
,
'firstname'
,
'lastname'
,
'picture'
,
'preferences'
,
'substitute'
,
'"isRest"'
,
'signature_modes'
],
'id'
=>
$args
[
'id'
]]);
$user
=
UserModel
::
getById
([
'select'
=>
[
'id'
,
'login'
,
'email'
,
'firstname'
,
'lastname'
,
'picture'
,
'preferences'
,
'substitute'
,
'"isRest"'
,
'signature_modes'
,
'x509_fingerprint'
],
'id'
=>
$args
[
'id'
]]);
if
(
empty
(
$user
))
{
if
(
empty
(
$user
))
{
return
[];
return
[];
}
}
...
@@ -736,6 +753,12 @@ class UserController
...
@@ -736,6 +753,12 @@ class UserController
}
}
}
}
$currentUser
=
UserModel
::
getById
([
'select'
=>
[
'"isRest"'
],
'id'
=>
$GLOBALS
[
'id'
]]);
if
(
$currentUser
[
'isRest'
])
{
$user
[
'x509Fingerprint'
]
=
$user
[
'x509_fingerprint'
];
}
unset
(
$user
[
'x509_fingerprint'
]);
return
$user
;
return
$user
;
}
}
}
}
This diff is collapsed.
Click to expand it.
src/app/user/models/UserModel.php
+
3
−
2
View file @
ba1a174e
...
@@ -80,7 +80,7 @@ class UserModel
...
@@ -80,7 +80,7 @@ class UserModel
public
static
function
create
(
array
$args
)
public
static
function
create
(
array
$args
)
{
{
ValidatorModel
::
notEmpty
(
$args
,
[
'login'
,
'email'
,
'firstname'
,
'lastname'
,
'picture'
]);
ValidatorModel
::
notEmpty
(
$args
,
[
'login'
,
'email'
,
'firstname'
,
'lastname'
,
'picture'
]);
ValidatorModel
::
stringType
(
$args
,
[
'login'
,
'email'
,
'firstname'
,
'lastname'
,
'picture'
,
'mode'
,
'signatureModes'
]);
ValidatorModel
::
stringType
(
$args
,
[
'login'
,
'email'
,
'firstname'
,
'lastname'
,
'picture'
,
'mode'
,
'signatureModes'
,
'x509_fingerprint'
]);
if
(
empty
(
$args
[
'password'
]))
{
if
(
empty
(
$args
[
'password'
]))
{
$args
[
'password'
]
=
AuthenticationModel
::
generatePassword
();
$args
[
'password'
]
=
AuthenticationModel
::
generatePassword
();
...
@@ -99,7 +99,8 @@ class UserModel
...
@@ -99,7 +99,8 @@ class UserModel
'"isRest"'
=>
empty
(
$args
[
'isRest'
])
?
'false'
:
'true'
,
'"isRest"'
=>
empty
(
$args
[
'isRest'
])
?
'false'
:
'true'
,
'picture'
=>
$args
[
'picture'
],
'picture'
=>
$args
[
'picture'
],
'password_modification_date'
=>
'CURRENT_TIMESTAMP'
,
'password_modification_date'
=>
'CURRENT_TIMESTAMP'
,
'signature_modes'
=>
$args
[
'signatureModes'
]
'signature_modes'
=>
$args
[
'signatureModes'
],
'x509_fingerprint'
=>
$args
[
'x509_fingerprint'
],
]
]
]);
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment