| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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;
- if (res.accessToken) {
- return await this.login3rd('facebook', res.accessToken);
- }
- 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();
|