Commit 147d139f authored by nanahira's avatar nanahira

add loginUser thing

parent e4b54a0a
Pipeline #16062 passed with stages
in 6 minutes and 25 seconds
...@@ -13,10 +13,11 @@ export class AuthGuard implements CanActivateChild { ...@@ -13,10 +13,11 @@ export class AuthGuard implements CanActivateChild {
return true; return true;
} }
const token = state.root.queryParamMap.get('sso') || new URL(location.href).searchParams.get('sso') || localStorage.getItem('login'); const tokenFromSSO = state.root.queryParamMap.get('sso') || new URL(location.href).searchParams.get('sso');
const token = tokenFromSSO || localStorage.getItem('login');
if (token) { if (token) {
this.login.callback(token); this.login.callback(token, !!tokenFromSSO);
return true; return true;
} else { } else {
location.replace(this.login.login()); location.replace(this.login.login());
......
...@@ -56,7 +56,7 @@ export class LoginService { ...@@ -56,7 +56,7 @@ export class LoginService {
return url.toString(); return url.toString();
} }
callback(token: string) { callback(token: string, isNewLogin: boolean) {
this.token = token; this.token = token;
this.user = <any>fromPairs(Array.from(new URLSearchParams(Buffer.from(token, 'base64').toString()))); this.user = <any>fromPairs(Array.from(new URLSearchParams(Buffer.from(token, 'base64').toString())));
Raven.setUserContext({ Raven.setUserContext({
...@@ -67,7 +67,11 @@ export class LoginService { ...@@ -67,7 +67,11 @@ export class LoginService {
localStorage.setItem('login', token); localStorage.setItem('login', token);
if (window.ygopro) { if (window.ygopro) {
try { try {
if(isNewLogin && window.ygopro.loginUser) {
window.ygopro.loginUser(this.user, null);
} else {
window.ygopro.updateUser(this.user.username, this.user.avatar_url, this.user.email); window.ygopro.updateUser(this.user.username, this.user.avatar_url, this.user.email);
}
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
......
...@@ -21,6 +21,7 @@ export interface User { ...@@ -21,6 +21,7 @@ export interface User {
moderator: boolean; moderator: boolean;
name: string; name: string;
username: string; username: string;
token: string;
} }
export interface Room { export interface Room {
......
...@@ -16,6 +16,7 @@ interface Window { ...@@ -16,6 +16,7 @@ interface Window {
backHome(): void; backHome(): void;
share(text: string): void share(text: string): void
updateUser(name: string, avatar: string, status: string): void; updateUser(name: string, avatar: string, status: string): void;
loginUser(user: any, exception: any): void;
readFile(path: string): string; readFile(path: string): string;
writeFile(path: string, data: string): string; writeFile(path: string, data: string): string;
......
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