Пример #1
0
        void InIt()
        {
            BackgroundColor = Constants.BackgroundColor;
            // Lbl_Username.TextColor = Constants.MainTextColor;
            //  Lbl_Password.TextColor = Constants.MainTextColor;
            Btn_Login.BackgroundColor = Constants.BackgroundColor;
            ActivitySpinner.IsVisible = false;
            //LoginIcon.HeightRequest = Constants.LoginIconHeight;
            Entry_Username.Completed += (s, e) => Entry_Username.Focus();
            Entry_Password.Completed += (s, e) => Entry_Password.Focus();
            //Btn_Register.Text = "Click Me!";
            //Btn_Register.Font = Font.SystemFontOfSize(NamedSize.Large);
            //Btn_Register.BorderWidth = 1;
            //Btn_Register.HorizontalOptions = LayoutOptions.Center;
            //Btn_Register.VerticalOptions = LayoutOptions.CenterAndExpand;

            //////Btn_Register.BorderWidth = 1;
            //Btn_Search.HorizontalOptions = LayoutOptions.Center;
            //Btn_Search.VerticalOptions = LayoutOptions.CenterAndExpand;
            ////Btn_Login.HorizontalOptions = LayoutOptions.Center;
            ////Btn_Login.VerticalOptions = LayoutOptions.CenterAndExpand;
            //Btn_Search.BackgroundColor = Constants.BackgroundColor;
            //Btn_Register.BackgroundColor = Constants.BackgroundColor;
            Btn_Register.BackgroundColor = Constants.BackgroundColor;
            Btn_Search.BackgroundColor   = Constants.BackgroundColor;
        }
Пример #2
0
        void Init()
        {
            BackgroundColor           = Constants.BackgroundColor;
            Lbl_Username.TextColor    = Constants.MainTextColor;
            Lbl_Password.TextColor    = Constants.MainTextColor;
            ActivitySpinner.IsVisible = false;
            LoginIcon.HeightRequest   = Constants.LoginIconHeight;

            Entry_Username.Completed += (s, e) => Entry_Username.Focus();
            Entry_Password.Completed += (s, e) => Entry_Password.Focus();
        }
Пример #3
0
 public SignupPage(string image, string name, string price, int qty)
 {
     InitializeComponent();
     this.BackgroundImage = "background.jpg";
     this.Title           = "SignUp";
     this.getImage        = image;
     this.getName         = name;
     this.getPrice        = price;
     this.getQuantity     = qty;
     userDB    = new UserDB();
     userQuery = new UserQuery();
     Entry_Fullname.Completed         += (s, e) => Entry_Username.Focus();
     Entry_Username.Completed         += (s, e) => Entry_Password.Focus();
     Entry_Password.Completed         += (s, e) => Entry_Confirm_Password.Focus();
     Entry_Confirm_Password.Completed += (s, e) => Entry_Mobile_Number.Focus();
     Entry_Mobile_Number.Completed    += (s, e) => Entry_Address.Focus();
     Entry_Address.Completed          += (s, e) => SignUpInsert(s, e);
 }
