Cockatrice/webclient/src/api/AuthenticationService.tsx
Zach H b1ef8220ee
Support Registration on Webatrice with a baseline of handling. (#4436)
* Support Registration on Webatrice with a baseline of handling. Still needs to support activation tokens & unit testing.

* Add support for account activation with token

* Activate Account refactor

* Fix typo

* Add Unit Testing for Commands/Events

* Changes based on review feedback
2021-10-20 21:07:35 -05:00

35 lines
1.1 KiB
TypeScript

import {StatusEnum, User} from "types";
import {SessionCommands, webClient} from "websocket";
import {WebSocketConnectReason, WebSocketOptions} from "../websocket/services/WebSocketService";
export default class AuthenticationService {
static connect(options: WebSocketOptions): void {
SessionCommands.connect(options, WebSocketConnectReason.LOGIN);
}
static register(options: WebSocketOptions): void {
SessionCommands.connect(options, WebSocketConnectReason.REGISTER);
}
static activateAccount(options: WebSocketOptions): void {
SessionCommands.connect(options, WebSocketConnectReason.ACTIVATE_ACCOUNT);
}
static disconnect(): void {
SessionCommands.disconnect();
}
static isConnected(state: number): boolean {
return state === StatusEnum.LOGGEDIN;
}
static isModerator(user: User): boolean {
const moderatorLevel = webClient.protobuf.controller.ServerInfo_User.UserLevelFlag.IsModerator;
// @TODO tell cockatrice not to do this so shittily
return (user.userLevel & moderatorLevel) === moderatorLevel;
}
static isAdmin() {
}
}