示例#1
0
        private bool Authenticated()
        {
            bool valid = true;

            if (string.IsNullOrWhiteSpace(UsernameEntry.Text))
            {
                UsernameEntry.BorderBrush = Brushes.Red;
                valid = false;
            }
            if (string.IsNullOrWhiteSpace(PasswordEntry.Password))
            {
                PasswordEntry.BorderBrush = Brushes.Red;
                valid = false;
            }
            if (!valid)
            {
                return(false);
            }
            User tmp = Users.FirstOrDefault(x => x.Username == UsernameEntry.Text &&
                                            x.Password == PasswordEntry.Password);

            if (tmp == null)
            {
                valid = false;
                MessageBox.Show("Invalid account credentials. Please try again.", "Login Error");
                UsernameEntry.Focus();
            }
            return(valid);
        }
示例#2
0
        protected async override void OnAppearing()
        {
            base.OnAppearing();

            await Task.Delay(1);

            UsernameEntry.Focus();
        }
示例#3
0
 protected override void OnAppearing()
 {
     base.OnAppearing();
     UsernameEntry.Focus();
     using (SQLiteConnection conn = new SQLiteConnection(App.FilePath)) {
         //    conn.DeleteAll<TransactionTable>();
         //    conn.DeleteAll<UserModel>();
     }
 }
示例#4
0
        private void UsernameEntry_Completed(object sender, EventArgs e)
        {
            var input = UsernameEntry.Text;

            if (input == null)
            {
                DisplayAlert("Error", "Username is too short (minimum is 6 characters)", "OK");
                UsernameEntry.Focus();
            }
            else
            {
                input = input.ToLower();
                if (input.Length > 20)
                {
                    DisplayAlert("Error", "Username is too long (maximum is 20 characters)", "OK");
                    UsernameEntry.Focus();
                    return;
                }
                if (input.Length < 6)
                {
                    DisplayAlert("Error", "Username is too short (minimum is 6 characters)", "OK");
                    UsernameEntry.Focus();
                    return;
                }
                if (input.Contains(' '))
                {
                    DisplayAlert("Error", "Username Can't Have Whitespaces", "OK");
                    UsernameEntry.Focus();
                    return;
                }
                bool temp = true;
                foreach (var item in input)
                {
                    if (!char.IsLetterOrDigit(item))
                    {
                        temp = false;
                        break;
                    }
                }
                if (!temp)
                {
                    DisplayAlert("Error", "Username Can Only Contain Alphabets or Digits", "OK");
                    UsernameEntry.Focus();
                    return;
                }
                PasswordEntry.Focus();
            }
        }
示例#5
0
        public async void SignInPressed(object sender, EventArgs e)
        {
            var service = new AccountsService();

            if (string.IsNullOrEmpty(UsernameEntry.Text))
            {
                await DisplayAlert("Alerta", "Ingrese nombre de usuario", "Aceptar");

                UsernameEntry.Focus();
                return;
            }

            if (string.IsNullOrEmpty(PasswordEntry.Text))
            {
                await DisplayAlert("Alerta", "Ingrese contraseña", "Aceptar");

                PasswordEntry.Focus();
                return;
            }

            if (service.Authentication(UsernameEntry.Text, PasswordEntry.Text))
            {
                waitActivityIndicator.IsRunning = true;
                await Task.Delay(1500);

                if (service.GetUserNameType(UsernameEntry.Text) == "Paciente")
                {
                    Patient patient = service.GetPatientByUserId(1);
                    App.Current.MainPage = new NavigationPage(new PatientMainPage(patient));
                }
                else if (service.GetUserNameType(UsernameEntry.Text) == "Doctor")
                {
                    Doctor doctor = service.GetDoctorByUserId(1);
                    App.Current.MainPage = new NavigationPage(new DoctorMainPage(doctor));
                }

                waitActivityIndicator.IsRunning = false;
                UsernameEntry.Text = string.Empty;
                PasswordEntry.Text = string.Empty;
            }
            else
            {
                await DisplayAlert("Alerta", "Usuario o contraseña incorrectos", "Aceptar");

                PasswordEntry.Text = string.Empty;
                return;
            }
        }
示例#6
0
        public async void SubmitButtonClicked(Object sender, EventArgs args)
        {
            if (String.IsNullOrEmpty(UsernameEntry.Text))
            {
                UsernameEntry.Focus();
            }
            else if (String.IsNullOrEmpty(PasswordEntry.Text))
            {
                PasswordEntry.Focus();
            }
            else if (!GlobalData.VerifyData(UsernameEntry.Text, PasswordEntry.Text))
            {
                await DisplayAlert("Warning", " Username or Password is Incorrect ", "Okay");
            }
            else
            {
                await Navigation.PushAsync(new MainPage());

                Navigation.RemovePage(Navigation.NavigationStack[0]);
            }
        }
