Example #1
0
        async void Login_Clicked(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(Usuario.Text))
            {
                await DisplayAlert("", "Por favor, indique el número de CUI de su DPI", "Aceptar");

                Usuario.Focus();
                return;
            }
            else if (Usuario.Text.Length < 15)
            {
                await DisplayAlert("", "Por favor, indique un número de CUI válido", "Aceptar");

                Usuario.Focus();
                return;
            }
            if (String.IsNullOrEmpty(Contrasenia.Text))
            {
                await DisplayAlert("", "Por favor, indique su contraseña", "Aceptar");

                Contrasenia.Focus();
                return;
            }
            string CUI = Regex.Replace(Usuario.Text, @"\s+", "");

            System.Diagnostics.Debug.WriteLine(CUI);
            await Navigation.PushPopupAsync(new NotificacionCargando());

            await Navigation.PushPopupAsync(new LoginVerificacion("1850"));
        }
        public NewPasswordViewModel(Contrasenia newPassword)
        {
            this.currentObject   = newPassword;
            this.validProperties = new Dictionary <string, bool>();
            this.validProperties.Add("CurrentPassword", false);
            //this.validProperties.Add("Height", false);
            //this.validProperties.Add("Width", false);

            //this.currentObject.
            //  Password.ActualWidth = 5;
            //newPassword.
            //Password.
        }
Example #3
0
        public async void Login()
        {
            if (String.IsNullOrEmpty(Usuario.Text))
            {
                await DisplayAlert("", "Por favor, indique su usuario/carné", "Aceptar");

                Usuario.Focus();
                return;
            }

            if (String.IsNullOrEmpty(Contrasenia.Text))
            {
                await DisplayAlert("", "Por favor, indique su contraseña", "Aceptar");

                Contrasenia.Focus();
                return;
            }
            this.IsBusy     = true;
            login.IsEnabled = false;
            login.IsVisible = false;

            Login peticion = new Login
            {
                username = Usuario.Text.Trim(),
                password = Contrasenia.Text.Trim().Replace("&", "%26")
            };
            List <UsuarioRespuesta> Session = new List <UsuarioRespuesta>();

            Session = await App.ManejadorDatos.LoginAsync(peticion);

            bool isEmpty = !Session.Any();

            if (isEmpty)
            {
                ShowToast(ToastNotificationType.Error, "Verifique sus datos de inicio de sesión", "Los datos de acceso proporcionados son erroneos.", 5);
                login.IsVisible = true;
                login.IsEnabled = true;
                this.IsBusy     = false;
            }
            else
            {
                confirmUser peticion1 = new confirmUser
                {
                    username = Usuario.Text.Trim()
                };
                String Session1 = String.Empty;
                Session1 = await App.ManejadorDatos.confirmUserAsync(peticion1);

                if (String.IsNullOrEmpty(Session1))
                {
                    ShowToast(ToastNotificationType.Error, "Tenemos problemas en verificar tu cuenta.", "Inténtalo de nuevo más tarde o contáctanos.", 5);
                    login.IsVisible = true;
                    login.IsEnabled = true;
                    this.IsBusy     = false;
                    return;
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("llego aca");
                    if (Session1.Equals("1"))
                    {
                        foreach (var session in Session)
                        {
                            ShowToast(ToastNotificationType.Success, "¡Bienvenido!", "Has iniciado sesión correctamente.", 7);
                            Settings.session_access_token  = session.access_token;
                            Settings.session_token_type    = session.token_type;
                            Settings.session_refresh_token = session.refresh_token;
                            Settings.session_expires_in    = session.expires_in;
                            Settings.session_scope         = session.scope;
                            Settings.session_carne         = Usuario.Text.Trim();

                            if (Usuario.Text.Trim().Contains("-"))
                            {
                                Settings.session_role = "E";
                            }
                            else
                            {
                                Settings.session_role = "C";
                            }

                            MessagingCenter.Send <InicioSesion>(this, "Autenticado");
                        }
                    }
                    else
                    {
                        content_ingreso.IsVisible = false;
                        await Navigation.PushPopupAsync(new CambioContrasenia(Usuario.Text.Trim(), Contrasenia.Text.Trim()));
                    }
                }
            }
        }
