tokenservice *should* now commect to api, getting the bonus token

parent 480f522f
......@@ -49,6 +49,7 @@ export enum Project {
}
export enum StorageKey {
CurrentBonusToken = 'CurrentBonusToken',
CurrentQuestionIndex = 'CurrentQuestionIndex', //
PrivateKey = 'PrivateKey', //
LoginToken = 'LoginToken', //
......
import {Component} from '@angular/core';
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
import {BonusTokenService} from '../../../../../service/user/bonus-token/bonus-token.service';
import {AttendeeService} from '../../../../../service/attendee/attendee.service';
@Component({
selector: 'app-bonus-token',
......@@ -12,8 +13,8 @@ export class BonusTokenComponent {
public clipboardText: boolean;
constructor(private activeModal: NgbActiveModal, bonusTokenService: BonusTokenService) {
this.bonusToken = bonusTokenService.getToken();
constructor(private activeModal: NgbActiveModal, bonusTokenService: BonusTokenService, attendeeService: AttendeeService) {
this.bonusToken = attendeeService.bonusToken;
this.clipboardText = true;
}
......
......@@ -10,6 +10,7 @@ import { AttendeeService } from '../../../service/attendee/attendee.service';
import { FooterBarService } from '../../../service/footer-bar/footer-bar.service';
import { QuizService } from '../../../service/quiz/quiz.service';
import { UserService } from '../../../service/user/user.service';
import {BonusTokenService} from 'src/app/service/user/shared/bonus-token.service';
@Component({
selector: 'app-nickname-input',
......@@ -36,6 +37,7 @@ export class NicknameInputComponent implements OnInit, OnDestroy {
private attendeeService: AttendeeService,
private userService: UserService,
private quizService: QuizService, private memberApiService: MemberApiService, private messageQueue: SimpleMQ,
private bonusTokenService: BonusTokenService
) {
this.footerBarService.TYPE_REFERENCE = NicknameInputComponent.TYPE;
......@@ -113,6 +115,13 @@ export class NicknameInputComponent implements OnInit, OnDestroy {
})).subscribe(data => {
if (data.status !== StatusProtocol.Success || data.step !== MessageProtocol.Added) {
reject(data);
} else {
this.bonusTokenService.getBonusToken().subscribe(
nextResult => {
this.attendeeService.bonusToken = nextResult;
},
err => console.error('Observer got an error: ' + err)
);
}
}, (error) => {
reject({
......
......@@ -12,6 +12,7 @@ import { CustomMarkdownService } from '../../../service/custom-markdown/custom-m
import { FooterBarService } from '../../../service/footer-bar/footer-bar.service';
import { QuizService } from '../../../service/quiz/quiz.service';
import { UserService } from '../../../service/user/user.service';
import {BonusTokenService} from '../../../service/user/shared/bonus-token.service';
@Component({
selector: 'app-nickname-select',
......@@ -41,6 +42,7 @@ export class NicknameSelectComponent implements OnInit, OnDestroy {
private memberApiService: MemberApiService,
private messageQueue: SimpleMQ,
private customMarkdownService: CustomMarkdownService,
private bonusTokenService: BonusTokenService
) {
this.footerBarService.TYPE_REFERENCE = NicknameSelectComponent.TYPE;
......@@ -64,7 +66,6 @@ export class NicknameSelectComponent implements OnInit, OnDestroy {
nickname = nickname.toString();
const token = await this.memberApiService.generateMemberToken(nickname, this.quizService.quiz.name).toPromise();
sessionStorage.setItem(StorageKey.QuizToken, token);
this.putMember(nickname).then(() => {
......@@ -127,6 +128,13 @@ export class NicknameSelectComponent implements OnInit, OnDestroy {
})).subscribe((data: IMessage) => {
if (data.status !== StatusProtocol.Success || data.step !== MessageProtocol.Added) {
reject(data);
} else {
this.bonusTokenService.getBonusToken().subscribe(
nextResult => {
this.attendeeService.bonusToken = nextResult;
},
err => console.error('Observer got an error: ' + err)
);
}
}, error => {
reject({
......
......@@ -8,6 +8,7 @@ import { IMemberSerialized } from '../../lib/interfaces/entities/Member/IMemberS
import { MemberApiService } from '../api/member/member-api.service';
import { QuizService } from '../quiz/quiz.service';
import { StorageService } from '../storage/storage.service';
import {BonusTokenService} from '../user/shared/bonus-token.service';
@Injectable({ providedIn: 'root' })
export class AttendeeService {
......@@ -32,11 +33,23 @@ export class AttendeeService {
sessionStorage.setItem(StorageKey.CurrentNickName, value);
}
private _bonusToken: string;
get bonusToken(): string {
return this._bonusToken;
}
set bonusToken(value: string) {
this._bonusToken = value;
sessionStorage.setItem(StorageKey.CurrentBonusToken, value);
}
constructor(
@Inject(PLATFORM_ID) private platformId: Object,
private quizService: QuizService,
private storageService: StorageService,
private memberApiService: MemberApiService,
private bonusTokenService: BonusTokenService
) {
if (isPlatformBrowser(this.platformId)) {
this.loadData();
......@@ -147,6 +160,12 @@ export class AttendeeService {
this._attendees = data.payload.members.map((attendee) => {
return new Attendee(attendee);
});
this.bonusTokenService.getBonusToken().subscribe(
nextResult => {
this.bonusToken = nextResult;
},
err => console.error('Observer got an error: ' + err)
);
resolve();
}, () => reject());
});
......
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {UserService} from '../../user/user.service';
import {DefaultSettings} from '../../../lib/default.settings';
import {Observable} from 'rxjs';
import {StorageKey} from '../../../lib/enums/enums';
@Injectable({
providedIn: 'root'
})
export class BonusTokenService {
constructor(private http: HttpClient, private userService: UserService) {
}
public getBonusToken(): Observable<string> {
return this.http.get<string>(`${DefaultSettings.httpApiEndpoint}/member/bonustoken`, {
headers: {authorization: sessionStorage.getItem(StorageKey.QuizToken)},
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment