user role + module alias
This commit is contained in:
parent
f6a7415884
commit
0c3a3546e6
@ -1,19 +1,25 @@
|
|||||||
# RA:TE (Réalité Augmenté: Truc en)
|
# RA:TE (Réalité Augmenté: Truc en)
|
||||||
|
|
||||||
|
Version Live : https://html5.yayeet.cf
|
||||||
|
|
||||||
## Installation des dépendances
|
## Installation des dépendances
|
||||||
|
|
||||||
|
Dans ./
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python install.py
|
python ./scripts/install.py
|
||||||
```
|
```
|
||||||
|
|
||||||
## Pour lancer le projet
|
## Pour lancer le projet
|
||||||
|
|
||||||
Dans ./api
|
Dans ./api
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dev
|
npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Dans ./www
|
Dans ./www
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dev
|
npm run dev
|
||||||
```
|
```
|
||||||
|
@ -11,7 +11,7 @@ Group=node
|
|||||||
|
|
||||||
Environment="CONFIGFILE=/home/node/config/config.json"
|
Environment="CONFIGFILE=/home/node/config/config.json"
|
||||||
WorkingDirectory=/home/node/app
|
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]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
24
api/package-lock.json
generated
24
api/package-lock.json
generated
@ -13,6 +13,7 @@
|
|||||||
"express-session": "^1.17.3",
|
"express-session": "^1.17.3",
|
||||||
"express-validator": "^6.14.2",
|
"express-validator": "^6.14.2",
|
||||||
"ip": "^1.1.8",
|
"ip": "^1.1.8",
|
||||||
|
"module-alias": "^2.2.2",
|
||||||
"mongodb": "^4.10.0",
|
"mongodb": "^4.10.0",
|
||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0"
|
||||||
},
|
},
|
||||||
@ -21,6 +22,7 @@
|
|||||||
"@types/express": "^4.17.14",
|
"@types/express": "^4.17.14",
|
||||||
"@types/express-session": "^1.17.5",
|
"@types/express-session": "^1.17.5",
|
||||||
"@types/ip": "^1.1.0",
|
"@types/ip": "^1.1.0",
|
||||||
|
"@types/module-alias": "^2.0.1",
|
||||||
"@types/node": "^18.7.18",
|
"@types/node": "^18.7.18",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
@ -161,6 +163,12 @@
|
|||||||
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
|
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/@types/node": {
|
||||||
"version": "18.7.18",
|
"version": "18.7.18",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz",
|
||||||
@ -1011,6 +1019,11 @@
|
|||||||
"node": ">=10"
|
"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": {
|
"node_modules/mongodb": {
|
||||||
"version": "4.10.0",
|
"version": "4.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.10.0.tgz",
|
||||||
@ -1836,6 +1849,12 @@
|
|||||||
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
|
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
|
||||||
"dev": true
|
"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": {
|
"@types/node": {
|
||||||
"version": "18.7.18",
|
"version": "18.7.18",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz",
|
||||||
@ -2467,6 +2486,11 @@
|
|||||||
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
|
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
|
||||||
"dev": true
|
"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": {
|
"mongodb": {
|
||||||
"version": "4.10.0",
|
"version": "4.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.10.0.tgz",
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"dev": "CONFIGFILE=config/config.json ts-node-dev --respawn --transpile-only ./src/app.ts",
|
"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"
|
"prettier": "prettier -w ./src"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -15,6 +15,7 @@
|
|||||||
"@types/express": "^4.17.14",
|
"@types/express": "^4.17.14",
|
||||||
"@types/express-session": "^1.17.5",
|
"@types/express-session": "^1.17.5",
|
||||||
"@types/ip": "^1.1.0",
|
"@types/ip": "^1.1.0",
|
||||||
|
"@types/module-alias": "^2.0.1",
|
||||||
"@types/node": "^18.7.18",
|
"@types/node": "^18.7.18",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
@ -27,6 +28,7 @@
|
|||||||
"express-session": "^1.17.3",
|
"express-session": "^1.17.3",
|
||||||
"express-validator": "^6.14.2",
|
"express-validator": "^6.14.2",
|
||||||
"ip": "^1.1.8",
|
"ip": "^1.1.8",
|
||||||
|
"module-alias": "^2.2.2",
|
||||||
"mongodb": "^4.10.0",
|
"mongodb": "^4.10.0",
|
||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0"
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import './paths';
|
||||||
import Server from './framework/express/server';
|
import Server from './framework/express/server';
|
||||||
import ip from 'ip';
|
import ip from 'ip';
|
||||||
import UserModel from './framework/mongo/user';
|
import UserModel from './framework/mongo/user';
|
||||||
|
@ -2,6 +2,7 @@ import {
|
|||||||
UserCtor,
|
UserCtor,
|
||||||
UserInfo,
|
UserInfo,
|
||||||
UserInfoWithPassword,
|
UserInfoWithPassword,
|
||||||
|
UserRoles,
|
||||||
UserWithPasswordCtor,
|
UserWithPasswordCtor,
|
||||||
} from '@core';
|
} from '@core';
|
||||||
import { generateHash } from '../functions/password';
|
import { generateHash } from '../functions/password';
|
||||||
@ -9,17 +10,20 @@ import { Entity } from './entity';
|
|||||||
|
|
||||||
export class User extends Entity implements UserInfo {
|
export class User extends Entity implements UserInfo {
|
||||||
username: string;
|
username: string;
|
||||||
|
role: keyof typeof UserRoles;
|
||||||
|
|
||||||
constructor(raw: UserCtor) {
|
constructor(raw: UserCtor) {
|
||||||
super(raw);
|
super(raw);
|
||||||
|
|
||||||
this.username = raw.username ? raw.username : '';
|
this.username = raw.username || '';
|
||||||
|
this.role = raw.role || UserRoles.USER;
|
||||||
}
|
}
|
||||||
|
|
||||||
Info(): UserInfo {
|
Info(): UserInfo {
|
||||||
return {
|
return {
|
||||||
uuid: this.uuid,
|
uuid: this.uuid,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
|
role: this.role,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,6 +41,7 @@ export class UserWithPassword extends User implements UserInfoWithPassword {
|
|||||||
return {
|
return {
|
||||||
uuid: this.uuid,
|
uuid: this.uuid,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
|
role: this.role,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
5
api/src/paths.ts
Normal file
5
api/src/paths.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { addAliases } from 'module-alias';
|
||||||
|
|
||||||
|
addAliases({
|
||||||
|
'@core': `${__dirname}/../../core/src`,
|
||||||
|
});
|
@ -7,16 +7,12 @@
|
|||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
|
"baseUrl": "./src",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@core": ["../core/src"]
|
"@core": ["../../core/src"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lib": ["es2015"],
|
"lib": ["es2015"],
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*"],
|
||||||
"exclude": ["node_modules/*", "dist/*"],
|
"exclude": ["node_modules/*", "dist/*"]
|
||||||
"references": [
|
|
||||||
{
|
|
||||||
"path": "../core"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,35 @@
|
|||||||
import { EntityInfo } from './entity';
|
import { EntityInfo } from './entity';
|
||||||
|
|
||||||
|
export enum UserRoles {
|
||||||
|
ADMIN = 'ADMIN',
|
||||||
|
USER = 'USER',
|
||||||
|
}
|
||||||
|
|
||||||
export type UserInfo = {
|
export type UserInfo = {
|
||||||
uuid: string;
|
uuid: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
role: keyof typeof UserRoles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type User = UserInfo & EntityInfo;
|
||||||
|
|
||||||
|
export type UserCtor = Partial<User>;
|
||||||
|
|
||||||
export type UserInfoWithPassword = {
|
export type UserInfoWithPassword = {
|
||||||
password: string;
|
password: string;
|
||||||
} & UserInfo;
|
} & UserInfo;
|
||||||
|
|
||||||
export type User = UserInfo & EntityInfo;
|
|
||||||
|
|
||||||
export type UserWithPassword = UserInfoWithPassword & EntityInfo;
|
export type UserWithPassword = UserInfoWithPassword & EntityInfo;
|
||||||
|
|
||||||
|
export type UserWithPasswordCtor = Partial<UserWithPassword>;
|
||||||
|
|
||||||
export type CreateUserBody = {
|
export type CreateUserBody = {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
role: keyof typeof UserRoles;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LoginUserBody = {
|
export type LoginUserBody = {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UserCtor = Partial<User>;
|
|
||||||
|
|
||||||
export type UserWithPasswordCtor = Partial<UserWithPassword>;
|
|
||||||
|
@ -8,6 +8,5 @@
|
|||||||
"outDir": "dist"
|
"outDir": "dist"
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*"],
|
||||||
"exclude": ["node_modules/*", "dist/*"],
|
"exclude": ["node_modules/*", "dist/*"]
|
||||||
"references": []
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
|
||||||
apps = json.load(open('apps.json'))['apps']
|
apps: list[str] = json.load(open('apps.json'))['apps']
|
||||||
|
|
||||||
print(len(apps), 'apps:', apps)
|
print(len(apps), 'apps:', apps)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
|
||||||
apps = json.load(open('apps.json'))['apps']
|
apps: list[str] = json.load(open('apps.json'))['apps']
|
||||||
|
|
||||||
print(len(apps), 'apps:', apps)
|
print(len(apps), 'apps:', apps)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
|
||||||
apps = json.load(open('apps.json'))['apps']
|
apps: list[str] = json.load(open('apps.json'))['apps']
|
||||||
|
|
||||||
print(len(apps), 'apps:', apps)
|
print(len(apps), 'apps:', apps)
|
||||||
|
|
||||||
|
@ -3,15 +3,11 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
|
"baseUrl": "./src",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@core": ["../core/src"]
|
"@core": ["../../core/src"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*"],
|
||||||
"exclude": ["node_modules/*", "public/*"],
|
"exclude": ["node_modules/*", "public/*"]
|
||||||
"references": [
|
|
||||||
{
|
|
||||||
"path": "../core"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user