user role + module alias

This commit is contained in:
Yanis Rigaudeau 2022-10-16 15:28:42 +02:00
parent f6a7415884
commit 0c3a3546e6
Signed by: yanis
GPG Key ID: 4DD2841DF1C94D83
14 changed files with 70 additions and 29 deletions

View File

@ -1,19 +1,25 @@
# RA:TE (Réalité Augmenté: Truc en)
Version Live : https://html5.yayeet.cf
## Installation des dépendances
Dans ./
```bash
python install.py
python ./scripts/install.py
```
## Pour lancer le projet
Dans ./api
```bash
npm run dev
```
Dans ./www
```bash
npm run dev
```

View File

@ -11,7 +11,7 @@ Group=node
Environment="CONFIGFILE=/home/node/config/config.json"
WorkingDirectory=/home/node/app
ExecStart=/usr/bin/node /home/node/app/dist/app.js
ExecStart=/usr/bin/node /home/node/app/dist/api/src/app.js
[Install]
WantedBy=multi-user.target

24
api/package-lock.json generated
View File

@ -13,6 +13,7 @@
"express-session": "^1.17.3",
"express-validator": "^6.14.2",
"ip": "^1.1.8",
"module-alias": "^2.2.2",
"mongodb": "^4.10.0",
"uuid": "^9.0.0"
},
@ -21,6 +22,7 @@
"@types/express": "^4.17.14",
"@types/express-session": "^1.17.5",
"@types/ip": "^1.1.0",
"@types/module-alias": "^2.0.1",
"@types/node": "^18.7.18",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
@ -161,6 +163,12 @@
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
"dev": true
},
"node_modules/@types/module-alias": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/module-alias/-/module-alias-2.0.1.tgz",
"integrity": "sha512-DN/CCT1HQG6HquBNJdLkvV+4v5l/oEuwOHUPLxI+Eub0NED+lk0YUfba04WGH90EINiUrNgClkNnwGmbICeWMQ==",
"dev": true
},
"node_modules/@types/node": {
"version": "18.7.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz",
@ -1011,6 +1019,11 @@
"node": ">=10"
}
},
"node_modules/module-alias": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz",
"integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q=="
},
"node_modules/mongodb": {
"version": "4.10.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.10.0.tgz",
@ -1836,6 +1849,12 @@
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
"dev": true
},
"@types/module-alias": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/module-alias/-/module-alias-2.0.1.tgz",
"integrity": "sha512-DN/CCT1HQG6HquBNJdLkvV+4v5l/oEuwOHUPLxI+Eub0NED+lk0YUfba04WGH90EINiUrNgClkNnwGmbICeWMQ==",
"dev": true
},
"@types/node": {
"version": "18.7.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz",
@ -2467,6 +2486,11 @@
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true
},
"module-alias": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz",
"integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q=="
},
"mongodb": {
"version": "4.10.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.10.0.tgz",

View File

@ -7,7 +7,7 @@
"scripts": {
"build": "tsc",
"dev": "CONFIGFILE=config/config.json ts-node-dev --respawn --transpile-only ./src/app.ts",
"start": "npm run build && CONFIGFILE=config/config.json node ./dist/app.js",
"start": "npm run build && CONFIGFILE=config/config.json node ./dist/api/src/app.js",
"prettier": "prettier -w ./src"
},
"devDependencies": {
@ -15,6 +15,7 @@
"@types/express": "^4.17.14",
"@types/express-session": "^1.17.5",
"@types/ip": "^1.1.0",
"@types/module-alias": "^2.0.1",
"@types/node": "^18.7.18",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
@ -27,6 +28,7 @@
"express-session": "^1.17.3",
"express-validator": "^6.14.2",
"ip": "^1.1.8",
"module-alias": "^2.2.2",
"mongodb": "^4.10.0",
"uuid": "^9.0.0"
}

View File

@ -1,3 +1,4 @@
import './paths';
import Server from './framework/express/server';
import ip from 'ip';
import UserModel from './framework/mongo/user';

View File

@ -2,6 +2,7 @@ import {
UserCtor,
UserInfo,
UserInfoWithPassword,
UserRoles,
UserWithPasswordCtor,
} from '@core';
import { generateHash } from '../functions/password';
@ -9,17 +10,20 @@ import { Entity } from './entity';
export class User extends Entity implements UserInfo {
username: string;
role: keyof typeof UserRoles;
constructor(raw: UserCtor) {
super(raw);
this.username = raw.username ? raw.username : '';
this.username = raw.username || '';
this.role = raw.role || UserRoles.USER;
}
Info(): UserInfo {
return {
uuid: this.uuid,
username: this.username,
role: this.role,
};
}
}
@ -37,6 +41,7 @@ export class UserWithPassword extends User implements UserInfoWithPassword {
return {
uuid: this.uuid,
username: this.username,
role: this.role,
password: this.password,
};
}

5
api/src/paths.ts Normal file
View File

@ -0,0 +1,5 @@
import { addAliases } from 'module-alias';
addAliases({
'@core': `${__dirname}/../../core/src`,
});

View File

@ -7,16 +7,12 @@
"outDir": "dist",
"sourceMap": false,
"strictNullChecks": true,
"baseUrl": "./src",
"paths": {
"@core": ["../core/src"]
"@core": ["../../core/src"]
}
},
"lib": ["es2015"],
"include": ["src/**/*"],
"exclude": ["node_modules/*", "dist/*"],
"references": [
{
"path": "../core"
}
]
"exclude": ["node_modules/*", "dist/*"]
}

View File

@ -1,28 +1,35 @@
import { EntityInfo } from './entity';
export enum UserRoles {
ADMIN = 'ADMIN',
USER = 'USER',
}
export type UserInfo = {
uuid: string;
username: string;
role: keyof typeof UserRoles;
};
export type User = UserInfo & EntityInfo;
export type UserCtor = Partial<User>;
export type UserInfoWithPassword = {
password: string;
} & UserInfo;
export type User = UserInfo & EntityInfo;
export type UserWithPassword = UserInfoWithPassword & EntityInfo;
export type UserWithPasswordCtor = Partial<UserWithPassword>;
export type CreateUserBody = {
username: string;
password: string;
role: keyof typeof UserRoles;
};
export type LoginUserBody = {
username: string;
password: string;
};
export type UserCtor = Partial<User>;
export type UserWithPasswordCtor = Partial<UserWithPassword>;

View File

@ -8,6 +8,5 @@
"outDir": "dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules/*", "dist/*"],
"references": []
"exclude": ["node_modules/*", "dist/*"]
}

View File

@ -2,7 +2,7 @@
import os
import json
apps = json.load(open('apps.json'))['apps']
apps: list[str] = json.load(open('apps.json'))['apps']
print(len(apps), 'apps:', apps)

View File

@ -2,7 +2,7 @@
import os
import json
apps = json.load(open('apps.json'))['apps']
apps: list[str] = json.load(open('apps.json'))['apps']
print(len(apps), 'apps:', apps)

View File

@ -2,7 +2,7 @@
import os
import json
apps = json.load(open('apps.json'))['apps']
apps: list[str] = json.load(open('apps.json'))['apps']
print(len(apps), 'apps:', apps)

View File

@ -3,15 +3,11 @@
"compilerOptions": {
"sourceMap": false,
"strictNullChecks": true,
"baseUrl": "./src",
"paths": {
"@core": ["../core/src"]
"@core": ["../../core/src"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules/*", "public/*"],
"references": [
{
"path": "../core"
}
]
"exclude": ["node_modules/*", "public/*"]
}