Example #1
0
        public static void SetupLang(string locale)
        {
            if (locale != null)
            {
                ApplicationLanguages.PrimaryLanguageOverride = locale;
                return;
            }
            if (LocalSettingHelper.HasValue("AppLang") == false)
            {
                var lang = GlobalizationPreferences.Languages[0];
                if (lang.Contains("zh"))
                {
                    ApplicationLanguages.PrimaryLanguageOverride = "zh-CN";
                }
                else
                {
                    ApplicationLanguages.PrimaryLanguageOverride = "en-US";
                }

                LocalSettingHelper.AddValue("AppLang", ApplicationLanguages.PrimaryLanguageOverride);
            }
            else
            {
                ApplicationLanguages.PrimaryLanguageOverride = LocalSettingHelper.GetValue("AppLang");
            }
        }
Example #2
0
        private void GestureControl_OnClickToDismiss(object sender, EventArgs e)
        {
            ToggleGestureTipsControlAnimation(false);

            var key = (string)App.Current.Resources["GestureKey"];

            LocalSettingHelper.AddValue(key, true);
        }
        private async Task <bool> Login()
        {
            try
            {
                var loader = new ResourceLoader();

                IsLoading = Visibility.Visible;

                var check = await PostHelper.CheckExist(TempEmail);

                if (check)
                {
                    string salt = await PostHelper.GetSalt(TempEmail);

                    if (!String.IsNullOrEmpty(salt))
                    {
                        //尝试登录
                        var login = await PostHelper.Login(TempEmail, InputPassword, salt);

                        if (login)
                        {
                            App.isInOfflineMode = false;

                            LocalSettingHelper.AddValue("OfflineMode", "false");
                            return(true);
                        }
                        else
                        {
                            Messenger.Default.Send <GenericMessage <string> >(new GenericMessage <string>(loader.GetString("NotCorrectContent")), "toast");

                            IsLoading = Visibility.Collapsed;
                            return(false);
                        }
                    }
                    else
                    {
                        Messenger.Default.Send <GenericMessage <string> >(new GenericMessage <string>(loader.GetString("NotCorrectContent")), "toast");

                        IsLoading = Visibility.Collapsed;
                        return(false);
                    }
                }
                else
                {
                    Messenger.Default.Send <GenericMessage <string> >(new GenericMessage <string>(loader.GetString("AccountNotExistContent")), "toast");

                    IsLoading = Visibility.Collapsed;
                    return(false);
                }
            }
            catch (Exception e)
            {
                var task = ExceptionHelper.WriteRecord(e);
                return(false);
            }
        }
Example #4
0
        private async Task Login()
        {
            try
            {
                var saltResult = await CloudService.GetSalt(Email, CTSFactory.MakeCTS(100000).Token);

                saltResult.ParseAPIResult();
                if (!saltResult.IsSuccessful)
                {
                    throw new APIException(saltResult.ErrorMsg);
                }
                var saltObj = JsonObject.Parse(saltResult.JsonSrc);
                var salt    = JsonParser.GetStringFromJsonObj(saltObj, "Salt");
                if (string.IsNullOrEmpty(salt))
                {
                    throw new APIException("User does not exist.");
                }

                var newPwd       = MD5.GetMd5String(Password);
                var newPwdInSalt = MD5.GetMd5String(newPwd + salt);
                var loginResult  = await CloudService.Login(Email, newPwdInSalt, CTSFactory.MakeCTS(100000).Token);

                loginResult.ParseAPIResult();
                if (!loginResult.IsSuccessful)
                {
                    throw new APIException(loginResult.ErrorMsg);
                }
                var loginObj    = JsonObject.Parse(loginResult.JsonSrc);
                var userObj     = loginObj["UserInfo"];
                var uid         = JsonParser.GetStringFromJsonObj(userObj, "uid");
                var accessToken = JsonParser.GetStringFromJsonObj(userObj, "access_token");
                if (uid.IsNotNullOrEmpty() && accessToken.IsNotNullOrEmpty())
                {
                    LocalSettingHelper.AddValue("uid", uid);
                    LocalSettingHelper.AddValue("access_token", accessToken);
                    NavigationService.NavigateViaRootFrame(typeof(MainPage));
                }
            }
            catch (TaskCanceledException)
            {
                ToastService.SendToast("Connection time out");
            }
            catch (APIException e)
            {
                ToastService.SendToast(e.ErrorMessage.IsNotNullOrEmpty() ? e.Message : "Fail to login");
            }
            catch (Exception e)
            {
                ToastService.SendToast("Fail to login");
                var task = ExceptionHelper.WriteRecordAsync(e, nameof(LoginViewModel), nameof(Login));
            }
            finally
            {
                ShowLoading = Visibility.Collapsed;
            }
        }