示例#7
0
 public Login()
 {
     InitializeComponent();
     //BindingContext = loginM;
     UsernameEntry.Focus();
 }
示例#8
0
        private async void LogInButton_Clicked(object sender, EventArgs e)
        {
            var Username = UsernameEntry.Text;
            var Password = PasswordEntry.Text;

            if (Username == null)
            {
                await DisplayAlert("Error", "Username is too short (minimum is 6 characters)", "OK");

                UsernameEntry.Focus();
                return;
            }
            if (Password == null)
            {
                var Message = "Password is too short (minimum is 6 characters)";
                await DisplayAlert("Error", Message, "OK");

                PasswordEntry.Focus();
                return;
            }
            if (Username.Length < 6)
            {
                var Message = "Username is too short (minimum is 6 characters)";
                await DisplayAlert("Error", Message, "OK");

                UsernameEntry.Focus();
                return;
            }
            if (Password.Length < 6)
            {
                var Message = "Password is too short (minimum is 6 characters)";
                await DisplayAlert("Error", Message, "OK");

                PasswordEntry.Focus();
                return;
            }
            if (Username.Length > 20)
            {
                var Message = "Username is too long (maximum is 20 characters)";
                await DisplayAlert("Error", Message, "OK");

                UsernameEntry.Focus();
                return;
            }
            if (Password.Length > 20)
            {
                var Message = "Password is too long (maximum is 20 characters)";
                await DisplayAlert("Error", Message, "OK");

                PasswordEntry.Focus();
                return;
            }
            MainFrame.IsVisible       = false;
            LoadingOverlay.IsVisible  = true;
            LoadingIndicatorText.Text = "Checking Credentials";
            Username = Username.ToLower();
            await Task.Run(async() =>
            {
                string url     = "http://supplyblockchain.sudeshkumar.me/UserAccount/LogIn";
                HttpContent q1 = new FormUrlEncodedContent(new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("userName", Username), new KeyValuePair <string, string>("password", Password)
                });
                using (var httpClient = new HttpClient())
                {
                    try
                    {
                        Task <HttpResponseMessage> getResponse = httpClient.PostAsync(url, q1);
                        HttpResponseMessage response           = await getResponse;
                        if (response.IsSuccessStatusCode)
                        {
                            var myContent = await response.Content.ReadAsStringAsync();
                            if (myContent == "False")
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    var Message = "Invalid Login Attempt!!!";
                                    DisplayAlert("Error", Message, "OK");
                                    UsernameEntry.Focus();
                                    MainFrame.IsVisible      = true;
                                    LoadingOverlay.IsVisible = false;
                                    return;
                                });
                            }
                            else
                            {
                                Device.BeginInvokeOnMainThread(async() =>
                                {
                                    User user = JsonConvert.DeserializeObject <User>(myContent);
                                    Application.Current.Properties["UserName"]               = user.UserName;
                                    Application.Current.Properties["Password"]               = user.Password;
                                    Application.Current.Properties["FullName"]               = user.FullName;
                                    Application.Current.Properties["EmailID"]                = user.EmailID;
                                    Application.Current.Properties["AccessRights"]           = user.AccessRights;
                                    Application.Current.Properties["AssociatedProductTypes"] = user.AssociatedProductTypes;
                                    await Application.Current.SavePropertiesAsync();
                                    MainFrame.IsVisible          = true;
                                    LoadingOverlay.IsVisible     = false;
                                    Application.Current.MainPage = new NavigationPage(new HomePage());
                                    return;
                                });
                            }
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                var Message = "Server Is Down. Try Again After Some Time";
                                DisplayAlert("Error", Message, "OK");
                                MainFrame.IsVisible      = true;
                                LoadingOverlay.IsVisible = false;
                                return;
                            });
                        }
                    }
                    catch (Exception)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            var Message = "Check Your Internet Connection and Try Again";
                            DisplayAlert("Error", Message, "OK");
                            MainFrame.IsVisible      = true;
                            LoadingOverlay.IsVisible = false;
                            return;
                        });
                    }
                }
            });
        }
