Skip to content

Commit 646b5d1

Browse files
jessevzjessevz
andauthored
Fix bug in user creation (#1887)
* Fix bug in user creation * Made user session lifetime configurable --------- Co-authored-by: jessevz <jesse.van.zutphen@nfi.nl>
1 parent 42afc2e commit 646b5d1

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/dba/models/User.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static function getFeatures(): array {
7272
$dict['isComputedPassword'] = ['read_only' => True, "type" => "bool", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "isComputedPassword", "public" => False, "dba_mapping" => False];
7373
$dict['lastLoginDate'] = ['read_only' => True, "type" => "int64", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "lastLoginDate", "public" => False, "dba_mapping" => False];
7474
$dict['registeredSince'] = ['read_only' => True, "type" => "int64", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "registeredSince", "public" => False, "dba_mapping" => False];
75-
$dict['sessionLifetime'] = ['read_only' => False, "type" => "int", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "sessionLifetime", "public" => False, "dba_mapping" => False];
75+
$dict['sessionLifetime'] = ['read_only' => False, "type" => "int", "subtype" => "unset", "choices" => "unset", "null" => True, "pk" => False, "protected" => False, "private" => False, "alias" => "sessionLifetime", "public" => False, "dba_mapping" => False];
7676
$dict['rightGroupId'] = ['read_only' => False, "type" => "int", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "globalPermissionGroupId", "public" => False, "dba_mapping" => False];
7777
$dict['yubikey'] = ['read_only' => True, "type" => "str(256)", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "yubikey", "public" => False, "dba_mapping" => False];
7878
$dict['otp1'] = ['read_only' => True, "type" => "str(256)", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "otp1", "public" => False, "dba_mapping" => False];

src/inc/apiv2/model/users.routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ protected function createObject($data): int {
8686
$data[User::RIGHT_GROUP_ID],
8787
$this->getCurrentUser(),
8888
$data[User::IS_VALID] ?? false,
89+
$data[User::SESSION_LIFETIME] ?? 3600
8990
);
9091

9192
return $user->getId();
@@ -95,6 +96,7 @@ function getAllPostParameters(array $features): array {
9596

9697
$features = parent::getAllPostParameters($features);
9798
unset($features[User::IS_VALID]);
99+
unset($features[User::SESSION_LIFETIME]);
98100
return $features;
99101
}
100102

src/inc/utils/UserUtils.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public static function setPassword($userId, $password, $adminUser) {
186186
* @throws HttpConflict
187187
* @throws HttpError
188188
*/
189-
public static function createUser(string $username, string $email, int $rightGroupId, User $adminUser, bool $isValid = true): User {
189+
public static function createUser(string $username, string $email, int $rightGroupId, User $adminUser, bool $isValid = true, int $session_lifetime=3600): User {
190190
$username = htmlentities($username, ENT_QUOTES, "UTF-8");
191191
$group = AccessControlUtils::getGroup($rightGroupId);
192192
if (!filter_var($email, FILTER_VALIDATE_EMAIL) || strlen($email) == 0) {
@@ -206,7 +206,7 @@ public static function createUser(string $username, string $email, int $rightGro
206206
$newPass = Util::randomString(10);
207207
$newSalt = Util::randomString(20);
208208
$newHash = Encryption::passwordHash($newPass, $newSalt);
209-
$user = new User(null, $username, $email, $newHash, $newSalt, $isValid ? 1: 0, 1, 0, time(), 3600, $group->getId(), 0, "", "", "", "");
209+
$user = new User(null, $username, $email, $newHash, $newSalt, $isValid ? 1: 0, 1, 0, time(), $session_lifetime, $group->getId(), 0, "", "", "", "");
210210
Factory::getUserFactory()->save($user);
211211

212212
// add user to default group

0 commit comments

Comments
 (0)