Пример #1
0
        private async void SubmitNewPassword(string pass)
        {
            try
            {
                string authHeader = Functions.Base64Encode(string.Format("{0}:{1};{2}", App.ManagerProfile.ID, ManagerPassword.Password, pass));

                App.client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeader);

                string json_data = await App.client.GetStringAsync(Globals.baseURL + "UpdatePass");

                if (!string.IsNullOrEmpty(json_data))
                {
                    JsonBasicResult <object> json = JsonConvert.DeserializeObject <JsonBasicResult <object> >(json_data);
                    if (json.ok)
                    {
                        Functions.ShowMessageDialog("", PageText.SavedSuccess);
                    }
                    else
                    {
                        throw new Exception(json.message);
                    }
                }
                else
                {
                    throw new Exception("No result data!");
                }
            }
            catch (Exception e)
            {
                Functions.ShowErrorMessageDialog(e);
            }
        }
Пример #2
0
        private async Task AutoFetchData()
        {
            try
            {
                if (Functions.AppVerified(out string email))
                {
                    string userData = Functions.Base64Encode(string.Format("{0}:{1}", email, ""));

                    App.client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", userData);

                    string json_data = await App.client.GetStringAsync(Globals.baseURL + "GetAppData");

                    if (!string.IsNullOrEmpty(json_data))
                    {
                        JsonBasicResult <ManagerLoginResult> json = JsonConvert.DeserializeObject <JsonBasicResult <ManagerLoginResult> >(json_data);
                        if (json.ok)
                        {
                            Application.Current.Dispatcher.Invoke(() => {
                                Functions.SynchroniseAppData(json.data);
                                LoginOptionBtnsStackPanel.Visibility = Visibility.Visible;
                            });
                        }
                        else
                        {
                            throw new Exception(json.message);
                        }
                    }
                    else
                    {
                        throw new Exception("No result data!");
                    }
                }
                else
                {
                    //app not been used yet, so only allow manager login
                    LoginOptionBtnsStackPanel.Visibility = Visibility.Visible;
                    //LoginOptionBtnsStackPanel.Visibility = Visibility.Hidden;
                }
            }
            catch (Exception e)
            {
                Functions.ShowErrorMessageDialog(e);
            }
        }
Пример #3
0
        private async void ProcessLogin()
        {
            try
            {
                Dispatcher.Invoke(() => {
                    UsernameInput.IsEnabled      = false;
                    PasswordInput.IsEnabled      = false;
                    LoginBtn.IsEnabled           = false;
                    RememberMeCheckbox.IsEnabled = false;
                });

                App.UserLogin    = UsernameInput.Text;
                App.UserPassword = PasswordInput.Password;

                string userData = Functions.Base64Encode(string.Format("{0}:{1}", App.UserLogin, App.UserPassword));

                App.client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", userData);

                string json_data = await App.client.GetStringAsync(Globals.baseURL + "StudentLogin");

                if (!string.IsNullOrEmpty(json_data))
                {
                    JsonBasicResult <StudentLoginResult> json = JsonConvert.DeserializeObject <JsonBasicResult <StudentLoginResult> >(json_data);
                    if (json.ok)
                    {
                        App.UserType       = Helpers.Enums.UserType.Candidate;
                        App.ManagerProfile = json.data.Manager;
                        App.StudentProfile = json.data.Student;
                        App.StudentProfile.ProcessData();

                        if (RememberMe)
                        {
                            DbContext.AddRememberMe(new DbRememberMe {
                                Email = UsernameInput.Text, Type = (int)DataLayer.Enums.RememberMeType.Candidate
                            });
                        }
                        else if (DbRememberMe != null)
                        {
                            DbContext.DeleteRememberMe(DbRememberMe);
                        }

                        if (!Functions.AppVerified(out _))
                        {
                            DbContext.AddVerified(new DbVerified {
                                Email = App.ManagerProfile.Email
                            });
                        }


                        SetMainWindowContent(new Layout(Logout));
                    }
                    else
                    {
                        throw new Exception(json.message);
                    }
                }
                else
                {
                    throw new Exception("Username or password incorrect!");
                }
            }
            catch (Exception ex)
            {
                Functions.ShowErrorMessageDialog(ex);
                Dispatcher.Invoke(() => {
                    UsernameInput.IsEnabled      = true;
                    PasswordInput.IsEnabled      = true;
                    LoginBtn.IsEnabled           = true;
                    RememberMeCheckbox.IsEnabled = true;
                });
            }
        }