Пример #4
0
        // Función de autenticación
        async Task SignInProcedureAsync(object sender, EventArgs e)
        {
            // Capturamos las credenciales
            User user = new User(Entry_Username.Text, Entry_Password.Text);

            // Validación de campos vacíos
            if (user.CheckInformation())
            {
                // Instanciamos la clase para mapear
                // el request del login
                var request = new RequestAuth
                {
                    // Capturamos los parámetros de credenciales
                    // los cuales van a ser enviados al servicio de login
                    Grant_type = "password",
                    Username   = user.Username,
                    Password   = user.Password
                };
                // Globalizamos los datos del usuario
                Constants.CurrentUser = user;
                // Globalizamos las credenciales
                Constants.RequestAuth = request;
                // Verificamos nuevamente que haya conexión a internet
                CheckConnectivity();
                // Verificamos que exista conexión a internet
                if (Constants.hasInternet)
                {
                    // Creamos un hilo de ejecución para consumir el servicio del login
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        // Mostramos el spinner de carga
                        ActivitySpinner.IsVisible = true;
                        // Ocultamos el botón de submit
                        Btn_SignIn.IsVisible = false;
                        // Try catch para excepción de errores
                        try
                        {
                            // Consumimos el servicio de autenticación de Solex
                            var result = await App.RestClient.Login <ResponseAuth>();
                            // Verificamos que el servicio haya devuelto una respuesta
                            if (result != null)
                            {
                                // Verificamos que las credenciales sean correctas
                                if (result.Codigo == 1)
                                {
                                    // Verificamos que el usuario tenga roles asignados
                                    if (result.Roles != null)
                                    {
                                        // Consultamos los datos del usuario en la BD local
                                        var userDB = App.UserDatabase.GetUserByUsername(user.Username);
                                        // Solo en caso de que ya se encuentre registrado en el dispositivo
                                        if (userDB != null)
                                        {
                                            user.Id = userDB.Id;
                                        }
                                        // Activamos la propiedad de login
                                        user.IsLogin = true;
                                        // Asignamos el id de solex
                                        user.IdSolex = result.UsuarioId;
                                        // Asignamos la placa al usuario
                                        user.Placa = result.Placa;
                                        // Actualizamos la hora de actualización
                                        // del registro del usuario
                                        user.Updated_at = DateTime.Now;
                                        // Valor por defecto para los permisos de cubicación
                                        Constants.CurrentUser.IsCubage = false;
                                        // Recorremos los roles uno a uno
                                        foreach (string x in result.Roles)
                                        {
                                            // Chequamos si el usuario tiene el rol de administrador
                                            if (x.Equals("Administrator"))
                                            {
                                                Constants.CurrentUser.IsCubage = true;
                                                Constants.CurrentUser.IsAdmin  = true;
                                            }
                                            else
                                            {
                                                // Chequamos si el usuario tiene el rol de cubicación manual
                                                if (x.Equals("Cubicación manual"))
                                                {
                                                    Constants.CurrentUser.IsCubage = true;
                                                }
                                            }
                                        }
                                        // Guardamos el dato de los permisos de cubicación
                                        user.IsCubage = Constants.CurrentUser.IsCubage;
                                        // Guardamso el dato del rol de administrador
                                        user.IsAdmin = Constants.CurrentUser.IsAdmin;
                                        // Guardamos los datos del usuario
                                        // en la base de datos local
                                        App.UserDatabase.SaveUser(user);
                                        // Globalizamos el usuario que acaba de ingresar
                                        Constants.CurrentUser = App.UserDatabase.GetLastUserActive();
                                        // Junto con el token que es devuelto desde Solex
                                        App.TokenDatabase.SaveToken(result.Access_token);
                                        // Globalizamos el token de la sesión
                                        if (App.TokenDatabase.GetToken() != null)
                                        {
                                            // Se obtien el token actual en caso de que no este asignado
                                            Constants.BearerToken = App.TokenDatabase.GetToken().Access_token;
                                        }
                                        // Si el usuario tiene como único rol el de cubicación
                                        if (Constants.CurrentUser.IsCubage && result.Roles.Length == 1)
                                        {
                                            // Verificamos la plataforma para saber
                                            // de que manera se debe hacer el cambio de página
                                            if (Device.RuntimePlatform == Device.Android)
                                            {
                                                await Navigation.PushAsync(new CubingPage());
                                            }
                                            else if (Device.RuntimePlatform == Device.iOS)
                                            {
                                                await Navigation.PushModalAsync(new NavigationPage(new CubingPage()));
                                            }
                                        }
                                        else
                                        {
                                            // Verificamos la plataforma para saber
                                            // de que manera se debe hacer el cambio de página
                                            if (Device.RuntimePlatform == Device.Android)
                                            {
                                                await Navigation.PushAsync(new DashboardPage());
                                            }
                                            else if (Device.RuntimePlatform == Device.iOS)
                                            {
                                                await Navigation.PushModalAsync(new NavigationPage(new DashboardPage()));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // Mostramos el mensaje informativo
                                        await DisplayAlert("Login", "El usuario no tiene roles asignados!", "OK");
                                    }
                                }
                                else
                                {
                                    // Mensaje informativo del error
                                    await DisplayAlert("Respuesta de Solex", result.Respuesta, "OK");
                                }
                            }
                            else
                            {
                                // Mensaje informativo del error
                                await DisplayAlert("Login", "Ocurrió un error al intentar loguearte!", "OK");
                            }
                        }
                        catch (Exception er)
                        {
                            // Mensaje informativo del error
                            await DisplayAlert("Login", "Ocurrió un error al intentar loguearte!", "OK");
                            // Impresión del error en consola
                            Debug.WriteLine("Error: " + er.Message);
                        }
                        // Desabilitamos el spinner de carga
                        ActivitySpinner.IsVisible = false;
                        // Mostramos el botón de submit
                        Btn_SignIn.IsVisible = true;
                        // Posicionamiento del cursor
                        Entry_Username.Focus();
                    });
                }
                else
                {
                    // Se busca el usuario
                    User userDB = App.UserDatabase.GetUserByUsername(user.Username);
                    // Si el usuario existe en el dipositivo, entonces verificamos
                    // que las credenciales de acceso sean correctas
                    if (userDB != null)
                    {
                        if (!App.UserDatabase.CheckCredentialsUserLocal(user.Username, user.Password))
                        {
                            await DisplayAlert("Login", "Crendenciales Incorrectas", "OK");
                        }
                        else
                        {
                            // Verificamos la plataforma para saber
                            // de que manera se debe hacer el cambio de página
                            if (Device.RuntimePlatform == Device.Android)
                            {
                                Application.Current.MainPage = new NavigationPage(new DashboardPage());
                            }
                            else if (Device.RuntimePlatform == Device.iOS)
                            {
                                await Navigation.PushModalAsync(new NavigationPage(new DashboardPage()));
                            }
                        }
                    }
                    // Esto ocurre en dado caso de que no haya conexión a internet
                    // y el usuario no haya sido autenticado anteriormente en ese dispositivo
                    else
                    {
                        await DisplayAlert("Login", "El Usuario no se encuentra registrado en este dispositivo!", "OK");
                    }
                }
            }
            // En caso de que alguno de los campos del login esté vacio
            else
            {
                // Mensaje de validación de campos
                await DisplayAlert("Error de campos vacios!", "Por favor digita tus credenciales de acceso, para que puedas ingresar a la aplicación.", "OK");
            }
            // Desabilitamos el spinner de carga
            ActivitySpinner.IsVisible = false;
        }
