示例#1
0
        /// <summary>
        /// Attempts to login using information from properties.
        /// </summary>
        public async void AttemptLogin()
        {
            DisplayLoginWindow = false;
            DisplayLoading     = true;
            OnPropertyChanged(nameof(DisplayLoginWindow));
            OnPropertyChanged(nameof(DisplayLoading));
            string passwordSalt = await APIHandler <string> .GetOne($"Auth/GetSalt/{Username}");

            if (passwordSalt != null)
            {
                (int UserID, string SessionKey)sessionTuple =
                    await APIHandler <(int UserID, string SessionKey)> .GetOne($"Auth/Login/{Username}/{AuthHandler.EncryptPassword(Password, passwordSalt)}");

                if (sessionTuple != default)
                {
                    AuthHandler.UserID     = sessionTuple.UserID;
                    AuthHandler.SessionKey = sessionTuple.SessionKey;
                    await AuthHandler.InitializeAuth();

                    Frame mainFrame = Window.Current.Content as Frame;
                    mainFrame?.Navigate(Type.GetType($"{Application.Current.GetType().Namespace}.MainPage"));
                }
                else
                {
                    DisplayLoginError(Constants.LOGIN_ERROR);
                }
            }
            else
            {
                DisplayLoginError(Constants.LOGIN_ERROR);
            }
        }