Skip to content

Commit

Permalink
added referrer query in bandage creation notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Nov 25, 2024
1 parent 81c9f89 commit 15e89fc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
9 changes: 6 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"singleQuote": true,
"trailingComma": "all"
}
"singleQuote": true,
"trailingComma": "none",
"endOfLine": "crlf",
"tabWidth": 4,
"printWidth": 250
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"prod": "nest build && node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
Expand Down
22 changes: 14 additions & 8 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,30 @@ export class AuthService {

// ----------------------- Create session token ---------------------------

const sessionId = sign({ userId: user_db.id }, 'ppl_super_secret', { expiresIn: Number(process.env.SESSION_TTL) });
const session = await this.createSession(user_db.id, user_agent);
return {
message: 'logged in',
message_ru: 'Вход произведен успешно',
sessionId: session.sessionId,
statusCode: 200
};
}


async createSession(user_id: string, user_agent: string) {
const sessionId = sign({ userId: user_id }, 'ppl_super_secret', { expiresIn: Number(process.env.SESSION_TTL) });
const token_record = await this.prisma.sessions.create({
data: {
sessionId: sessionId,
User_Agent: user_agent,
User: {
connect: {
id: user_db.id
id: user_id
}
}
}
});
return {
message: 'logged in',
message_ru: 'Вход произведен успешно',
sessionId: token_record.sessionId,
statusCode: 200
};
return token_record;
}

async validateSession(session: string | undefined, user_agent: string): Promise<Session | null> {
Expand Down
12 changes: 8 additions & 4 deletions src/minecraft/minecraft.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ export class MinecraftService {
return { statusCode: 200, new_data: result.valid };
}

async getByCode(code: string): Promise<{ nickname: string, UUID: string } | null> {
const response = await axios.get(`https://mc-oauth.andcool.ru/code/${code}`, { validateStatus: () => true });
if (response.status !== 200) return null;
return response.data as { nickname: string, UUID: string };
}

async connect(session: Session, code: string) {
/* connect minecraft account to a user profile */

Expand All @@ -243,16 +249,14 @@ export class MinecraftService {
};
}

const user_data = await axios.get(`https://mc-oauth.andcool.ru/code/${code}`, { validateStatus: () => true });
if (user_data.status !== 200) {
const data = await this.getByCode(code);
if (!data) {
return {
statusCode: 404,
message: 'Code not found',
message_ru: 'Код не найден'
};
}

const data = user_data.data as { nickname: string, UUID: string };
const skin_data = await this.updateSkinCache(data.UUID, true);

if (!skin_data) {
Expand Down
13 changes: 5 additions & 8 deletions src/workshop/bandage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class BandageService {
);

await this.notifications.createNotification(session.user.id, {
content: `Повязка <a href="/workshop/${result.externalId}"><b>${result.title}</b></a> создана и отправлена на проверку!`
content: `Повязка <a href="/workshop/${result.externalId}?referrer=/me/notifications"><b>${result.title}</b></a> создана и отправлена на проверку!`
});

return {
Expand All @@ -256,11 +256,8 @@ export class BandageService {

const admin = hasAccess(session?.user, RolesEnum.ManageBandages);
const categories = await this.prisma.category.findMany({
where: for_edit ? {
reachable: admin ? undefined : true,
only_admins: admin ? undefined : false,
visible: true
} : {
where: {
reachable: for_edit && !admin ? true : undefined,
only_admins: admin ? undefined : false,
visible: true
},
Expand Down Expand Up @@ -449,14 +446,14 @@ export class BandageService {
const difference_after = validated_categories.filter(element => !bandage_categories.includes(element));
if (difference_after.includes(moderation_id[1])) {
await this.notifications.createNotification(bandage.userId, {
content: `Повязка <a href="/workshop/${bandage.externalId}"><b>${bandage.title}</b></a> была отклонена. Пожалуйста, свяжитесь с <a href="/contacts"><b>администрацией</b></a> для уточнения причин.`,
content: `Повязка <a href="/workshop/${bandage.externalId}?referrer=/me/notifications"><b>${bandage.title}</b></a> была отклонена. Пожалуйста, свяжитесь с <a href="/contacts"><b>администрацией</b></a> для уточнения причин.`,
type: 2
});
}

else if (moderation_id.some(element => difference.includes(element))) {
await this.notifications.createNotification(bandage.userId, {
content: `Повязка <a href="/workshop/${bandage.externalId}"><b>${bandage.title}</b></a> успешно прошла проверку и теперь доступна остальным в <a href="/workshop"><b>мастерской</b></a>!`,
content: `Повязка <a href="/workshop/${bandage.externalId}?referrer=/me/notifications"><b>${bandage.title}</b></a> успешно прошла проверку и теперь доступна остальным в <a href="/workshop"><b>мастерской</b></a>!`,
type: 1
});
}
Expand Down

0 comments on commit 15e89fc

Please sign in to comment.