Ejemplo n.º 1
0
        private void OnSave(object sender, EventArgs args)
        {
            try
            {
                if (string.IsNullOrEmpty(Username.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Enter username to proceed", MessageType.Regular, promptPageState), true));
                    return;
                }

                if (user.UserName.Equals(Username.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("The username you've entered is the same as the current one", MessageType.Regular, promptPageState), true));
                    return;
                }

                //Save configuration
                configuration.Users.Find(x => x.UserName == user.UserName).UserName = Username.Text;
                AiDataStore.SaveConfiguration(configuration);

                //Save user
                user.UserName = Username.Text;
                AiDataStore.SaveUser(user);

                //Close Popup
                promptPageState.OnResumePage(null);
                Task.Run(async() => await PopupNavigation.Instance.RemovePageAsync(this));
            }
            catch (Exception ex)
            {
                Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox(ex.Message, MessageType.Regular, promptPageState), true));
            }
        }
Ejemplo n.º 2
0
        public void Authorize()
        {
            //Show progress indicator
            processInIndicator.IsVisible = true;
            processInIndicator.IsRunning = true;
            signInLbl.Text = "Please wait...";

            Task.Factory.StartNew(async() =>
            {
                // Do some work on a background thread, allowing the UI to remain responsive
                user = configuration.Users.Find(x => x.UserName == Username.Text && x.Password == Password.Text);
            }).ContinueWith(task =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    try
                    {
                        Task.Run(async() => await Task.Delay(5000));
                        //Hide progress indicator
                        processInIndicator.IsRunning = false;
                        processInIndicator.IsVisible = false;

                        if (user != null)
                        {
                            AiDataStore.SaveUser(user);
                            StartApplication(user.UserRights.FirstOrDefault().ObjectType);
                        }
                        else
                        {
                            Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Wrong username or password", MessageType.Regular, this)));
                            signInLbl.Text = "SIGN IN";
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                });
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 3
0
        private void OnSave(object sender, EventArgs args)
        {
            try
            {
                if (string.IsNullOrEmpty(CPassword.Text) || string.IsNullOrEmpty(NPassword.Text) || string.IsNullOrEmpty(Password.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Enter missing password to proceed", MessageType.Regular, promptPageState), true));
                    return;
                }

                if (user.Password.Equals(NPassword.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("You've entered a wrong current password", MessageType.Regular, promptPageState), true));
                    return;
                }

                if (!NPassword.Text.Equals(Password.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("New Password doesnot match the confirmed password", MessageType.Regular, promptPageState), true));
                    return;
                }

                //Save configuration
                configuration.Users.Find(x => x.UserName == user.UserName).Password = NPassword.Text;
                AiDataStore.SaveConfiguration(configuration);

                //Save user
                user.Password = NPassword.Text;
                AiDataStore.SaveUser(user);

                //Close Popup
                Task.Run(async() => await PopupNavigation.Instance.RemovePageAsync(this));
            }
            catch (Exception ex)
            {
                Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox(ex.Message, MessageType.Regular, promptPageState), true));
            }
        }
Ejemplo n.º 4
0
        private void Authentication()
        {
            try
            {
                Password.IsEnabled           = false;
                Username.IsEnabled           = false;
                processInIndicator.IsVisible = true;
                processInIndicator.IsRunning = true;
                signInLbl.Text      = "Please wait...";
                signInBtn.IsEnabled = false;
                Task.Factory.StartNew(async() => {
                    // Do some work on a background thread, allowing the UI to remain responsive
                    var response        = Synchronization.SignInAsync(Username.Text, Password.Text).Result;
                    var responseContent = await response.Content.ReadAsStringAsync();
                    user = JsonConvert.DeserializeObject <User>(responseContent);
                }).ContinueWith(task => {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (user != null)
                        {
                            if (string.IsNullOrEmpty(user.UserName))
                            {
                                Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Wrong username or password", MessageType.Regular, this)));
                                (Username.Parent as Frame).BorderColor = Color.Red;
                                ((Password.Parent as Grid).Parent as Frame).BorderColor = Color.Red;
                            }
                            else if (!user.Enabled)
                            {
                                Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Your acccount has beeen disabled, please contact your administrator for a possible solution", MessageType.Regular, this)));
                            }
                            else
                            {
                                AiDataStore.SaveUser(user);
                                //                 if (user.UserRights != null)
                                //                {
                                //                     var userRights = user.UserRights.Where(x => x.Configuration.OID > 0).ToList();

                                //                     if (userRights.Count > 0)
                                //                     {
                                App.Current.MainPage = new NavigationPage(new Configurations(user, this));
                                //                     }
                                //                     else
                                //                    {
                                //                         Task.Run(async () => await PopupNavigation.Instance.PushAsync(new MessageBox("You have no affiliated permissions to use this application, please contact your administrator for a solution", MessageType.Regular, this)));
                                //                         AiDataStore.Logout();

                                //                     }
                                //                 }
                                //                 else
                                //                     Task.Run(async () => await PopupNavigation.Instance.PushAsync(new MessageBox("You have no affiliated permissions to use this application, please contact your administrator for a solution", MessageType.Regular, this)));
                            }
                        }
                        else
                        {
                            Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Something went wrong, please try again", MessageType.Regular, this)));
                        }

                        signInLbl.Text               = "SIGN IN";
                        Password.IsEnabled           = true;
                        Username.IsEnabled           = true;
                        signInBtn.IsEnabled          = true;
                        processInIndicator.IsRunning = false;
                        processInIndicator.IsVisible = false;
                    });
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex)
            {
                Debug.Write(ex.StackTrace);
            }
        }