import { Login3rdType, APP_LOGIN_TYPE } from "@scripts/define/Define"; import { AppKernel } from "../../app/AppKernel"; import { IGoogleLoginRes } from "@scripts/platform/Google/GoogleImpl"; import { checkResponse, getHttpMsg } from "@scripts/api/ApiHelper"; class LoginService { async guestLogin() { const mainStore = AppKernel.stores.mainStore; const res = await mainStore.reqLogin({ type: APP_LOGIN_TYPE.GUEST }); if (checkResponse(res)) { await AppKernel.appLobby.onLoginSuccess(); return true; } return false; } async fbLogin() { const res = await AppKernel.fb.login(); if (res.accessToken) { await this.login3rd('facebook', res.accessToken); } console.log("facebook login res: ", res); } async googleLogin(res?: IGoogleLoginRes) { if (!res) { /// h5 通过dom按钮触发登录 res = await AppKernel.google.login(); } if (res && res.accessToken) { await this.login3rd('google', res.accessToken); } return true; } async login3rd(type: Login3rdType, token: string) { const mainStore = AppKernel.stores.mainStore; const res = await mainStore.reqLogin3rd(type, token); if (checkResponse(res)) { await AppKernel.appLobby.onLoginSuccess(); return true; } return false; } async loginAccount(account: string, password: string) { const mainStore = AppKernel.stores.mainStore; const res = await mainStore.reqLogin({ type: APP_LOGIN_TYPE.ID, password, account, }) if (checkResponse(res)) { // await AppKernel.appLobby.onLoginSuccess(); return true; } return false; } async logOut() { } async register({ account, code, password, act }) { const mainStore = AppKernel.stores.mainStore; const res = await mainStore.reqRegister({ account, code, password, act }) return checkResponse(res); } } export const loginService = new LoginService();