Example #5
0
        private async Task <bool> RegisterAsync()
        {
            try
            {
                //注册
                IsLoading = true;

                var loader = new ResourceLoader();

                var check = await CloudService.CheckEmailExistAsync(TempEmail);

                if (check)
                {
                    throw new MyerListException()
                          {
                              ErrorCode = "202"
                          };
                }
                string salt = await CloudService.RegisterAsync(TempEmail, InputPassword);

                if (!string.IsNullOrEmpty(salt))
                {
                    LocalSettingHelper.AddValue("email", TempEmail);
                    LocalSettingHelper.AddValue("password", InputPassword);
                    return(true);
                }
                else
                {
                    throw new MyerListException()
                          {
                              ErrorCode = ""
                          };
                }
            }
            catch (MyerListException e)
            {
                ToastService.SendToast(ErrorUtils.GetUserMsgFromErrorCode(int.Parse(e.ErrorCode)));
                IsLoading = false;
                return(false);
            }
            catch (TaskCanceledException)
            {
                ToastService.SendToast(ResourcesHelper.GetResString("RequestError"));
                IsLoading = false;
                return(false);
            }
            catch (COMException)
            {
                ToastService.SendToast(ResourcesHelper.GetResString("RequestError"));
                IsLoading = false;
                return(false);
            }
        }
