Skip to content

Commit

Permalink
add ability to stay logged in through sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
goosewoman committed Aug 7, 2020
1 parent 46dd1f3 commit 197add6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/app/login-screen/login-screen.component.html
Expand Up @@ -11,8 +11,8 @@
#passwordInput aria-describedby="loginHelp" placeholder="Password">
<small id="loginHelp" class="form-text text-muted">Login info isn't sent anywhere but Mojang's servers</small>
<div class="form-check">
<!-- <input type="checkbox" #checkbox class="form-check-input" id="checkbox">-->
<!-- <label class="form-check-label" for="checkbox">Remember login?</label>-->
<input type="checkbox" #checkbox class="form-check-input" id="checkbox">
<label class="form-check-label" for="checkbox">Remember login?</label>
</div>
<button type="button" class="btn btn-primary" id (click)="OnSubmit()">Log In</button>
</form>
Expand Down
118 changes: 55 additions & 63 deletions src/app/login-screen/login-screen.component.ts
Expand Up @@ -13,8 +13,8 @@ export class LoginScreenComponent implements OnInit {

@ViewChild("passwordInput") passwordInput;
@ViewChild("emailInput") emailInput;
// @ViewChild("checkbox") checkbox;
private store: ElectronStore
@ViewChild("checkbox") checkbox;
private store: ElectronStore;
hasError = false;
errorMessage: string;
private submitting = false;
Expand All @@ -27,60 +27,52 @@ export class LoginScreenComponent implements OnInit {
const ElectronStore = require("electron-store");
this.store = new ElectronStore();
this.https = remote.require('https');
// if (this.store.has("clientToken") && this.store.has("accessToken")) {
// this.botContainerService.clientToken = this.store.get("clientToken").toString();
// this.botContainerService.accessToken = this.store.get("accessToken").toString();
// const data = JSON.stringify({
// agent: {
// name: "Minecraft",
// version: 1
// },
// });
//
// const options = {
// hostname: 'authserver.mojang.com',
// port: 443,
// path: '/validate',
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// }
// }
//
// const req = this.https.request(options, (res) => {
// res.on('data', (data) => {
// data = JSON.parse((data.toString()));
//
// const accessToken = data.accessToken;
// const clientToken = data.clientToken;
// this.botContainerService.accessToken = accessToken;
// this.botContainerService.clientToken = clientToken;
// this.botContainerService.selectedProfile = data.selectedProfile;
// this.store.set("clientToken", clientToken);
// if (this.checkbox.nativeElement.checked) {
// this.store.set("accessToken", accessToken);
// this.store.set("username", data.selectedProfile.name);
// this.store.set("userID", data.selectedProfile.id);
// }
// this.ngZone.run(() => {
// this.router.navigate(['/server-list'])
// })
// })
// });
//
//
// req.write(data, (err) => {
// if (err !== undefined) {
// console.info(err);
// }
// });
// req.end()
// this.botContainerService.selectedProfile = {
// name: this.store.get("username").toString(),
// id: this.store.get('userID').toString()
// };
// this.router.navigate(["/server-list"])
// }
if (this.store.has("clientToken") && this.store.has("accessToken")) {
this.botContainerService.clientToken = this.store.get("clientToken").toString();
const data = JSON.stringify({
"accessToken": this.store.get("accessToken").toString(),
"clientToken": this.botContainerService.clientToken
});

const options = {
hostname: 'authserver.mojang.com',
port: 443,
path: '/refresh',
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};

const req = this.https.request(options, (res) => {
res.on('data', (data) => {
data = JSON.parse((data.toString()));
console.log(data);
if (data.accessToken !== undefined) {
console.log(data);
this.botContainerService.accessToken = data.accessToken;
this.store.set("accessToken", data.accessToken);
this.botContainerService.selectedProfile = {
name: this.store.get("username").toString(),
id: this.store.get('userID').toString()
};
this.ngZone.run(() => {
this.router.navigate(['/server-list'])
})
}

})
});


req.write(data, (err) => {
if (err !== undefined) {
console.info(err);
}
});
req.end();

}

}

Expand All @@ -107,7 +99,7 @@ export class LoginScreenComponent implements OnInit {
headers: {
'Content-Type': 'application/json'
}
}
};

const req = this.https.request(options, (res) => {
res.on('data', (data) => {
Expand All @@ -122,12 +114,12 @@ export class LoginScreenComponent implements OnInit {
this.botContainerService.accessToken = accessToken;
this.botContainerService.clientToken = clientToken;
this.botContainerService.selectedProfile = data.selectedProfile;
// if (this.checkbox.nativeElement.checked) {
// this.store.set("accessToken", accessToken);
// this.store.set("clientToken", clientToken);
// this.store.set("username", data.selectedProfile.name);
// this.store.set("userID", data.selectedProfile.id);
// }
if (this.checkbox.nativeElement.checked) {
this.store.set("accessToken", accessToken);
this.store.set("clientToken", clientToken);
this.store.set("username", data.selectedProfile.name);
this.store.set("userID", data.selectedProfile.id);
}
this.ngZone.run(() => {
this.router.navigate(['/server-list'])
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/server-list/server-list.component.ts
Expand Up @@ -103,7 +103,7 @@ export class ServerListComponent implements OnInit {
}

onClickLogoutButton(): void {
this.store.delete("clientToken");
// this.store.delete("clientToken");
this.store.delete("accessToken");
this.store.delete("username");
this.store.delete("userID");
Expand Down

0 comments on commit 197add6

Please sign in to comment.