예제 #1
0
        //performs login and navigates to startpage if successfull
        private async void login()
        {
            string userMail = ApplicationData.Current.LocalSettings.Values["userMail"].ToString();

            if (ApplicationData.Current.LocalSettings.Values.ContainsKey("password"))
            {
                string password = ApplicationData.Current.LocalSettings.Values["password"].ToString();
                (App.Current as App).Server = new ServerCommunication(userMail, password);
                try
                {
                    SamServerResponse response = await(App.Current as App).Server.Signin();
                    if (response.successfull)
                    {
                        (App.Current as App)._loggedIn  = true;
                        _accountSettingButton.Content   = "Anmeldung verwalten";
                        _accountSettingButton.IsEnabled = true;
                        Frame.Navigate(typeof(StartPage));
                    }
                    else
                    {
                        ShowGenericOkDialog(response.ErrorMessage);
                        Frame.Navigate(typeof(AccountConfiguration));
                    }
                }
                catch (Exception)
                {
                    ShowGenericOkDialog("Ein unbekannter Fehler ist aufgetreten.");
                }
            }
        }
예제 #2
0
        public async Task <SamServerResponse> submitPoints()
        {
            // int transmittedInByte;
            SamServerResponse response = await(App.Current as App).Server.TransmitTrip(_points, _tag);

            _points.Clear();
            return(response);
        }
        //changes password of active user-account
        private async void _changePasswordButton_Click(object sender, RoutedEventArgs e)
        {
            _newUsernameBox.Visibility = Visibility.Collapsed;
            if (_newPassword.Visibility == Visibility.Collapsed)
            {
                //show input dialogs
                _newPassword.Password    = "";
                _newPassword2.Password   = "";
                _newPassword.Visibility  = Visibility.Visible;
                _newPassword2.Visibility = Visibility.Visible;
            }
            else
            {
                if (_newPassword2.Password != _newPassword.Password)
                {
                    var emailErrorDialog = new MessageDialog("Passwörter müssen übereinstimmen");
                    emailErrorDialog.Commands.Add(new UICommand("ok"));
                    await emailErrorDialog.ShowAsync();

                    return;
                }
                else if (_newPassword.Password == "")
                {
                    _newPassword.Visibility  = Visibility.Collapsed;
                    _newPassword2.Visibility = Visibility.Collapsed;
                    return;
                }
                //change password
                String            password       = _newPassword.Password;
                SamServerResponse changeResponse = await(App.Current as App).Server.ChangePassword(password);
                if (changeResponse.successfull)
                {
                    String mail = ApplicationData.Current.LocalSettings.Values["userMail"].ToString();
                    (App.Current as App).Server = new ServerCommunication(mail, password);
                    SamServerResponse signinResponse = await(App.Current as App).Server.Signin();
                    if (signinResponse.successfull)
                    {
                        ApplicationData.Current.LocalSettings.Values["password"] = password;
                        ShowGenericOkDialog("Das Passwort wurde erfolgreich geändert. Sie sind jetzt mit dem neuen Passwort eingeloggt.");
                    }
                    else
                    {
                        ShowGenericOkDialog(signinResponse.ErrorMessage);
                    }
                }
                else
                {
                    ShowGenericOkDialog(changeResponse.ErrorMessage);
                }

                _newPassword.Visibility  = Visibility.Collapsed;
                _newPassword2.Visibility = Visibility.Collapsed;
            }
        }
        //changes user-name of active-account
        private async void _changeUsernameButton_Click(object sender, RoutedEventArgs e)
        {
            _newPassword.Visibility  = Visibility.Collapsed;
            _newPassword2.Visibility = Visibility.Collapsed;
            if (_newUsernameBox.Visibility == Visibility.Collapsed)
            {
                _newUsernameBox.Visibility = Visibility.Visible;
            }
            else
            {
                String mail = _newUsernameBox.Text;
                if (mail == "")
                {
                    _newUsernameBox.Visibility = Visibility.Collapsed;
                    return;
                }
                else
                {
                    Match mailValidation = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Match(mail);
                    if (!mailValidation.Success)
                    {
                        ShowGenericOkDialog("Bitte gültige E-Mail Adresse eingeben");
                        return;
                    }

                    //change request
                    try
                    {
                        SamServerResponse response = await(App.Current as App).Server.ChangeUsername(mail);
                        if (response.successfull)
                        {
                            String password = ApplicationData.Current.LocalSettings.Values["password"].ToString();
                            (App.Current as App).Server = new ServerCommunication(mail, password);
                            SamServerResponse signinResponse = await(App.Current as App).Server.Signin();
                            if (signinResponse.successfull)
                            {
                                ApplicationData.Current.LocalSettings.Values["userMail"] = mail;
                                ShowGenericOkDialog("Der Nutzername wurde erfolgreich geändert. Sie sind jetzt mit dem neuen Nutzernamen eingeloggt.");
                                _newUsernameBox.Visibility = Visibility.Collapsed;
                                _accountMailPanel.Text     = ApplicationData.Current.LocalSettings.Values["userMail"].ToString();
                            }
                            else
                            {
                                ShowGenericOkDialog(signinResponse.ErrorMessage);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        ShowGenericOkDialog("Ein unbekannter Fehler ist aufgetreten");
                    }
                }
            }
        }
        //creates a new user-account
        private async void _createButton_Click(object sender, RoutedEventArgs e)
        {
            String mail           = _createUserMailBox.Text;
            Match  mailValidation = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Match(mail);

            if (!mailValidation.Success)
            {
                var emailErrorDialog = new MessageDialog("Bitte gültige E-Mail Adresse eingeben");
                emailErrorDialog.Commands.Add(new UICommand("ok"));
                await emailErrorDialog.ShowAsync();

                return;
            }

            if (_createPasswordTextBox.Password != _passwordVerifyBox.Password)
            {
                ShowGenericOkDialog("Passwörter müssen übereinstimmen");
                return;
            }

            _createButton.Content   = "Erstelle Account...";
            _createButton.IsEnabled = false;

            (App.Current as App).Server = new ServerCommunication(_createUserMailBox.Text, _createPasswordTextBox.Password);
            SamServerResponse response = await(App.Current as App).Server.Signup();

            if (response.successfull)
            {
                ApplicationData.Current.LocalSettings.Values["userMail"] = mail;
                ApplicationData.Current.LocalSettings.Values["password"] = _passwordTextBox.Password;
                (App.Current as App)._loggedIn = true;
                var successDialog = new MessageDialog("Account wurde erfolgreich erstellt. Sie sind jetzt eingeloggt!");
                successDialog.Commands.Add(new UICommand("ok"));
                await successDialog.ShowAsync();

                _createButton.IsEnabled        = true;
                _createAccountPanel.Visibility = Visibility.Collapsed;
                _configurationPanel.Visibility = Visibility.Visible;
                Frame.Navigate(typeof(StartPage));
            }
            else
            {
                ShowGenericOkDialog(response.ErrorMessage);
                _createButton.IsEnabled = true;
                _createButton.Content   = "Neuen Account Erstellen";
            }
        }
        private async void _submitButton_Click(object sender, RoutedEventArgs e)
        {
            SamServerResponse response = await _trip.submitPoints();

            if (response.successfull)
            {
                var successDialog = new MessageDialog("Der Trip wurde erfolgreich an dem SAM-Server übertragen.");
                successDialog.Commands.Add(new UICommand("ok"));
                await successDialog.ShowAsync();
            }
            else
            {
                var dialog = new MessageDialog(response.ErrorMessage);
                dialog.Commands.Add(new UICommand("ok"));
                await dialog.ShowAsync();
            }
        }
        // private methods---------------------------------------------------------------------------
        private async void delete_account(IUICommand label)
        {
            SamServerResponse response = await(App.Current as App).Server.DeleteUser();

            if (response.successfull)
            {
                var Dialog = new MessageDialog("Ihr Account wurde erfolgreich gelöscht. Sie sind jetzt abgemeldet!");
                Dialog.Commands.Add(new UICommand("OK", new UICommandInvokedHandler(delete_account)));
                await Dialog.ShowAsync();

                ApplicationData.Current.LocalSettings.Values.Remove("userMail");
                ApplicationData.Current.LocalSettings.Values.Remove("password");
                _configurationPanel.Visibility = Visibility.Collapsed;
                _loginPanel.Visibility         = Visibility.Visible;
            }
            else
            {
                ShowGenericOkDialog(response.ErrorMessage);
            }
        }
        // performs login to SAM server
        private async void _loginButton_Click(object sender, RoutedEventArgs e)
        {
            //Verify Mail-Adress
            String mail           = _userMailBox.Text;
            Match  mailValidation = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Match(mail);

            if (!mailValidation.Success)
            {
                ShowGenericOkDialog("Bitte gültige E-Mail Adresse eingeben");
                return;
            }


            try
            {
                string password = _passwordTextBox.Password;
                (App.Current as App).Server = new ServerCommunication(mail, password);
                SamServerResponse response = await(App.Current as App).Server.Signin();
                if (response.successfull)
                {
                    ApplicationData.Current.LocalSettings.Values["password"] = password;
                    ApplicationData.Current.LocalSettings.Values["userMail"] = mail;
                    _loginPanel.Visibility = Visibility.Collapsed;

                    Frame.Navigate(typeof(StartPage));
                    (App.Current as App)._loggedIn = true;
                }
                else
                {
                    (App.Current as App)._loggedIn = false;
                    ShowGenericOkDialog(response.ErrorMessage);
                }
            }
            catch (Exception)
            {
                ShowGenericOkDialog("Es ist ein unbekannter Fehler beim Login augetreten!");
                (App.Current as App)._loggedIn = false;
            }
        }
예제 #9
0
        //downloads user-tags and returns list of SamTags
        public async Task <SamTagResponse> GetTags()
        {
            HttpClient client         = new HttpClient();
            Uri        domain         = new Uri(_serverUrl + "get_usertags/");
            JsonObject tagRequestJson = new JsonObject();

            tagRequestJson.SetNamedValue("userID", JsonValue.CreateNumberValue(_userId));
            Windows.Web.Http.HttpStringContent httpFrame = new Windows.Web.Http.HttpStringContent(tagRequestJson.Stringify());

            try
            {
                HttpResponseMessage response = await client.PostAsync(domain, httpFrame);

                SamServerResponse result = AnalyzeResponse(response);
                if (result.successfull)
                {
                    return(new SamTagResponse
                    {
                        successfull = true,
                        Tags = JsonConvert.DeserializeObject <List <SamTag> >(response.Content.ToString())
                    });
                }
                else
                {
                    //server error
                    return(new SamTagResponse {
                        successfull = false, ErrorMessage = result.ErrorMessage
                    });
                }
            }
            catch (Exception)
            {
                //connection error
                return(new SamTagResponse {
                    successfull = false, ErrorMessage = GenericConnectionFailedResponse.ErrorMessage
                });
            }
        }