Commit 1ec68850 authored by 神楽坂玲奈's avatar 神楽坂玲奈

fix

parent 89e07722
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
let shadow: ShadowRoot; let shadow: ShadowRoot;
const jQueryOriginal = window['jQuery'];
const jQueryShadow = require('../jquery-shadow.js'); const jQueryShadow = require('../jquery-shadow.js');
jQueryShadow.fn.init = new Proxy(jQueryShadow.fn.init, { jQueryShadow.fn.init = new Proxy(jQueryShadow.fn.init, {
construct(target, argumentsList, newTarget) { construct(target, argumentsList, newTarget) {
...@@ -28,7 +28,7 @@ import {LoginService} from './login.service'; ...@@ -28,7 +28,7 @@ import {LoginService} from './login.service';
import {SettingsService} from './settings.sevices'; import {SettingsService} from './settings.sevices';
import {App} from './app'; import {App} from './app';
import 'node_modules/candy/libs.min.js'; import 'node_modules/candy/libs.min.js';
import 'node_modules/candy/candy.min.js'; import 'node_modules/candy/candy.bundle.js';
import 'node_modules/candy-shop/notifyme/candy.js'; import 'node_modules/candy-shop/notifyme/candy.js';
import 'node_modules/candy-shop/namecomplete/candy.js'; import 'node_modules/candy-shop/namecomplete/candy.js';
import 'node_modules/candy-shop/modify-role/candy.js'; import 'node_modules/candy-shop/modify-role/candy.js';
...@@ -37,10 +37,15 @@ import 'node_modules/candy-shop/notifications/candy.js'; ...@@ -37,10 +37,15 @@ import 'node_modules/candy-shop/notifications/candy.js';
import 'node_modules/candy-shop/refocus/candy.js'; import 'node_modules/candy-shop/refocus/candy.js';
import 'electron-cookies'; import 'electron-cookies';
window['jQuery'] = jQueryOriginal; delete window['jQuery'];
// Candy fix
declare const Candy: any, CandyShop: any, Base64: any; declare const Candy: any, CandyShop: any, Base64: any;
Base64.encode = (data: string) => Buffer.from(data).toString('base64');
Base64.decode = (data: string) => Buffer.from(data, 'base64').toString();
Candy.Util.getPosLeftAccordingToWindowBounds = new Proxy(Candy.Util.getPosLeftAccordingToWindowBounds, { Candy.Util.getPosLeftAccordingToWindowBounds = new Proxy(Candy.Util.getPosLeftAccordingToWindowBounds, {
apply(target, thisArg, argumentsList) { apply(target, thisArg, argumentsList) {
argumentsList[1] -= shadow.host.getBoundingClientRect().left; argumentsList[1] -= shadow.host.getBoundingClientRect().left;
...@@ -54,6 +59,7 @@ Candy.Util.getPosTopAccordingToWindowBounds = new Proxy(Candy.Util.getPosTopAcco ...@@ -54,6 +59,7 @@ Candy.Util.getPosTopAccordingToWindowBounds = new Proxy(Candy.Util.getPosTopAcco
} }
}); });
Candy.Util.setCookie('candy-nostatusmessages', '1', 365);
@Component({ @Component({
moduleId: module.id, moduleId: module.id,
...@@ -91,10 +97,6 @@ export class CandyComponent implements OnInit, OnChanges { ...@@ -91,10 +97,6 @@ export class CandyComponent implements OnInit, OnChanges {
`; `;
shadow.insertBefore(element, shadow.firstChild); shadow.insertBefore(element, shadow.firstChild);
// Candy fix
Base64.encode = (data: string) => Buffer.from(data).toString('base64');
Base64.decode = (data: string) => Buffer.from(data, 'base64').toString();
Candy.View.Template.Login.form = ` Candy.View.Template.Login.form = `
<form method="post" id="login-form" class="login-form"> <form method="post" id="login-form" class="login-form">
<input type="hidden" id="nickname" name="nickname" value="${this.nickname}"/> <input type="hidden" id="nickname" name="nickname" value="${this.nickname}"/>
...@@ -111,8 +113,6 @@ export class CandyComponent implements OnInit, OnChanges { ...@@ -111,8 +113,6 @@ export class CandyComponent implements OnInit, OnChanges {
</form> </form>
`; `;
Candy.Util.setCookie('candy-nostatusmessages', '1', 365);
Candy.init('wss://chat.mycard.moe:5280/websocket', { Candy.init('wss://chat.mycard.moe:5280/websocket', {
core: { core: {
debug: false, debug: false,
...@@ -156,4 +156,10 @@ export class CandyComponent implements OnInit, OnChanges { ...@@ -156,4 +156,10 @@ export class CandyComponent implements OnInit, OnChanges {
} }
} }
// ngOnDestroy () {
// if (Candy.Core.getConnection()) {
// Candy.Core.disconnect();
// }
// }
} }
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {LoginService} from './login.service'; import {LoginService} from './login.service';
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import * as querystring from 'querystring';
import * as url from 'url';
import {shell} from 'electron'; import {shell} from 'electron';
declare const URLSearchParams: any;
@Component({ @Component({
moduleId: module.id, moduleId: module.id,
selector: 'login', selector: 'login',
...@@ -16,36 +17,52 @@ import {shell} from 'electron'; ...@@ -16,36 +17,52 @@ import {shell} from 'electron';
}) })
export class LoginComponent { export class LoginComponent {
url: string; url: string;
return_sso_url = 'https://mycard.moe/login_callback'; // 这个url不会真的被使用,可以填写不存在的 readonly return_sso_url = 'https://mycard.moe/login_callback'; // 这个url不会真的被使用,可以填写不存在的
constructor (private loginService: LoginService) { constructor (private loginService: LoginService) {
let payload = new Buffer(querystring.stringify({ let params = new URLSearchParams();
// nonce: nonce, params.set('return_sso_url', this.return_sso_url);
return_sso_url: this.return_sso_url let payload = Buffer.from(params.toString()).toString('base64');
})).toString('base64');
let url = new URL('https://ygobbs.com/session/sso_provider');
params = url['searchParams'];
params.set('sso', payload);
params.set('sig', crypto.createHmac('sha256', 'zsZv6LXHDwwtUAGa').update(payload).digest('hex'));
let request = querystring.stringify({ this.url = url.toString();
'sso': payload,
'sig': crypto.createHmac('sha256', 'zsZv6LXHDwwtUAGa').update(payload).digest('hex')
});
this.url = 'https://ygobbs.com/session/sso_provider?' + request;
if (this.loginService.logging_out) { if (this.loginService.logging_out) {
this.url = 'https://ygobbs.com/logout?' + querystring.stringify({'redirect': this.url}); url = new URL('https://ygobbs.com/logout');
params = url['searchParams'];
// params.set('redirect', this.url);
// 暂时 hack 一下登出,因为聊天室现在没办法重新初始化,于是登出后刷新页面。
params.set('redirect', 'https://mycard.moe/logout_callback');
this.url = url.toString()
} }
} }
return_sso (return_url: string) { return_sso (return_url: string) {
if (return_url === 'https://mycard.moe/logout_callback') {
return location.reload()
}
if (!return_url.startsWith(this.return_sso_url)) { if (!return_url.startsWith(this.return_sso_url)) {
return; return;
} }
let token = querystring.parse(url.parse(return_url).query).sso; let token = new URL(return_url)['searchParams'].get('sso');
let user = querystring.parse(new Buffer(token, 'base64').toString()); let user = this.toObject(new URLSearchParams(Buffer.from(token, 'base64').toString()));
this.loginService.login(user); this.loginService.login(user);
} }
toObject (entries: Iterable<[string, any]>): any {
let result = {};
for (let [key, value] of entries) {
result[key] = value;
}
return result;
}
openExternal (url: string) { openExternal (url: string) {
shell.openExternal(url); shell.openExternal(url);
} }
......
window['jQuery'] = require('jquery');
window['Tether'] = require('tether');
import 'node_modules/bootstrap/dist/js/bootstrap.min.js';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {getTranslationProviders} from './i18n-providers'; import {getTranslationProviders} from './i18n-providers';
import {MyCard} from './mycard.module'; import {MyCard} from './mycard.module';
......
...@@ -3,6 +3,8 @@ import {remote, shell} from 'electron'; ...@@ -3,6 +3,8 @@ import {remote, shell} from 'electron';
import {LoginService} from './login.service'; import {LoginService} from './login.service';
import {SettingsService} from './settings.sevices'; import {SettingsService} from './settings.sevices';
import * as $ from 'jquery'; import * as $ from 'jquery';
import 'bootstrap';
const autoUpdater: Electron.AutoUpdater = remote.getGlobal('autoUpdater'); const autoUpdater: Electron.AutoUpdater = remote.getGlobal('autoUpdater');
@Component({ @Component({
......
...@@ -75,9 +75,9 @@ System.config({ ...@@ -75,9 +75,9 @@ System.config({
"electron-sudo": "@node/electron-sudo", "electron-sudo": "@node/electron-sudo",
"electron-cookies": "@node/electron-cookies", "electron-cookies": "@node/electron-cookies",
'jquery': '@node/jquery', 'jquery': 'npm:jquery/dist/jquery.min.js',
'tether': '@node/tether', 'tether': 'npm:tether/dist/js/tether.min.js',
'bootstrap': '@node/bootstrap', 'bootstrap': 'npm:bootstrap/dist/js/bootstrap.min.js',
'typeahead.js': '@node/typeahead.js' 'typeahead.js': '@node/typeahead.js'
}, },
// packages tells the System loader how to load when no filename and/or no extension // packages tells the System loader how to load when no filename and/or no extension
...@@ -89,5 +89,13 @@ System.config({ ...@@ -89,5 +89,13 @@ System.config({
rxjs: { rxjs: {
defaultExtension: 'js' defaultExtension: 'js'
} }
},
meta: {
bootstrap: {
globals: {
jQuery: 'jquery',
Tether: 'tether'
}
}
} }
}); });
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