| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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.isCancel) return false;
- const token = res.accessToken || res.authenticationToken;
- if (token) {
- return await this.login3rd('facebook', token);
- }
- // if (res.authenticationToken) {
- // // The current backend accepts Access Tokens only. Do not send an OIDC JWT
- // // through that endpoint or report a game login success without a session.
- // AppKernel.ui.toast('Facebook 授权已完成,但服务器尚未支持此 iOS 登录方式,请暂时使用其他登录方式。');
- // return false;
- // }
- AppKernel.ui.toast(res.reason || 'Facebook 未返回可用的 Access Token,请使用其他登录方式。');
- return false;
- }
- 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();
|