-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316 from TaloDev/develop
Release 0.37.0
- Loading branch information
Showing
38 changed files
with
942 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,6 +237,45 @@ const PlayerAuthAPIDocs: APIDocs<PlayerAuthAPIService> = { | |
} | ||
} | ||
] | ||
}, | ||
toggleVerification: { | ||
description: 'Toggle if verification is required for a player account', | ||
params: { | ||
headers: { | ||
'x-talo-player': 'The ID of the player', | ||
'x-talo-alias': 'The ID of the player\'s alias', | ||
'x-talo-session': 'The session token' | ||
}, | ||
body: { | ||
currentPassword: 'The current password of the player', | ||
verificationEnabled: 'The new verification status for the player account', | ||
email: 'Required when attempting to enable verification if the player does not currently have an email address set' | ||
} | ||
}, | ||
samples: [ | ||
{ | ||
title: 'Sample request (disabling verification)', | ||
sample: { | ||
currentPassword: 'password', | ||
verificationEnabled: false | ||
} | ||
}, | ||
{ | ||
title: 'Sample request (enabling verification, player does not have an email address)', | ||
sample: { | ||
currentPassword: 'password', | ||
email: '[email protected]', | ||
verificationEnabled: true | ||
} | ||
}, | ||
{ | ||
title: 'Sample request (enabling verification, player has an email address)', | ||
sample: { | ||
currentPassword: 'password', | ||
verificationEnabled: true | ||
} | ||
} | ||
] | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Entity, Enum, ManyToOne, PrimaryKey, Property } from '@mikro-orm/mysql' | ||
import Player from './player' | ||
import PlayerAlias, { PlayerAliasService } from './player-alias' | ||
|
||
export enum PlayerAuthActivityType { | ||
REGISTERED, | ||
VERIFICATION_STARTED, | ||
VERIFICATION_FAILED, | ||
LOGGED_IN, | ||
LOGGED_OUT, | ||
CHANGED_PASSWORD, | ||
CHANGED_EMAIL, | ||
PASSWORD_RESET_REQUESTED, | ||
PASSWORD_RESET_COMPLETED, | ||
VERFICIATION_TOGGLED, | ||
CHANGE_PASSWORD_FAILED, | ||
CHANGE_EMAIL_FAILED, | ||
TOGGLE_VERIFICATION_FAILED | ||
} | ||
|
||
@Entity() | ||
export default class PlayerAuthActivity { | ||
@PrimaryKey() | ||
id: number | ||
|
||
@ManyToOne(() => Player, { eager: true }) | ||
player: Player | ||
|
||
@Enum(() => PlayerAuthActivityType) | ||
type: PlayerAuthActivityType | ||
|
||
@Property({ type: 'json' }) | ||
extra: { | ||
[key: string]: unknown | ||
} = {} | ||
|
||
@Property() | ||
createdAt: Date = new Date() | ||
|
||
constructor(player: Player) { | ||
this.player = player | ||
} | ||
|
||
private getAuthAlias(): PlayerAlias { | ||
return this.player.aliases.find((alias) => alias.service === PlayerAliasService.TALO) | ||
} | ||
|
||
/* v8 ignore start */ | ||
private getActivity(): string { | ||
const authAlias = this.getAuthAlias() | ||
|
||
switch (this.type) { | ||
case PlayerAuthActivityType.REGISTERED: | ||
return `${authAlias.identifier} created their account` | ||
case PlayerAuthActivityType.VERIFICATION_STARTED: | ||
return `${authAlias.identifier} started verification` | ||
case PlayerAuthActivityType.VERIFICATION_FAILED: | ||
return `${authAlias.identifier} failed verification` | ||
case PlayerAuthActivityType.LOGGED_IN: | ||
return `${authAlias.identifier} logged in` | ||
case PlayerAuthActivityType.LOGGED_OUT: | ||
return `${authAlias.identifier} logged out` | ||
case PlayerAuthActivityType.CHANGED_PASSWORD: | ||
return `${authAlias.identifier} changed their password` | ||
case PlayerAuthActivityType.CHANGED_EMAIL: | ||
return `${authAlias.identifier} changed their email` | ||
case PlayerAuthActivityType.PASSWORD_RESET_REQUESTED: | ||
return `A password reset request was made for ${authAlias.identifier}'s account` | ||
case PlayerAuthActivityType.PASSWORD_RESET_COMPLETED: | ||
return `A password reset was completed for ${authAlias.identifier}'s account` | ||
case PlayerAuthActivityType.VERFICIATION_TOGGLED: | ||
return `${authAlias.identifier} toggled verification` | ||
case PlayerAuthActivityType.CHANGE_PASSWORD_FAILED: | ||
return `${authAlias.identifier} failed to change their password` | ||
case PlayerAuthActivityType.CHANGE_EMAIL_FAILED: | ||
return `${authAlias.identifier} failed to change their email` | ||
case PlayerAuthActivityType.TOGGLE_VERIFICATION_FAILED: | ||
return `${authAlias.identifier} failed to toggle verification` | ||
default: | ||
return '' | ||
} | ||
} | ||
/* v8 ignore stop */ | ||
|
||
toJSON() { | ||
return { | ||
id: this.id, | ||
type: this.type, | ||
description: this.getActivity(), | ||
extra: this.extra, | ||
createdAt: this.createdAt | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import PlayerAuthActivity from '../../entities/player-auth-activity' | ||
import Player from '../../entities/player' | ||
import { Request } from 'koa-clay' | ||
import { EntityManager } from '@mikro-orm/mysql' | ||
|
||
export default function createPlayerAuthActivity( | ||
req: Request, | ||
player: Player, | ||
data: Pick<Partial<PlayerAuthActivity>, 'type' | 'extra'> | ||
): PlayerAuthActivity { | ||
const em: EntityManager = req.ctx.em | ||
|
||
const activity = new PlayerAuthActivity(player) | ||
activity.type = data.type | ||
activity.extra = { | ||
...(data.extra ?? {}), | ||
userAgent: req.headers['user-agent'], | ||
ip: req.ctx.request.ip | ||
} | ||
|
||
em.persist(activity) | ||
|
||
return activity | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/migrations/20240725183402CreatePlayerAuthActivityTable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Migration } from '@mikro-orm/migrations' | ||
|
||
export class CreatePlayerAuthActivityTable extends Migration { | ||
|
||
async up(): Promise<void> { | ||
this.addSql('create table `player_auth_activity` (`id` int unsigned not null auto_increment primary key, `player_id` varchar(255) not null, `type` tinyint not null, `extra` json not null, `created_at` datetime not null) default character set utf8mb4 engine = InnoDB;') | ||
this.addSql('alter table `player_auth_activity` add index `player_auth_activity_player_id_index`(`player_id`);') | ||
|
||
this.addSql('alter table `player_auth_activity` add constraint `player_auth_activity_player_id_foreign` foreign key (`player_id`) references `player` (`id`) on update cascade;') | ||
} | ||
|
||
async down(): Promise<void> { | ||
this.addSql('drop table if exists `player_auth_activity`;') | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.