Пример #5
0
 public void LoginFaild()
 {
     Entry_Username.Text = null;
     Entry_Password.Text = null;
     Entry_Username.Focus();
 }
Пример #6
0
        private async void btn_Login_Clicked(object sender, EventArgs e)
        {
            btn_Login.IsEnabled = false;
            int val = new ModelLogin().CheckEntryNull(Entry_Username.Text, Entry_Password.Text);

            if (val == 0)
            {
                ValueDTO <TaiKhoan> tk = await new LoginViewModel().CheckLogin(Entry_Username.Text, Entry_Password.Text);
                if (tk.Error == 0)
                {
                    if (tk.ListT.Count == 1)
                    {
                        App.IDAccount = tk.ListT[0].ID;
                        App.UserName  = tk.ListT[0].UserName;
                        if (await LoadDataInDatabase())
                        {
                            await DisplayAlert("Thông báo", "Đăng nhập thành công", "Ok");

                            App.lstLoaiDiems.Sort(new SortLoaiDiem());
                            Application.Current.MainPage = new MainPage();
                        }
                        else
                        {
                            await DisplayAlert("Thông báo", "Đăng nhập thất bại. Không thể load được vì mạng yếu. hoặc chưa bật mạng vui lòng kiểm tra lại.", "OK");

                            LoginFaild();
                            btn_Login.IsEnabled = true;
                        }
                    }
                    else
                    {
                        await DisplayAlert("Thông báo", "Đăng nhập thất bại.\nTài khoản hoặc mật khẩu không chính xác", "OK");

                        LoginFaild();
                        btn_Login.IsEnabled = true;
                    }
                }
                else
                {
                    await DisplayAlert("Thông báo", error.IDErrorToNotify(tk.Error), "OK");

                    btn_Login.IsEnabled = true;
                }
            }
            else
            {
                switch (val)
                {
                case 1:
                {
                    await DisplayAlert("Thông báo", "Vui Lòng nhập TÀI KHOẢN", "OK");

                    Entry_Username.Focus();
                    break;
                }

                case 2:
                {
                    await DisplayAlert("Thông báo", "Vui Lòng nhập MẬT KHẨU", "OK");

                    Entry_Password.Focus();
                    break;
                }

                default:
                {
                    break;
                }
                }
                btn_Login.IsEnabled = true;
            }
        }
Пример #7
0
        public RegisterPage()
        {
            InitializeComponent();
            if (Device.RuntimePlatform == Device.iOS)
            {
                ((NavigationPage)Application.Current.MainPage).BarBackgroundColor = Color.FromHex("#f37a3f");
                ((NavigationPage)Application.Current.MainPage).BarTextColor       = Color.White;
            }
            SetActivityIndicatorState(false);
            Entry_Registration_Key.Completed  += (s, e) => Entry_Username.Focus();
            Entry_Username.Completed          += (s, e) => Entry_Password.Focus();
            Entry_Password.Completed          += (s, e) => Entry_Password_Confirm.Focus();
            Entry_Password_Confirm.Completed  += (s, e) => Entry_First_Name.Focus();
            Entry_First_Name.Completed        += (s, e) => Entry_Last_Name.Focus();
            Entry_Last_Name.Completed         += (s, e) => GenderPicker.Focus();
            GenderPicker.SelectedIndexChanged += (s, e) =>
            {
                if (GenderPicker.SelectedIndex == -1)
                {
                    return;
                }
                else
                {
                    string profileTypeName = ProfileTypePicker.Items[ProfileTypePicker.SelectedIndex];
                    string profileTypeId   = ProfileTypes[profileTypeName];
                    if (profileTypeId.Equals("interpreter"))
                    {
                        Entry_Email.Focus();
                    }
                    else
                    {
                        NativeLanguagePicker.Focus();
                    }
                }
            };
            NativeLanguagePicker.SelectedIndexChanged += (s, e) => Entry_Email.Focus();
            Entry_Email.Completed        += (s, e) => Entry_Phone_Number.Focus();
            Entry_Phone_Number.Completed += (s, e) => Entry_Address.Focus();
            Entry_Address.Completed      += (s, e) => Entry_City.Focus();
            Entry_City.Completed         += (s, e) => Entry_Province.Focus();
            Entry_Province.Completed     += (s, e) => Entry_Zip_Code.Focus();

            foreach (String profileTypeName in ProfileTypes.Keys)
            {
                ProfileTypePicker.Items.Add(profileTypeName);
            }

            ProfileTypePicker.SelectedIndexChanged += (sender, args) =>
            {
                if (ProfileTypePicker.SelectedIndex == -1)
                {
                    return;
                }
                else
                {
                    string profileTypeName = ProfileTypePicker.Items[ProfileTypePicker.SelectedIndex];
                    string profileTypeId   = ProfileTypes[profileTypeName];
                    RegistrationLabel.IsVisible      = profileTypeId.Equals("interpreter") ? true : false;
                    Entry_Registration_Key.IsVisible = profileTypeId.Equals("interpreter") ? true : false;
                    LanguagePickerLabel.IsVisible    = profileTypeId.Equals("client") ? true : false;
                    NativeLanguagePicker.IsVisible   = profileTypeId.Equals("client") ? true : false;
                }
            };
            foreach (String genderName in Genders.Keys)
            {
                GenderPicker.Items.Add(genderName);
            }

            Languages = new ObservableCollection <LanguageModel>();
            LoadLanguagesAsync();

            this.BindingContext = this;
        }
Пример #8
0
        public RegisterPage()
        {
            InitializeComponent();
            SetActivityIndicatorState(false);
            Entry_Registration_Key.Completed  += (s, e) => Entry_Username.Focus();
            Entry_Username.Completed          += (s, e) => Entry_Password.Focus();
            Entry_Password.Completed          += (s, e) => Entry_Password_Confirm.Focus();
            Entry_Password_Confirm.Completed  += (s, e) => Entry_First_Name.Focus();
            Entry_First_Name.Completed        += (s, e) => Entry_Last_Name.Focus();
            Entry_Last_Name.Completed         += (s, e) => GenderPicker.Focus();
            GenderPicker.SelectedIndexChanged += (s, e) =>
            {
                if (GenderPicker.SelectedIndex == -1)
                {
                    return;
                }
                else
                {
                    string profileTypeName = ProfileTypePicker.Items[ProfileTypePicker.SelectedIndex];
                    string profileTypeId   = ProfileTypes[profileTypeName];
                    if (profileTypeId.Equals("interpreter"))
                    {
                        Entry_Email.Focus();
                    }
                    else
                    {
                        NativeLanguagePicker.Focus();
                    }
                }
            };
            NativeLanguagePicker.SelectedIndexChanged += (s, e) => Entry_Email.Focus();
            Entry_Email.Completed        += (s, e) => Entry_Phone_Number.Focus();
            Entry_Phone_Number.Completed += (s, e) => Entry_Address.Focus();
            Entry_Address.Completed      += (s, e) => Entry_City.Focus();
            Entry_City.Completed         += (s, e) => Entry_Province.Focus();
            Entry_Province.Completed     += (s, e) => Entry_Zip_Code.Focus();

            foreach (String profileTypeName in ProfileTypes.Keys)
            {
                ProfileTypePicker.Items.Add(profileTypeName);
            }

            ProfileTypePicker.SelectedIndexChanged += (sender, args) =>
            {
                if (ProfileTypePicker.SelectedIndex == -1)
                {
                    return;
                }
                else
                {
                    string profileTypeName = ProfileTypePicker.Items[ProfileTypePicker.SelectedIndex];
                    string profileTypeId   = ProfileTypes[profileTypeName];
                    Lbl_Registration_Key.IsVisible   = profileTypeId.Equals("interpreter") ? true : false;
                    Entry_Registration_Key.IsVisible = profileTypeId.Equals("interpreter") ? true : false;
                    Lbl_NativeLanguage.IsVisible     = profileTypeId.Equals("client") ? true : false;
                    NativeLanguagePicker.IsVisible   = profileTypeId.Equals("client") ? true : false;
                }
            };
            foreach (String genderName in Genders.Keys)
            {
                GenderPicker.Items.Add(genderName);
            }

            Languages = new ObservableCollection <LanguageModel>();
            LoadLanguagesAsync();

            this.BindingContext = this;
        }