Example #4
0
        public InicioSesion()
        {
            MessagingCenter.Subscribe <CambioContrasenia>(this, "Cambio", (sender) =>
            {
                Usuario.Text     = sender.user;
                Contrasenia.Text = sender.contrasenia.Text.Trim();
            });
            Usuario = new ExtendedEntry()
            {
                AutomationId     = "LoginUser",
                Keyboard         = Keyboard.Text,
                Placeholder      = "USUARIO",
                PlaceholderColor = Color.FromHex("91a5af"),
                FontFamily       = Device.OnPlatform("Montserrat-Regular", "Montserrat-Regular", null),
                TextColor        = Color.FromHex("CDCDCD"),
                BackgroundColor  = Color.Transparent,
                Text             = string.Empty,
                FontSize         = Device.OnPlatform(16, 22, 12),
                HeightRequest    = Device.OnPlatform(40, 50, 12),
                HasBorder        = false,
                Margin           = new Thickness(15, 0),
                VerticalOptions  = LayoutOptions.Center,
                ReturnKeyType    = ReturnKeyTypes.Next
            };
            Usuario.Completed += (sender, e) => { /*Usuario.Unfocus();*/ Contrasenia.Focus(); };
            Contrasenia        = new ExtendedEntry()
            {
                AutomationId     = "LoginPass",
                Placeholder      = "CONTRASEÑA",
                PlaceholderColor = Color.FromHex("91a5af"),
                FontFamily       = Device.OnPlatform("Montserrat-Regular", "Montserrat-Regular", null),
                TextColor        = Color.FromHex("CDCDCD"),
                BackgroundColor  = Color.Transparent,
                Text             = string.Empty,
                FontSize         = Device.OnPlatform(16, 22, 12),
                HeightRequest    = Device.OnPlatform(40, 50, 12),
                HasBorder        = false,
                Margin           = new Thickness(15, 0),
                VerticalOptions  = LayoutOptions.Center,
                IsPassword       = true,
                ReturnKeyType    = ReturnKeyTypes.Go
            };
            Contrasenia.Completed += (sender, e) => { Contrasenia.Unfocus(); Login(); };

            var ingreso = new StackLayout
            {
                Orientation       = StackOrientation.Vertical,
                Padding           = new Thickness(20, 0),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Spacing           = 10,
                Children          =
                {
                    //Usuario,
                    new Grid
                    {
                        HeightRequest     = Device.OnPlatform(40, 50, 12),
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children          =
                        {
                            new RoundedBoxView.Forms.Plugin.Abstractions.RoundedBoxView
                            {
                                BackgroundColor   = Color.Transparent,
                                BorderThickness   = 2,
                                CornerRadius      = 20,
                                BorderColor       = Color.FromHex("94a8c1"),
                                HeightRequest     = Device.OnPlatform(40, 50, 12),
                                HorizontalOptions = LayoutOptions.FillAndExpand,
                            },
                            Usuario
                        },
                    },
                    new Grid
                    {
                        HeightRequest = Device.OnPlatform(40, 50, 12),
                        Children      =
                        {
                            new RoundedBoxView.Forms.Plugin.Abstractions.RoundedBoxView
                            {
                                BackgroundColor = Color.Transparent,
                                BorderThickness = 2,
                                CornerRadius    = 20,
                                BorderColor     = Color.FromHex("94a8c1"),
                                HeightRequest   = Device.OnPlatform(40, 50, 12),
                                //WidthRequest = 128,
                            },
                            Contrasenia
                        },
                    }
                }
            };
            var fIngreso = new Frame
            {
                WidthRequest      = 300,
                Padding           = new Thickness(0, 0, 0, 0),
                BackgroundColor   = Color.Transparent,
                OutlineColor      = Color.Transparent,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                HasShadow         = false,
                Content           = ingreso
            };

            var logo = new Image
            {
                Source            = "logo.png",
                HorizontalOptions = LayoutOptions.Center,
                Margin            = new Thickness(50, 0)
            };

            content_ingreso = new StackLayout
            {
                VerticalOptions = LayoutOptions.CenterAndExpand,
                Spacing         = 25,
                Children        = { logo, fIngreso }
            };

            login = new Button
            {
                AutomationId      = "Login",
                Text              = "INGRESAR",
                TextColor         = Color.FromHex("3E1152"),
                FontFamily        = Device.OnPlatform("Montserrat-Bold", "Montserrat-Bold", null),
                FontSize          = 15,
                HorizontalOptions = LayoutOptions.Center,
                BackgroundColor   = Color.FromHex("ffffff"),
                WidthRequest      = 200,
                HeightRequest     = 35,
                BorderRadius      = 20
            };
            login.Clicked += Login_Clicked;


            var indicador = new ActivityIndicator
            {
                IsVisible         = true,
                IsRunning         = true,
                BindingContext    = this,
                Color             = Color.FromHex("f7efd9"),
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            indicador.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");

            forget = new Label
            {
                Text       = "Recuperar contraseña.",
                TextColor  = Color.FromHex("f7efd9"),
                FontFamily = Device.OnPlatform("Montserrat-Regular", "Montserrat-Regular", null),
                FontSize   = 14,
                //Margin = new Thickness(0, 0, 0, 40),
                //VerticalOptions = LayoutOptions.EndAndExpand,
                HorizontalOptions = LayoutOptions.Center
            };

            contactenos = new Label
            {
                //https://goo.gl/yAnQD4
                //https://waze.com/ul?ll=14.52459,-90.76137
                Text              = "¿Tienes dudas? contáctanos.",
                TextColor         = Color.FromHex("f7efd9"),
                FontFamily        = Device.OnPlatform("Montserrat-Regular", "Montserrat-Regular", null),
                FontSize          = 14,
                Margin            = new Thickness(0, 0, 0, 40),
                VerticalOptions   = LayoutOptions.EndAndExpand,
                HorizontalOptions = LayoutOptions.Center
            };
            var tap2 = new TapGestureRecognizer();

            tap2.Tapped += (s, e) =>
            {
                Device.OpenUri(new Uri("https://goo.gl/F2LzXD"));
            };
            contactenos.GestureRecognizers.Add(tap2);


            var tap = new TapGestureRecognizer();

            tap.Tapped += (s, e) => Forget_Clicked();
            forget.GestureRecognizers.Add(tap);

            var acceso = new StackLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Spacing         = 15,
                Children        = { new Grid {
                                        Children =  { indicador,login }
                                    }, forget, contactenos }
            };

            BackgroundImage = "fondo.png";
            Content         = new ScrollView
            {
                Content =
                    new StackLayout
                {
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    Spacing         = 20,
                    Padding         = new Thickness(0, 20, 0, 0),
                    Children        = { content_ingreso, acceso }
                }
            };
        }
