LoginService.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Login3rdType, APP_LOGIN_TYPE } from "@scripts/define/Define";
  2. import { AppKernel } from "../../app/AppKernel";
  3. import { IGoogleLoginRes } from "@scripts/platform/Google/GoogleImpl";
  4. import { checkResponse, getHttpMsg } from "@scripts/api/ApiHelper";
  5. class LoginService {
  6. async guestLogin() {
  7. const mainStore = AppKernel.stores.mainStore;
  8. const res = await mainStore.reqLogin({ type: APP_LOGIN_TYPE.GUEST });
  9. if (checkResponse(res)) {
  10. await AppKernel.appLobby.onLoginSuccess();
  11. return true;
  12. }
  13. return false;
  14. }
  15. async fbLogin() {
  16. const res = await AppKernel.fb.login();
  17. if (res.accessToken) {
  18. await this.login3rd('facebook', res.accessToken);
  19. }
  20. console.log("facebook login res: ", res);
  21. }
  22. async googleLogin(res?: IGoogleLoginRes) {
  23. if (!res) {
  24. /// h5 通过dom按钮触发登录
  25. res = await AppKernel.google.login();
  26. }
  27. if (res && res.accessToken) {
  28. await this.login3rd('google', res.accessToken);
  29. }
  30. return true;
  31. }
  32. async login3rd(type: Login3rdType, token: string) {
  33. const mainStore = AppKernel.stores.mainStore;
  34. const res = await mainStore.reqLogin3rd(type, token);
  35. if (checkResponse(res)) {
  36. await AppKernel.appLobby.onLoginSuccess();
  37. return true;
  38. }
  39. return false;
  40. }
  41. async loginAccount(account: string, password: string) {
  42. const mainStore = AppKernel.stores.mainStore;
  43. const res = await mainStore.reqLogin({
  44. type: APP_LOGIN_TYPE.ID,
  45. password,
  46. account,
  47. })
  48. if (checkResponse(res)) {
  49. // await AppKernel.appLobby.onLoginSuccess();
  50. return true;
  51. }
  52. return false;
  53. }
  54. async logOut() {
  55. }
  56. async register({ account, code, password, act }) {
  57. const mainStore = AppKernel.stores.mainStore;
  58. const res = await mainStore.reqRegister({ account, code, password, act })
  59. return checkResponse(res);
  60. }
  61. }
  62. export const loginService = new LoginService();