Esempio n. 1
0
 public static object loginByWechat(string code)
 {
     return(new ThunkAction <AppState>((dispatcher, getState) => {
         return LoginApi.LoginByWechat(code)
         .Then(loginInfo => {
             var user = new User {
                 id = loginInfo.userId,
                 fullName = loginInfo.userFullName,
                 avatar = loginInfo.userAvatar,
                 title = loginInfo.title,
                 coverImage = loginInfo.coverImageWithCDN
             };
             var dict = new Dictionary <string, User> {
                 { user.id, user }
             };
             dispatcher.dispatch(new UserMapAction {
                 userMap = dict
             });
             dispatcher.dispatch(new LoginByWechatSuccessAction {
                 loginInfo = loginInfo
             });
             UserInfoManager.saveUserInfo(loginInfo);
             AnalyticsManager.LoginEvent("wechat");
             AnalyticsManager.AnalyticsLogin("wechat", loginInfo.userId);
             JPushPlugin.setJPushAlias(loginInfo.userId);
         });
     }));
 }
Esempio n. 2
0
 public static object loginByEmail()
 {
     return(new ThunkAction <AppState>((dispatcher, getState) => {
         var email = getState().loginState.email;
         var password = getState().loginState.password;
         return LoginApi.LoginByEmail(email, password)
         .Then(loginInfo => {
             var user = new User {
                 id = loginInfo.userId,
                 fullName = loginInfo.userFullName,
                 avatar = loginInfo.userAvatar,
                 title = loginInfo.title,
                 coverImage = loginInfo.coverImageWithCDN
             };
             var dict = new Dictionary <string, User> {
                 { user.id, user }
             };
             dispatcher.dispatch(new UserMapAction {
                 userMap = dict
             });
             dispatcher.dispatch(new LoginByEmailSuccessAction {
                 loginInfo = loginInfo
             });
             dispatcher.dispatch(new MainNavigatorPopAction());
             dispatcher.dispatch(new CleanEmailAndPasswordAction());
             UserInfoManager.saveUserInfo(loginInfo);
             AnalyticsManager.LoginEvent("email");
             AnalyticsManager.AnalyticsLogin("email", loginInfo.userId);
             JPushPlugin.setJPushAlias(loginInfo.userId);
         });
     }));
 }
Esempio n. 3
0
 public static object loginByWechat(string code)
 {
     return(new ThunkAction <AppState>((dispatcher, getState) => {
         return LoginApi.LoginByWechat(code: code)
         .Then(loginInfo => {
             CustomDialogUtils.hiddenCustomDialog();
             var user = new User {
                 id = loginInfo.userId,
                 fullName = loginInfo.userFullName,
                 avatar = loginInfo.userAvatar,
                 title = loginInfo.title,
                 coverImage = loginInfo.coverImageWithCDN
             };
             var dict = new Dictionary <string, User> {
                 { user.id, user }
             };
             dispatcher.dispatch(new UserMapAction {
                 userMap = dict
             });
             dispatcher.dispatch(new LoginByWechatSuccessAction {
                 loginInfo = loginInfo
             });
             dispatcher.dispatch(fetchChannels(1));
             dispatcher.dispatch(fetchCreateChannelFilter());
             UserInfoManager.saveUserInfo(loginInfo);
             AnalyticsManager.LoginEvent("wechat");
             AnalyticsManager.AnalyticsLogin("wechat", loginInfo.userId);
             JPushPlugin.setJPushAlias(loginInfo.userId);
             if (loginInfo.anonymous)
             {
                 LoginScreen.navigator.pushReplacementNamed(routeName: LoginNavigatorRoutes
                                                            .WechatBindUnity);
             }
             else
             {
                 dispatcher.dispatch(new MainNavigatorPopAction());
                 EventBus.publish(sName: EventBusConstant.login_success,
                                  new List <object> {
                     loginInfo.userId
                 });
             }
         })
         .Catch(error => {
             CustomDialogUtils.hiddenCustomDialog();
             dispatcher.dispatch(new LoginByWechatFailureAction());
         });
     }));
 }
Esempio n. 4
0
 public static object loginByEmail()
 {
     return(new ThunkAction <AppState>((dispatcher, getState) => {
         var email = getState().loginState.email;
         var password = getState().loginState.password;
         return LoginApi.LoginByEmail(email: email, password: password)
         .Then(loginInfo => {
             var user = new User {
                 id = loginInfo.userId,
                 fullName = loginInfo.userFullName,
                 avatar = loginInfo.userAvatar,
                 title = loginInfo.title,
                 coverImage = loginInfo.coverImageWithCDN
             };
             var dict = new Dictionary <string, User> {
                 { user.id, user }
             };
             dispatcher.dispatch(new UserMapAction {
                 userMap = dict
             });
             dispatcher.dispatch(new LoginByEmailSuccessAction {
                 loginInfo = loginInfo
             });
             dispatcher.dispatch(fetchChannels(1));
             dispatcher.dispatch(fetchCreateChannelFilter());
             dispatcher.dispatch <IPromise>(fetchUserProfile(loginInfo.userId));
             dispatcher.dispatch(new CleanEmailAndPasswordAction());
             UserInfoManager.saveUserInfo(loginInfo);
             AnalyticsManager.LoginEvent("email");
             AnalyticsManager.AnalyticsLogin("email", loginInfo.userId);
             JPushPlugin.setJPushAlias(loginInfo.userId);
             BuglyAgent.SetUserId(loginInfo.userId);
             EventBus.publish(sName: EventBusConstant.login_success, new List <object> {
                 loginInfo.userId
             });
             dispatcher.dispatch(new MainNavigatorPopAction());
         })
         .Catch(error => {
             dispatcher.dispatch(new LoginByEmailFailureAction());
             Debuger.LogError(message: error);
             var customSnackBar = new CustomSnackBar(
                 "登录失败,请重试。"
                 );
             customSnackBar.show();
         });
     }));
 }