Merge pull request #114 from ryanesch/googleusername

For Google Auth, add register username panel
This commit is contained in:
ryanesch 2018-05-22 16:24:52 -05:00 committed by GitHub
commit a79b50ee55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -33,7 +33,7 @@
<input type="text" id="username" name="username" [(ngModel)]="username" /> <input type="text" id="username" name="username" [(ngModel)]="username" />
</div> </div>
<div class="form-item"> <div class="form-item">
<button type="button" (click)="loginAsGuest(username)">Sign In As Guest</button> <button type="button" id="signin" (click)="loginAsGuest(username)">Sign In As Guest</button>
</div> </div>
<div class="form-item"> <div class="form-item">
<button type="button" (click)="cancelLogin()">Cancel</button> <button type="button" (click)="cancelLogin()">Cancel</button>

View File

@ -162,6 +162,7 @@ export class LoginComponent implements OnInit, OnDestroy {
showGuestLogin() { showGuestLogin() {
this.pane = 'center'; this.pane = 'center';
document.getElementById("signin").innerHTML="Sign In As Guest";
} }
setQueueOnMessage() { setQueueOnMessage() {
@ -208,7 +209,7 @@ export class LoginComponent implements OnInit, OnDestroy {
} }
async loginAsGuest(username: string) { async loginAsGuest(username: string) {
if (await this.createUser(username, null)) if (await this.createUser(username, sessionStorage.getItem('userId')))
this.pane = 'right'; this.pane = 'right';
} }
@ -218,16 +219,14 @@ export class LoginComponent implements OnInit, OnDestroy {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': 'Bearer ' + `${jwt}` 'Authorization': 'Bearer ' + `${jwt}`
}) }).toPromise(); }) }).toPromise();
sessionStorage.setItem('userId', user.id);
if (user.exists === 'true') { if (user.exists === 'true') {
sessionStorage.setItem('username', user.username); sessionStorage.setItem('username', user.username);
sessionStorage.setItem('userId', user.id);
this.player.name = user.username; this.player.name = user.username;
this.pane = 'right'; this.pane = 'right';
} else { } else {
var username = prompt("Choose a username:", ""); this.pane = 'center';
if (await this.createUser(username, user.id)) { document.getElementById("signin").innerHTML="register username";
this.pane = 'right';
}
} }
} }
@ -272,6 +271,8 @@ export class LoginComponent implements OnInit, OnDestroy {
} }
cancelLogin() { cancelLogin() {
sessionStorage.removeItem('username');
sessionStorage.removeItem('userId');
this.pane = 'left'; this.pane = 'left';
} }
} }