Compare commits
7 Commits
1ed1f018e8
...
896b01f8b4
Author | SHA1 | Date | |
---|---|---|---|
896b01f8b4 | |||
03d10ca675 | |||
fa93b24ccc | |||
95dd3f36bf | |||
6a54dd0afa | |||
956a6ca7af | |||
e995aaa970 |
@ -4,6 +4,6 @@ PROJECT_NAME=''
|
|||||||
|
|
||||||
MYSQL_HOST=''
|
MYSQL_HOST=''
|
||||||
MYSQL_PORT=''
|
MYSQL_PORT=''
|
||||||
MYSQL_USERNAME=''
|
MYSQL_USER=''
|
||||||
MYSQL_PASS=''
|
MYSQL_PASS=''
|
||||||
MYSQL_DATABASE=''
|
MYSQL_DATABASE=''
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
.env
|
||||||
|
2
.idea/inspectionProfiles/Project_Default.xml
generated
2
.idea/inspectionProfiles/Project_Default.xml
generated
@ -3,7 +3,7 @@
|
|||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
<Languages>
|
<Languages>
|
||||||
<language minSize="82" name="TypeScript" />
|
<language minSize="114" name="TypeScript" />
|
||||||
</Languages>
|
</Languages>
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
</profile>
|
</profile>
|
||||||
|
8
.vscode/settings.json
vendored
Normal file
8
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"conventionalCommits.scopes": [
|
||||||
|
"interfaces",
|
||||||
|
"routes",
|
||||||
|
"services",
|
||||||
|
"controllers"
|
||||||
|
]
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
import JwtService from "@services/jwt.service";
|
import JwtService from "@services/jwt.service";
|
||||||
|
|
||||||
|
|
||||||
import {Logger} from "tslog";
|
import type {IReqEditUserData} from "@interfaces/IReqEditUserData";
|
||||||
import type {Request, Response} from "express";
|
|
||||||
import UserService from "@services/user.service";
|
import UserService from "@services/user.service";
|
||||||
import {IReqEditUserData} from "@interfaces/IReqEditUserData";
|
import type {Request, Response} from "express";
|
||||||
|
import {Logger} from "tslog";
|
||||||
|
|
||||||
|
|
||||||
const logger = new Logger({ name: "AuthController" });
|
const logger = new Logger({ name: "AuthController" });
|
||||||
|
@ -4,7 +4,7 @@ export interface IDbModel {
|
|||||||
display_name: string;
|
display_name: string;
|
||||||
brand_id: string;
|
brand_id: string;
|
||||||
category_id: string;
|
category_id: string;
|
||||||
image_bfile: BinaryType;
|
image_blob: BinaryType;
|
||||||
is_trending: boolean;
|
is_trending: boolean;
|
||||||
base_price: number;
|
base_price: number;
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
export * from './jwt.service';
|
export * from './jwt.service';
|
||||||
export * from './mysql.service'
|
export * as MySqlService from './mysql.service'
|
@ -319,7 +319,29 @@ const MySqlService = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
//TODO Create / Update / Delete
|
|
||||||
|
insert(handler: MysqlHandler, data: IDbModel) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!data.id) return reject('Id is undefined');
|
||||||
|
if (data.id.length !== 36) return reject('Id invalid');
|
||||||
|
|
||||||
|
const _sql = "INSERT INTO `users`(`id`,`username`, `firstname`, `lastname`, `dob`, `email`, `is_mail_verified`, `is_admin`, `gdpr`, `hash`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||||
|
const _values = [
|
||||||
|
data.slug_name,
|
||||||
|
data.display_name,
|
||||||
|
data.brand_id,
|
||||||
|
data.category_id,
|
||||||
|
data.image_blob,
|
||||||
|
data.is_trending,
|
||||||
|
data.base_price
|
||||||
|
]
|
||||||
|
try {
|
||||||
|
resolve(handler.execute(_sql, _values))
|
||||||
|
} catch (err: unknown) {
|
||||||
|
reject(err as Error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@ import {Logger} from "tslog";
|
|||||||
|
|
||||||
import Argon2id from "@node-rs/argon2";
|
import Argon2id from "@node-rs/argon2";
|
||||||
import MySqlService from "@services/mysql.service";
|
import MySqlService from "@services/mysql.service";
|
||||||
|
import CredentialService from "@services/credential.service";
|
||||||
|
import JwtService from "@services/jwt.service";
|
||||||
|
import MysqlService from "@services/mysql.service";
|
||||||
|
|
||||||
|
|
||||||
const logger = new Logger({ name: "UserService" });
|
const logger = new Logger({ name: "UserService" });
|
||||||
@ -50,7 +53,7 @@ async function RegisterService(sanitizedData) {
|
|||||||
logger.info(`REGISTER :> Invalid password (${sanitizedData.username})`)
|
logger.info(`REGISTER :> Invalid password (${sanitizedData.username})`)
|
||||||
return { error: "invalidPassword" };
|
return { error: "invalidPassword" };
|
||||||
}
|
}
|
||||||
const passwordHash = await getHashFromPassword(sanitizedData.password)
|
const passwordHash = await CredentialService.hash(sanitizedData.password)
|
||||||
|
|
||||||
// Does the new user has accepted GDPR ?
|
// Does the new user has accepted GDPR ?
|
||||||
if (sanitizedData.gdpr !== true) {
|
if (sanitizedData.gdpr !== true) {
|
||||||
@ -77,7 +80,7 @@ async function RegisterService(sanitizedData) {
|
|||||||
// JWT
|
// JWT
|
||||||
|
|
||||||
const alg = 'HS512'
|
const alg = 'HS512'
|
||||||
const token = await JwtSign({
|
const token = await JwtService.sign({
|
||||||
sub: NewUser.id
|
sub: NewUser.id
|
||||||
}, alg,
|
}, alg,
|
||||||
'1d',
|
'1d',
|
||||||
@ -112,9 +115,9 @@ async function RegisterService(sanitizedData) {
|
|||||||
* @returns {string} result.user.username - The username of the user.
|
* @returns {string} result.user.username - The username of the user.
|
||||||
* @returns {string} result.user.displayName - The display name of the user.
|
* @returns {string} result.user.displayName - The display name of the user.
|
||||||
*/
|
*/
|
||||||
async function LoginService(sanitizedData) {
|
async function LoginService(sanitizedData: { username: string; password: string; }) {
|
||||||
//const passwordHash = await getHashFromPassword(sanitizedData.password);
|
//const passwordHash = await getHashFromPassword(sanitizedData.password);
|
||||||
const dbUser = await getUserFromUsername(sanitizedData.username);
|
const dbUser = await MysqlService.User.getByUsername(DbHandler, sanitizedData.username);
|
||||||
if (!dbUser) {
|
if (!dbUser) {
|
||||||
console.log(`LoginService :> User does not exist (${sanitizedData.username})`);
|
console.log(`LoginService :> User does not exist (${sanitizedData.username})`);
|
||||||
return { error: "userNotFound" };
|
return { error: "userNotFound" };
|
||||||
@ -124,13 +127,7 @@ async function LoginService(sanitizedData) {
|
|||||||
console.log(`LoginService :> Invalid password (${sanitizedData.username})`);
|
console.log(`LoginService :> Invalid password (${sanitizedData.username})`);
|
||||||
return { error: "invalidPassword" };
|
return { error: "invalidPassword" };
|
||||||
}
|
}
|
||||||
const isPasswordValid = await Argon2id.verify(
|
const isPasswordValid = await CredentialService.compare(sanitizedData.password, dbUser.hash)
|
||||||
Buffer.from(dbUser.passwordHash),
|
|
||||||
Buffer.from(sanitizedData.password),
|
|
||||||
{
|
|
||||||
secret: Buffer.from(`${process.env.HASH_SECRET}`),
|
|
||||||
algorithm: 2
|
|
||||||
});
|
|
||||||
if (!isPasswordValid) {
|
if (!isPasswordValid) {
|
||||||
console.log(isPasswordValid)
|
console.log(isPasswordValid)
|
||||||
console.log(`LoginService :> Invalid password (${sanitizedData.username})`);
|
console.log(`LoginService :> Invalid password (${sanitizedData.username})`);
|
||||||
@ -139,7 +136,7 @@ async function LoginService(sanitizedData) {
|
|||||||
// biome-ignore lint/style/useConst: <explanation>
|
// biome-ignore lint/style/useConst: <explanation>
|
||||||
let userData = {
|
let userData = {
|
||||||
error: "none",
|
error: "none",
|
||||||
jwt: null,
|
jwt: '',
|
||||||
user: {
|
user: {
|
||||||
id: dbUser.id,
|
id: dbUser.id,
|
||||||
username: dbUser.username,
|
username: dbUser.username,
|
||||||
@ -147,8 +144,7 @@ async function LoginService(sanitizedData) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const alg = 'HS512';
|
userData.jwt = await JwtService.sign({sub: dbUser.id}, {alg: 'HS512'}, '7d', 'user')
|
||||||
userData.jwt = await JwtSign({sub: dbUser.id}, alg, '1d', 'user')
|
|
||||||
|
|
||||||
|
|
||||||
console.log("USERDATA :>");
|
console.log("USERDATA :>");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user