Example #5
0
        private async void Login_Clicked(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(Usuario.Text))
            {
                await DisplayAlert("", "Por favor, indique su correo electrónico ", "Aceptar");

                Usuario.Focus();
                return;
            }
            else
            {
                if (!Regex.Match(Usuario.Text, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Success)
                {
                    await DisplayAlert("", "Por favor, indique una dirección de correo electrónico válida", "Aceptar");

                    Usuario.Focus();
                    return;
                }
            }
            if (String.IsNullOrEmpty(Contrasenia.Text))
            {
                await DisplayAlert("", "Por favor, indique su contraseña", "Aceptar");

                Contrasenia.Focus();
                return;
            }
            this.IsBusy     = true;
            login.IsEnabled = false;
            login.IsVisible = false;

            Login peticion = new Login
            {
                username = Usuario.Text,
                password = getContrasenia()
            };
            LoginResponse Session = new LoginResponse();

            Session = await App.ManejadorDatos.LoginAsync(peticion);

            if (Session == null)
            {
                ShowToast(ToastNotificationType.Error, "Inconvenientes de conexión", "Lo lamentamos, existen inconvenientes en la conexión; intente más tarde.", 7);
                login.IsVisible = true;
                login.IsEnabled = true;
                this.IsBusy     = false;
            }
            else if (string.IsNullOrEmpty(Session.access_token))
            {
                ShowToast(ToastNotificationType.Error, "Verifique sus datos de inicio de sesión", "A ocurrido algo inesperado en el inicio de sesión", 5);
                login.IsVisible = true;
                login.IsEnabled = true;
                this.IsBusy     = false;
            }
            else
            {
                Settings.session_access_token = Session.access_token;
                Settings.session_expires_in   = Session.expires_in.ToString();
                Settings.session_username     = Session.user.username;
                Settings.session_authority    = Session.user.authorities[0].authority;
                usuarios usuario = App.Database.GetUser(peticion.username);
                if (usuario == null)
                {
                    usuario = new usuarios
                    {
                        email = peticion.username
                    };
                    Logeado = false;
                }
                else
                {
                    Logeado = true;
                }
                usuario.idUsuario             = Session.user.id;
                usuario.fechaUltimoInicio     = DateTime.Now.ToString();
                usuario.username              = Settings.session_username;
                usuario.firstName             = Session.user.firstName;
                usuario.lastName              = Session.user.lastName;
                usuario.phoneNumber           = Session.user.phoneNumber;
                usuario.enabled               = Session.user.enabled;
                usuario.lastPasswordResetDate = Session.user.lastPasswordResetDate;
                usuario.genero       = Session.user.genero;
                usuario.idPuesto     = Session.puesto.idPuesto;
                usuario.nombrePuesto = Session.puesto.nombre;
                var res = App.Database.InsertUsuario(usuario);
                if (!Logeado)
                {
                    usuario = App.Database.GetUser(peticion.username);
                }
                Settings.session_idUsuario = usuario.id.ToString();

                empresas empresa = App.Database.GetEmpresa(Session.empresa.id);
                if (empresa == null)
                {
                    empresa = new empresas
                    {
                        idEmpresa = Session.empresa.id
                    };
                    Logeado = false;
                }
                else
                {
                    Logeado = true;
                }

                empresa.nombre              = Session.empresa.nombre;
                empresa.direccion           = Session.empresa.direccion;
                empresa.numeroColaboradores = Session.empresa.numeroColaboradores;
                empresa.telefono            = Session.empresa.telefono;
                empresa.logo        = Session.empresa.logo;
                empresa.descripcion = Session.empresa.descripcion;
                empresa.status      = Session.empresa.status;
                res = App.Database.InsertEmpresa(empresa);
                if (!Logeado)
                {
                    empresa = App.Database.GetEmpresa(Session.empresa.id);
                }
                Settings.session_idEmpresa     = empresa.idEmpresa.ToString();
                Settings.session_nombreEmpresa = empresa.nombre;

                this.IsBusy = false;
                MessagingCenter.Send <LoginPage>(this, "Autenticado");
            }
        }