6 changed files with 217 additions and 7 deletions
@ -0,0 +1,13 @@ |
|||||
|
export class DiscordAccount { |
||||
|
accent_color!: number; |
||||
|
avatar!: string|null; |
||||
|
global_name!: string; |
||||
|
id!: string; |
||||
|
username!: string; |
||||
|
|
||||
|
static fromData(data:any):DiscordAccount { |
||||
|
let d = new DiscordAccount(); |
||||
|
Object.assign(d, data); |
||||
|
return d; |
||||
|
} |
||||
|
} |
@ -0,0 +1,151 @@ |
|||||
|
import {AfterViewInit, Component, Input} from "@angular/core"; |
||||
|
import {AuthService} from "../../../services/auth.service"; |
||||
|
import {ActionService} from "../../../services/action.service"; |
||||
|
import {MatStepper} from "@angular/material/stepper"; |
||||
|
import {DiscordAccount} from "../../../entities/DiscordAccount"; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'app-discord-connect-dialog', |
||||
|
template: ` |
||||
|
<h1 mat-dialog-title style="color: black">Получение доступа к нашему серверу дискорда</h1> |
||||
|
<mat-dialog-content> |
||||
|
<app-need-auth-to-continue *ngIf="!authService.isAuth()"></app-need-auth-to-continue> |
||||
|
<div *ngIf="authService.isAuth()"> |
||||
|
<mat-stepper orientation="vertical" [linear]="true" #stepper> |
||||
|
|
||||
|
<mat-step> |
||||
|
<ng-template matStepLabel>Привязка к Steam</ng-template> |
||||
|
<ng-template matStepContent> |
||||
|
<div *ngIf="currentDiscordId==''"> |
||||
|
<p>Проверка наличия привязки...</p> |
||||
|
</div> |
||||
|
<div *ngIf="currentDiscordId=='not_exists'"> |
||||
|
<p>Твой аккаунт стима не привязан, можно приступить к следующему шагу</p> |
||||
|
<button mat-button matStepperNext>Далее</button> |
||||
|
</div> |
||||
|
<div *ngIf="currentDiscordId!='not_exists' && currentDiscordId!=''"> |
||||
|
<p>У тебя на аккаунте уже есть привязанный дискорд, если хочешь его отвязать или потерял доступ, то жми скорее далее</p> |
||||
|
<button mat-button matStepperNext>Далее</button> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-step> |
||||
|
|
||||
|
<mat-step *ngIf="currentDiscordId!=''"> |
||||
|
<ng-template matStepLabel>Привязка к Discord</ng-template> |
||||
|
<ng-template matStepContent> |
||||
|
<div *ngIf="currentDiscordId=='not_exists'"> |
||||
|
<p>Твой аккаунт стима не привязан, можно приступить к следующему шагу</p> |
||||
|
<button mat-button matStepperNext>Далее</button> |
||||
|
</div> |
||||
|
<div *ngIf="currentDiscordId!='not_exists' && currentDiscordId!=''"> |
||||
|
<p>Удалить твой текущую связку?</p> |
||||
|
<p *ngIf="removeDiscordId == -1" style="color: red">Во время удаления связки аккаунтов произошла ошибка. Напиши админам в дискорде. Возможно ты еблан или мы.</p> |
||||
|
<button mat-button (click)="removeCurrentDiscordId()">Удалить</button> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-step> |
||||
|
|
||||
|
<mat-step *ngIf="currentDiscordId!='' && currentDiscordId=='not_exists'"> |
||||
|
<ng-template matStepLabel>Авторизация в дискорд</ng-template> |
||||
|
<ng-template matStepContent> |
||||
|
<div *ngIf="currentDiscordData == null"> |
||||
|
<div *ngIf="currentDiscordDataStatus == 401"> |
||||
|
<p>Нужно авторизоваться в дискорде для получения твоего уникального индификатора. Авторизуйся затем вернись в это окно так-же как и пришел!</p> |
||||
|
<button mat-button (click)="authService.discordLogin()">Авторизоваться</button> |
||||
|
</div> |
||||
|
<div *ngIf="currentDiscordDataStatus != 200 && currentDiscordDataStatus != 401"> |
||||
|
<p>Сервер не может соединиться с дискордом для верификации данных, попробуй сделать это позже</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div *ngIf="currentDiscordData != null && currentDiscordId=='not_exists'"> |
||||
|
<p>Аккаунт стим {{authService.steamdata?.nickname}} будет привязан к аккаунту дискорд {{currentDiscordData.username}}</p> |
||||
|
<div [ngSwitch]="registerDiscordStatus" *ngIf="registerDiscordStatus!=null"> |
||||
|
<p *ngSwitchCase="200" style="color: green">Аккаунты связаны, теперь можешь смотреть наш сервер дискорда</p> |
||||
|
<p *ngSwitchCase="413" style="color: red">Найден иной неотвязанный от текущего дискорда профиль стима. Если ты терял доступ к аккаунту то напиши админам в дискорде, мы отвяжем старые аккаунты.</p> |
||||
|
<p *ngSwitchCase="409" style="color: red">Найден иной неотвязанный от текущего профиля стима дискорд. Если ты терял доступ к аккаунту то напиши админам в дискорде, мы отвяжем старые аккаунты.</p> |
||||
|
<p *ngSwitchDefault style="color: red">Ошибка сервера. Напиши админам в дискорде.</p> |
||||
|
</div> |
||||
|
|
||||
|
<button mat-button (click)="registerCurrentDiscordUser()">Привязать</button> |
||||
|
</div> |
||||
|
<div *ngIf="currentDiscordData != null && currentDiscordId!='not_exists'"> |
||||
|
<p>Сначала нужно удалить текущию связку на предыдущем шаге</p> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-step> |
||||
|
</mat-stepper> |
||||
|
</div> |
||||
|
</mat-dialog-content> |
||||
|
<mat-dialog-actions> |
||||
|
|
||||
|
</mat-dialog-actions> |
||||
|
` |
||||
|
}) |
||||
|
export class DiscordConnectDialog implements AfterViewInit { |
||||
|
currentDiscordId: string|''|'not_exists' = ''; |
||||
|
removeDiscordId: number|null = null; //1 удален 0 неудален -1 ошибка нулл не проверяли
|
||||
|
stage: 'init' = 'init'; |
||||
|
@Input('stepper') |
||||
|
stepper!: MatStepper; |
||||
|
currentDiscordData!: DiscordAccount|null; |
||||
|
currentDiscordDataStatus!: number|null; |
||||
|
//200/201 - успешно
|
||||
|
//413 - найден иной не отвязанный стим с тем который хотят привязать
|
||||
|
//409 - найден иной не отвязанный дискорд с тем который хотят привязать
|
||||
|
registerDiscordStatus!: number|null; |
||||
|
|
||||
|
constructor(public authService: AuthService, public actionService: ActionService) {} |
||||
|
|
||||
|
ngAfterViewInit(): void { |
||||
|
this.fillCurrentDiscordId(); |
||||
|
this.getCurrentDiscordData(); |
||||
|
} |
||||
|
|
||||
|
fillCurrentDiscordId() { |
||||
|
this.currentDiscordId = ''; |
||||
|
this.authService.getCurrentUserDiscord().subscribe( |
||||
|
(id) => {this.currentDiscordId = id;}, |
||||
|
(err) => this.currentDiscordId = "not_exists" |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
removeCurrentDiscordId() { |
||||
|
this.removeDiscordId = this.removeDiscordId!=-1?null:this.removeDiscordId; |
||||
|
this.authService.removeCurrentUserDiscord().subscribe( |
||||
|
(res) => { |
||||
|
this.removeDiscordId = res?1:0; |
||||
|
this.actionService.showSnack("Аккаунт дискорда был отвязан"); |
||||
|
this.fillCurrentDiscordId(); |
||||
|
this.stepper.previous(); |
||||
|
}, |
||||
|
(err) => { |
||||
|
this.removeDiscordId = -1; |
||||
|
this.actionService.showSnack("Произошла ошибка во время удаления аккаунта"); |
||||
|
} |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
getCurrentDiscordData() { |
||||
|
this.authService.getCurrentUserDiscordData().subscribe( |
||||
|
(res) => { |
||||
|
this.currentDiscordData = res; |
||||
|
this.currentDiscordDataStatus = 200; |
||||
|
console.log(res); |
||||
|
}, (err) => { |
||||
|
this.currentDiscordDataStatus = err.status; |
||||
|
console.log(err); |
||||
|
} |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
registerCurrentDiscordUser() { |
||||
|
this.authService.registerCurrentDiscordData().subscribe( |
||||
|
(res) => { |
||||
|
this.registerDiscordStatus = 200; |
||||
|
}, |
||||
|
(err) => { |
||||
|
this.registerDiscordStatus = err.status; |
||||
|
} |
||||
|
) |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue