Compare commits
No commits in common. "896b01f8b4b9c1d4f1d9203bd0a794e1ede02190" and "1ed1f018e86848b1168e5c72f9395dd6b07a6083" have entirely different histories.
896b01f8b4
...
1ed1f018e8
@ -4,6 +4,6 @@ PROJECT_NAME=''
|
|||||||
|
|
||||||
MYSQL_HOST=''
|
MYSQL_HOST=''
|
||||||
MYSQL_PORT=''
|
MYSQL_PORT=''
|
||||||
MYSQL_USER=''
|
MYSQL_USERNAME=''
|
||||||
MYSQL_PASS=''
|
MYSQL_PASS=''
|
||||||
MYSQL_DATABASE=''
|
MYSQL_DATABASE=''
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
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="114" name="TypeScript" />
|
<language minSize="82" name="TypeScript" />
|
||||||
</Languages>
|
</Languages>
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
</profile>
|
</profile>
|
||||||
|
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"conventionalCommits.scopes": [
|
|
||||||
"interfaces",
|
|
||||||
"routes",
|
|
||||||
"services",
|
|
||||||
"controllers"
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,10 +1,10 @@
|
|||||||
import JwtService from "@services/jwt.service";
|
import JwtService from "@services/jwt.service";
|
||||||
|
|
||||||
|
|
||||||
import type {IReqEditUserData} from "@interfaces/IReqEditUserData";
|
|
||||||
import UserService from "@services/user.service";
|
|
||||||
import type {Request, Response} from "express";
|
|
||||||
import {Logger} from "tslog";
|
import {Logger} from "tslog";
|
||||||
|
import type {Request, Response} from "express";
|
||||||
|
import UserService from "@services/user.service";
|
||||||
|
import {IReqEditUserData} from "@interfaces/IReqEditUserData";
|
||||||
|
|
||||||
|
|
||||||
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_blob: BinaryType;
|
image_bfile: 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 * as MySqlService from './mysql.service'
|
export * from './mysql.service'
|
@ -319,29 +319,7 @@ 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,9 +2,6 @@ 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" });
|
||||||
@ -53,7 +50,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 CredentialService.hash(sanitizedData.password)
|
const passwordHash = await getHashFromPassword(sanitizedData.password)
|
||||||
|
|
||||||
// Does the new user has accepted GDPR ?
|
// Does the new user has accepted GDPR ?
|
||||||
if (sanitizedData.gdpr !== true) {
|
if (sanitizedData.gdpr !== true) {
|
||||||
@ -80,7 +77,7 @@ async function RegisterService(sanitizedData) {
|
|||||||
// JWT
|
// JWT
|
||||||
|
|
||||||
const alg = 'HS512'
|
const alg = 'HS512'
|
||||||
const token = await JwtService.sign({
|
const token = await JwtSign({
|
||||||
sub: NewUser.id
|
sub: NewUser.id
|
||||||
}, alg,
|
}, alg,
|
||||||
'1d',
|
'1d',
|
||||||
@ -115,9 +112,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: { username: string; password: string; }) {
|
async function LoginService(sanitizedData) {
|
||||||
//const passwordHash = await getHashFromPassword(sanitizedData.password);
|
//const passwordHash = await getHashFromPassword(sanitizedData.password);
|
||||||
const dbUser = await MysqlService.User.getByUsername(DbHandler, sanitizedData.username);
|
const dbUser = await getUserFromUsername(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" };
|
||||||
@ -127,7 +124,13 @@ async function LoginService(sanitizedData: { username: string; password: string;
|
|||||||
console.log(`LoginService :> Invalid password (${sanitizedData.username})`);
|
console.log(`LoginService :> Invalid password (${sanitizedData.username})`);
|
||||||
return { error: "invalidPassword" };
|
return { error: "invalidPassword" };
|
||||||
}
|
}
|
||||||
const isPasswordValid = await CredentialService.compare(sanitizedData.password, dbUser.hash)
|
const isPasswordValid = await Argon2id.verify(
|
||||||
|
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})`);
|
||||||
@ -136,7 +139,7 @@ async function LoginService(sanitizedData: { username: string; password: string;
|
|||||||
// biome-ignore lint/style/useConst: <explanation>
|
// biome-ignore lint/style/useConst: <explanation>
|
||||||
let userData = {
|
let userData = {
|
||||||
error: "none",
|
error: "none",
|
||||||
jwt: '',
|
jwt: null,
|
||||||
user: {
|
user: {
|
||||||
id: dbUser.id,
|
id: dbUser.id,
|
||||||
username: dbUser.username,
|
username: dbUser.username,
|
||||||
@ -144,7 +147,8 @@ async function LoginService(sanitizedData: { username: string; password: string;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
userData.jwt = await JwtService.sign({sub: dbUser.id}, {alg: 'HS512'}, '7d', 'user')
|
const alg = 'HS512';
|
||||||
|
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