forked from tools/josh
1
0
Fork 0

Use default home directory given empty string

Fixes #169.
This commit is contained in:
Florine W. Dekker 2021-05-17 12:42:07 +02:00
parent 5abf9d8201
commit bb9c535bb3
Signed by: FWDekker
GPG Key ID: 78B3EAF58145AF25
3 changed files with 13 additions and 14 deletions

BIN
package-lock.json generated

Binary file not shown.

View File

@ -1,6 +1,6 @@
{ {
"name": "fwdekker.com", "name": "fwdekker.com",
"version": "0.40.7", "version": "0.40.8",
"description": "The source code of [my personal website](https://fwdekker.com/).", "description": "The source code of [my personal website](https://fwdekker.com/).",
"author": "Felix W. Dekker", "author": "Felix W. Dekker",
"browser": "dist/bundle.js", "browser": "dist/bundle.js",
@ -24,7 +24,7 @@
}, },
"devDependencies": { "devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1", "@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/chai": "^4.2.17", "@types/chai": "^4.2.18",
"@types/js-cookie": "^2.2.6", "@types/js-cookie": "^2.2.6",
"@types/mocha": "^8.2.2", "@types/mocha": "^8.2.2",
"@types/semver": "^6.2.1", "@types/semver": "^6.2.1",
@ -39,12 +39,12 @@
"grunt-webpack": "^4.0.3", "grunt-webpack": "^4.0.3",
"jsdom": "^16.5.3", "jsdom": "^16.5.3",
"jsdom-global": "^3.0.2", "jsdom-global": "^3.0.2",
"mocha": "^8.3.2", "mocha": "^8.4.0",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"ts-loader": "^9.1.2", "ts-loader": "^9.1.2",
"ts-node": "^9.1.1", "ts-node": "^9.1.1",
"typescript": "^4.2.4", "typescript": "^4.2.4",
"webpack": "^5.36.2", "webpack": "^5.37.0",
"webpack-cli": "^4.7.0" "webpack-cli": "^4.7.0"
} }
} }

View File

@ -121,7 +121,7 @@ export class UserList {
return false; return false;
const modifiedUsers = this.users.map(user => user.name === modifiedUser.name ? modifiedUser : user); const modifiedUsers = this.users.map(user => user.name === modifiedUser.name ? modifiedUser : user);
this.userFile.open("write"); // Empty file this.userFile.open("write"); // Empty file
modifiedUsers.forEach(user => this.add(user)); modifiedUsers.forEach(user => this.add(user));
return true; return true;
} }
@ -192,16 +192,15 @@ export class User {
* Constructs a new user. * Constructs a new user.
* *
* @param name the name of the user * @param name the name of the user
* @param password the hash of this user's password * @param passwordHash the hash of this user's password
* @param home the path to the user's home directory, or `undefined` to use `/home/<name>` * @param home the path to the user's home directory, or an empty string to use `/home/<name>`
* @param description the description of the user * @param description the description of the user
*/ */
constructor(name: string, password: string, home: string | undefined = undefined, constructor(name: string, passwordHash: string, home: string = "", description: string = "") {
description: string | undefined = undefined) {
this.name = name; this.name = name;
this.passwordHash = password; this.passwordHash = passwordHash;
this.home = home ?? `/home/${name}`; this.home = home;
this.description = description ?? ""; this.description = description;
} }
@ -256,13 +255,13 @@ export class User {
/** /**
* Sets the path to the user's home directory. * Sets the path to the user's home directory.
* *
* @param home the path to the user's home directory to set * @param home the path to the user's home directory to set, or empty string to use `/home/<name>`
*/ */
set home(home: string) { set home(home: string) {
if (home?.includes("|") || home?.includes("\n")) if (home?.includes("|") || home?.includes("\n"))
throw new IllegalArgumentError("Home must not contain pipe ('|') or newline character."); throw new IllegalArgumentError("Home must not contain pipe ('|') or newline character.");
this._home = home; this._home = home || `/home/${this.name}`;
} }
/** /**