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

fix

parent 89e07722
......@@ -3,7 +3,7 @@
*/
let shadow: ShadowRoot;
const jQueryOriginal = window['jQuery'];
const jQueryShadow = require('../jquery-shadow.js');
jQueryShadow.fn.init = new Proxy(jQueryShadow.fn.init, {
construct(target, argumentsList, newTarget) {
......@@ -28,7 +28,7 @@ import {LoginService} from './login.service';
import {SettingsService} from './settings.sevices';
import {App} from './app';
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/namecomplete/candy.js';
import 'node_modules/candy-shop/modify-role/candy.js';
......@@ -37,10 +37,15 @@ import 'node_modules/candy-shop/notifications/candy.js';
import 'node_modules/candy-shop/refocus/candy.js';
import 'electron-cookies';
window['jQuery'] = jQueryOriginal;
delete window['jQuery'];
// Candy fix
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, {
apply(target, thisArg, argumentsList) {
argumentsList[1] -= shadow.host.getBoundingClientRect().left;
......@@ -54,6 +59,7 @@ Candy.Util.getPosTopAccordingToWindowBounds = new Proxy(Candy.Util.getPosTopAcco
}
});
Candy.Util.setCookie('candy-nostatusmessages', '1', 365);
@Component({
moduleId: module.id,
......@@ -91,10 +97,6 @@ export class CandyComponent implements OnInit, OnChanges {
`;
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 = `
<form method="post" id="login-form" class="login-form">
<input type="hidden" id="nickname" name="nickname" value="${this.nickname}"/>
......@@ -111,8 +113,6 @@ export class CandyComponent implements OnInit, OnChanges {
</form>
`;
Candy.Util.setCookie('candy-nostatusmessages', '1', 365);
Candy.init('wss://chat.mycard.moe:5280/websocket', {
core: {
debug: false,
......@@ -156,4 +156,10 @@ export class CandyComponent implements OnInit, OnChanges {
}
}
// ngOnDestroy () {
// if (Candy.Core.getConnection()) {
// Candy.Core.disconnect();
// }
// }
}
......@@ -4,10 +4,11 @@
import {Component} from '@angular/core';
import {LoginService} from './login.service';
import * as crypto from 'crypto';
import * as querystring from 'querystring';
import * as url from 'url';
import {shell} from 'electron';
declare const URLSearchParams: any;
@Component({
moduleId: module.id,
selector: 'login',
......@@ -16,36 +17,52 @@ import {shell} from 'electron';
})
export class LoginComponent {
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) {
let payload = new Buffer(querystring.stringify({
// nonce: nonce,
return_sso_url: this.return_sso_url
})).toString('base64');
let params = new URLSearchParams();
params.set('return_sso_url', this.return_sso_url);
let payload = Buffer.from(params.toString()).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({
'sso': payload,
'sig': crypto.createHmac('sha256', 'zsZv6LXHDwwtUAGa').update(payload).digest('hex')
});
this.url = 'https://ygobbs.com/session/sso_provider?' + request;
this.url = url.toString();
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) {
if (return_url === 'https://mycard.moe/logout_callback') {
return location.reload()
}
if (!return_url.startsWith(this.return_sso_url)) {
return;
}
let token = querystring.parse(url.parse(return_url).query).sso;
let user = querystring.parse(new Buffer(token, 'base64').toString());
let token = new URL(return_url)['searchParams'].get('sso');
let user = this.toObject(new URLSearchParams(Buffer.from(token, 'base64').toString()));
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) {
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 {getTranslationProviders} from './i18n-providers';
import {MyCard} from './mycard.module';
......
......@@ -3,6 +3,8 @@ import {remote, shell} from 'electron';
import {LoginService} from './login.service';
import {SettingsService} from './settings.sevices';
import * as $ from 'jquery';
import 'bootstrap';
const autoUpdater: Electron.AutoUpdater = remote.getGlobal('autoUpdater');
@Component({
......
......@@ -75,9 +75,9 @@ System.config({
"electron-sudo": "@node/electron-sudo",
"electron-cookies": "@node/electron-cookies",
'jquery': '@node/jquery',
'tether': '@node/tether',
'bootstrap': '@node/bootstrap',
'jquery': 'npm:jquery/dist/jquery.min.js',
'tether': 'npm:tether/dist/js/tether.min.js',
'bootstrap': 'npm:bootstrap/dist/js/bootstrap.min.js',
'typeahead.js': '@node/typeahead.js'
},
// packages tells the System loader how to load when no filename and/or no extension
......@@ -89,5 +89,13 @@ System.config({
rxjs: {
defaultExtension: 'js'
}
},
meta: {
bootstrap: {
globals: {
jQuery: 'jquery',
Tether: 'tether'
}
}
}
});
\ No newline at end of file
});
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