示例#9
0
        private async void LogInButton_Clicked(object sender, EventArgs e)
        {
            var Username = UsernameEntry.Text;
            var Password = PasswordEntry.Text;

            if (Username == null)
            {
                await DisplayAlert("Error", "Username should contain at least six characters", "OK");

                UsernameEntry.Focus();
                return;
            }
            if (Password == null)
            {
                var Message = "Password should contain at least six characters";
                await DisplayAlert("Error", Message, "OK");

                PasswordEntry.Focus();
                return;
            }
            if (Username.Length < 6)
            {
                var Message = "Username should contain at least six characters";
                await DisplayAlert("Error", Message, "OK");

                UsernameEntry.Focus();
                return;
            }
            if (Password.Length < 6)
            {
                var Message = "Password should contain at least six characters";
                await DisplayAlert("Error", Message, "OK");

                PasswordEntry.Focus();
                return;
            }
            if (Username.Length > 15)
            {
                var Message = "Username can contain at max fifteen characters";
                await DisplayAlert("Error", Message, "OK");

                UsernameEntry.Focus();
                return;
            }
            if (Password.Length > 15)
            {
                var Message = "Password can contain at max fifteen characters";
                await DisplayAlert("Error", Message, "OK");

                PasswordEntry.Focus();
                return;
            }
            MainFrame.IsVisible       = false;
            LoadingOverlay.IsVisible  = true;
            LoadingIndicatorText.Text = "Checking Credentials";
            Username = Username.ToLower();
            await Task.Run(async() =>
            {
                string url     = DifferentUrls.SignInUrl;
                HttpContent q1 = new FormUrlEncodedContent(new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("Username", Username), new KeyValuePair <string, string>("Password", Password)
                });
                using (var httpClient = new HttpClient())
                {
                    try
                    {
                        Task <HttpResponseMessage> getResponse = httpClient.PostAsync(url, q1);
                        HttpResponseMessage response           = await getResponse;
                        if (response.IsSuccessStatusCode)
                        {
                            var myContent = await response.Content.ReadAsStringAsync();
                            if (myContent == "False")
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    var Message = "Invalid Login Attempt!!!";
                                    DisplayAlert("Error", Message, "OK");
                                    UsernameEntry.Focus();
                                    MainFrame.IsVisible      = true;
                                    LoadingOverlay.IsVisible = false;
                                    return;
                                });
                            }
                            else
                            {
                                Device.BeginInvokeOnMainThread(async() =>
                                {
                                    UserAccount user = JsonConvert.DeserializeObject <UserAccount>(myContent);
                                    Application.Current.Properties["EID"]                = user.ID;
                                    Application.Current.Properties["Username"]           = user.Username;
                                    Application.Current.Properties["Password"]           = user.Password;
                                    Application.Current.Properties["FullName"]           = user.FullName;
                                    Application.Current.Properties["Designation"]        = user.Designation;
                                    Application.Current.Properties["ECode"]              = user.ECode;
                                    Application.Current.Properties["Section"]            = user.Section;
                                    Application.Current.Properties["FullDepartmentInfo"] = user.FullDepartmentInfo;
                                    Application.Current.Properties["MobileNumber"]       = user.MobileNumber;
                                    if (user.ReqPwdChange)
                                    {
                                        Application.Current.Properties["PWDChange"] = "Yes";
                                        await Application.Current.SavePropertiesAsync();
                                        MainFrame.IsVisible          = true;
                                        LoadingOverlay.IsVisible     = false;
                                        Application.Current.MainPage = new NavigationPage(new ChangePassword());
                                        return;
                                    }
                                    else
                                    {
                                        Application.Current.Properties["PWDChange"] = String.Empty;
                                        await Application.Current.SavePropertiesAsync();
                                        MainFrame.IsVisible          = true;
                                        LoadingOverlay.IsVisible     = false;
                                        Application.Current.MainPage = new NavigationPage(new HomePage());
                                        return;
                                    }
                                });
                            }
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                var Message = "Server Is Down. Try Again After Some Time";
                                DisplayAlert("Error", Message, "OK");
                                MainFrame.IsVisible      = true;
                                LoadingOverlay.IsVisible = false;
                                return;
                            });
                        }
                    }
                    catch (Exception)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            var Message = "Check Your Internet Connection and Try Again";
                            DisplayAlert("Error", Message, "OK");
                            MainFrame.IsVisible      = true;
                            LoadingOverlay.IsVisible = false;
                            return;
                        });
                    }
                }
            });
        }
示例#10
0
 public void UsernameEntry_Completed(object sender, EventArgs e)
 {
     UsernameEntry.Focus();
 }
示例#11
0
 public MainWindow()
 {
     InitializeComponent();
     ReadInUsers();
     UsernameEntry.Focus();
 }