Example #6
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="email">电子邮件</param>
        /// <param name="password">原始密码</param>
        /// <returns>成功返回True</returns>
        public async static Task <bool> Login(string email, string password, string salt)
        {
            try
            {
                var md5 = MD5.Create();
                var ps  = NetworkHelper.GetMd5Hash(md5, password);  //把密码MD5加密,这是数据库存的密码

                var pss = NetworkHelper.GetMd5Hash(md5, ps + salt); //加密后的密码跟盐串联再MD5加密

                var param = new Dictionary <string, string>()
                {
                    { "email", email },
                    { "password", pss },
                };
                Debug.WriteLine(pss);

                HttpClient client   = new HttpClient();
                var        messsage = await client.PostAsync(UserLoginUri, new FormUrlEncodedContent(param));

                if (messsage.IsSuccessStatusCode)
                {
                    var response = await messsage.Content.ReadAsStringAsync();

                    if (String.IsNullOrEmpty(response))
                    {
                        return(false);
                    }
                    JObject job = JObject.Parse(response);
                    if ((bool)job["isSuccessed"])
                    {
                        LocalSettingHelper.AddValue("sid", (string)job["UserInfo"]["sid"]);
                        LocalSettingHelper.AddValue("access_token", (string)job["UserInfo"]["access_token"]);
                        LocalSettingHelper.AddValue("email", email);
                        LocalSettingHelper.AddValue("password", password);

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                var task = ExceptionHelper.WriteRecord(e);
                return(false);
            }
        }
 protected override async void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     if (DeviceHelper.IsDesktop)
     {
         var key = (string)App.Current.Resources["CoachKey"];
         if (!LocalSettingHelper.HasValue(key))
         {
             LocalSettingHelper.AddValue(key, true);
             await PopupService.Instance.ShowAsync(new TipsControl());
         }
     }
 }
Example #8
0
        public void Activate(object param)
        {
            var task = HandleLaunchArg(param as string);

            if (DeviceHelper.IsDesktop)
            {
                if (!LocalSettingHelper.HasValue("TIPS261"))
                {
                    LocalSettingHelper.AddValue("TIPS261", true);
                    var uc    = new TipsControl();
                    var task2 = PopupService.Instance.ShowAsync(uc);
                }
            }
        }
Example #9
0
 private void ChangeLanguage()
 {
     if (CurrentLanguage == 1)
     {
         ApplicationLanguages.PrimaryLanguageOverride = "zh-CN";
         LocalSettingHelper.AddValue("AppLang", "zh-CN");
         var resourceContext = ResourceContext.GetForCurrentView();
         resourceContext.Reset();
     }
     else
     {
         ApplicationLanguages.PrimaryLanguageOverride = "en-US";
         LocalSettingHelper.AddValue("AppLang", "en-US");
         var resourceContext = ResourceContext.GetForCurrentView();
         resourceContext.Reset();
     }
 }
Example #10
0
 private void EnterBtn_Click(object sender, RoutedEventArgs e)
 {
     LocalSettingHelper.AddValue(App.Current.Resources["FeatureToken"] as string, "1");
     if (LocalSettingHelper.HasValue("email"))
     {
         Frame.Navigate(typeof(MainPage), LoginMode.Login);
     }
     else if (LocalSettingHelper.GetValue("OfflineMode") == "true")
     {
         App.IsInOfflineMode = true;
         Frame.Navigate(typeof(MainPage), LoginMode.OfflineMode);
     }
     else
     {
         App.IsInOfflineMode = false;
         Frame.Navigate(typeof(StartPage));
     }
 }
Example #11
0
        private async Task <bool> LoginAsync()
        {
            try
            {
                IsLoading = true;

                var check = await CloudService.CheckEmailExistAsync(TempEmail);

                string salt = await CloudService.GetSaltAsync(TempEmail);

                //尝试登录
                var login = await CloudService.LoginAsync(TempEmail, InputPassword, salt);

                App.IsInOfflineMode = false;
                LocalSettingHelper.AddValue("OfflineMode", "false");
                return(true);
            }
            catch (MyerListException e)
            {
                ToastService.SendToast(ErrorUtils.GetUserMsgFromErrorCode(int.Parse(e.ErrorCode)));
                return(false);
            }
            catch (TaskCanceledException)
            {
                ToastService.SendToast(ResourcesHelper.GetResString("RequestError"));
                return(false);
            }
            catch (COMException)
            {
                ToastService.SendToast(ResourcesHelper.GetResString("RequestError"));
                return(false);
            }
            catch (Exception)
            {
                ToastService.SendToast(ResourcesHelper.GetResString("RequestError"));
                return(false);
            }
            finally
            {
                IsLoading = false;
            }
        }
Example #12
0
        private async Task <bool> Register()
        {
            try
            {
                //注册
                IsLoading = Visibility.Visible;

                var loader = new ResourceLoader();

                var check = await PostHelper.CheckExist(TempEmail);

                if (check)
                {
                    Messenger.Default.Send <GenericMessage <string> >(new GenericMessage <string>(loader.GetString("EmailExistContent")), "toast");

                    IsLoading = Visibility.Collapsed;
                    return(false);
                }
                string salt = await PostHelper.Register(TempEmail, InputPassword);

                if (!String.IsNullOrEmpty(salt))
                {
                    LocalSettingHelper.AddValue("email", TempEmail);
                    LocalSettingHelper.AddValue("password", InputPassword);
                    return(true);
                }
                else
                {
                    Messenger.Default.Send <GenericMessage <string> >(new GenericMessage <string>(loader.GetString("RegisterFailedContent")), "toast");

                    IsLoading = Visibility.Collapsed;
                    return(false);
                }
            }
            catch (Exception e)
            {
                var task = ExceptionHelper.WriteRecord(e);
                return(false);
            }
        }
Example #13
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="email">电子邮件</param>
        /// <param name="password">原始密码</param>
        /// <returns>成功返回True</returns>
        public async static Task <bool> LoginAsync(string email, string password, string salt)
        {
            try
            {
                var ps         = MD5.GetMd5String(password);  //把密码MD5加密,这是数据库存的密码
                var psplussalt = MD5.GetMd5String(ps + salt); //加密后的密码跟盐串联再MD5加密

                var param = GetDefaultParam();
                param.Add(new KeyValuePair <string, string>("email", email));
                param.Add(new KeyValuePair <string, string>("password", psplussalt));

                CancellationTokenSource cts = new CancellationTokenSource(10000);
                var result = await HttpRequestSender.SendPostRequestAsync(UrlHelper.UserLoginUri, param, cts.Token);

                result.ParseResult();
                if (result.IsRequestSuccessful)
                {
                    JsonObject obj     = JsonObject.Parse(result.JsonSrc);
                    var        userObj = JsonParser.GetJsonObjFromJsonObj(obj, "UserInfo");
                    var        sid     = JsonParser.GetStringFromJsonObj(userObj, "sid");
                    var        token   = JsonParser.GetStringFromJsonObj(userObj, "access_token");

                    LocalSettingHelper.AddValue("sid", sid);
                    LocalSettingHelper.AddValue("access_token", token);
                    LocalSettingHelper.AddValue("email", email);
                    LocalSettingHelper.AddValue("password", password);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (OperationCanceledException)
            {
                throw;
            }
        }
Example #14
0
        public static void CheckConfig()
        {
            if (!LocalSettingHelper.HasValue("EnableTile"))
            {
                LocalSettingHelper.AddValue("EnableTile", "true");
            }

            if (!LocalSettingHelper.HasValue("EnableBackgroundTask"))
            {
                LocalSettingHelper.AddValue("EnableBackgroundTask", "true");
            }

            if (!LocalSettingHelper.HasValue("EnableGesture"))
            {
                LocalSettingHelper.AddValue("EnableGesture", "true");
            }

            if (!LocalSettingHelper.HasValue("ShowKeyboard"))
            {
                LocalSettingHelper.AddValue("ShowKeyboard", "true");
            }

            if (!LocalSettingHelper.HasValue("TransparentTile"))
            {
                LocalSettingHelper.AddValue("TransparentTile", "true");
            }

            if (!LocalSettingHelper.HasValue("AddMode"))
            {
                LocalSettingHelper.AddValue("AddMode", "1");
            }

            if (!LocalSettingHelper.HasValue("ThemeColor"))
            {
                LocalSettingHelper.AddValue("ThemeColor", "0");
            }
        }
Example #15
0
 public static void AddAuthInfo()
 {
     LocalSettingHelper.AddValue("uid", "3");
     LocalSettingHelper.AddValue("access_token", "d41d8cd98f00b204e9800998ecf8427e");
 }
Example #16
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            CacheUtilInstance = new CacheUtil();
            await CacheUtilInstance.LoadAsync();

            GlobalLocaleHelper.SetupLang(null);

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame            = new Frame();
                rootFrame.Background = App.Current.Resources["MyerSplashDarkColor"] as SolidColorBrush;

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter

                if (!LocalSettingHelper.HasValue("UPDATED_TO_1.1"))
                {
                    var files1 = await CacheUtil.GetCachedFileFolder().GetItemsAsync();

                    foreach (var file in files1)
                    {
                        await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    }
                    var files2 = await CacheUtil.GetTempFolder().GetItemsAsync();

                    foreach (var file in files2)
                    {
                        await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    }
                    LocalSettingHelper.AddValue("UPDATED_TO_1.1", true);
                }

                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();

            TitleBarHelper.SetUpThemeTitleBar();
            if (DeviceHelper.IsMobile)
            {
                StatusBarHelper.SetUpStatusBar();
            }

            SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
            if (APIInfoHelper.HasHardwareButton)
            {
                HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }
        }
Example #17
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                Window.Current.Content = rootFrame;

                ConfigHelper.CheckConfig();

                if (LocalSettingHelper.HasValue("AppLang") == false)
                {
                    var lang = Windows.System.UserProfile.GlobalizationPreferences.Languages[0];
                    if (lang.Contains("zh"))
                    {
                        ApplicationLanguages.PrimaryLanguageOverride = "zh-CN";
                    }
                    else
                    {
                        ApplicationLanguages.PrimaryLanguageOverride = "en-US";
                    }

                    LocalSettingHelper.AddValue("AppLang", ApplicationLanguages.PrimaryLanguageOverride);
                }
                else
                {
                    ApplicationLanguages.PrimaryLanguageOverride = LocalSettingHelper.GetValue("AppLang");
                }

                if (LocalSettingHelper.HasValue("email"))
                {
                    rootFrame.Navigate(typeof(MainPage), LoginMode.Login);
                }
                else if (LocalSettingHelper.GetValue("OfflineMode") == "true")
                {
                    App.isInOfflineMode = true;
                    rootFrame.Navigate(typeof(MainPage), LoginMode.OfflineMode);
                }
                else
                {
                    App.isInOfflineMode = false;
                    rootFrame.Navigate(typeof(StartPage));
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }