Ejemplo n.º 1
0
        private void AltaUsuario()
        {
            try
            {
                int returnValue       = 0;
                var digitoVerificador = HelperEncrypt.GeneratePassword(10);

                Usuario usuario = new Usuario(tbUsuario.Text.Trim(),
                                              tbDocumento.Text.Trim(),
                                              tbNombre.Text.Trim(),
                                              cbSector.SelectedIndex,
                                              HelperEncrypt.EncodePassword(tbContraseña.Text.Trim(), digitoVerificador),
                                              cbIdioma.SelectedIndex,
                                              digitoVerificador,
                                              "A");

                returnValue = UsuarioBLL.Insert(usuario);

                if (returnValue != 0)
                {
                    if (DialogResult.OK == MessageBox.Show("Usuario guardado exitosamente.", "Residica", MessageBoxButtons.OK))
                    {
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Ha ocurrido un error al guardar el Miembro.", "Residica", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Residica", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        private void btnDesbloquear_Click(object sender, EventArgs e)
        {
            try
            {
                if (tbContraseñaActual.Text.Length >= 3)
                {
                    Usuario usuario = UsuarioBLL.GetAdapted(tbUsuario.Text.Trim());
                    usuario.Password = HelperEncrypt.EncodePassword(tbContraseñaActual.Text, usuario.DigitoVerificador);
                    usuario.Estado   = "A";
                    UsuarioBLL.Update_Desbloqueo(usuario);
                    BitacoraBLL.GetInstance().RegistrarEnBitacora("Desbloqueo de usuario", User._userSession.NombreUsuario, string.Empty, System.Diagnostics.TraceEventType.Information);
                    MessageBox.Show("Usuario desbloqueado correctamente", "Residica", MessageBoxButtons.OK, MessageBoxIcon.None);

                    tbUsuario.Clear();
                    tbContraseñaActual.Clear();
                    btnDesbloquear.Enabled     = false;
                    tbContraseñaActual.Enabled = false;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("La contraseña debe contener como mínimo 3 caracteres.", "Residica", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Residica", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
 private void btnAceptar_Click(object sender, EventArgs e)
 {
     try
     {
         if (Validaciones())
         {
             if ((UsuarioBLL.Validar(User._userSession.NombreUsuario, User._userSession.Password) != 0))
             {
                 if (tbNuevaContraseña.Text.Length >= 3 && tbRepetirContraseña.Text.Length >= 3)
                 {
                     if (tbNuevaContraseña.Text == tbRepetirContraseña.Text)
                     {
                         Usuario usuario = UsuarioBLL.GetAdapted(User._userSession.IdUsuario);
                         usuario.Password = HelperEncrypt.EncodePassword(tbNuevaContraseña.Text, usuario.DigitoVerificador);
                         usuario.Estado   = "A";
                         UsuarioBLL.Update_Desbloqueo(usuario);
                         BitacoraBLL.GetInstance().RegistrarEnBitacora("Cambio de contraseña", User._userSession.NombreUsuario, string.Empty, TraceEventType.Information);
                         MessageBox.Show("Cambio de contraseña exitoso", "Residica", MessageBoxButtons.OK, MessageBoxIcon.None);
                         this.Close();
                     }
                     else
                     {
                         MessageBox.Show("Las contraseñas no coinciden.", "Residica", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                     }
                 }
                 else
                 {
                     MessageBox.Show("Las contraseñas deben tener como mínimo 3 caracteres.", "Residica", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Residica", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 4
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (model.Domain == "SUPPERADMIN")
                {
                    using (var dbConn = Helpers.OrmliteConnection.openConn())
                    {
                        var existUser = dbConn.SingleOrDefault <User>("ma_nguoi_dung ={0} and mat_khau ={1} and trang_thai = 'true'", model.UserName, Helpers.GetMd5Hash.Generate(model.Password));
                        if (existUser != null)
                        {
                            SetupFormsAuthTicket(model.UserName, model.RememberMe);
                            return(RedirectToAction("Index", "admin/Home"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng.");
                        }
                        //var passadmin = System.Configuration.ConfigurationManager.AppSettings["passAdmin"].ToString().Trim();
                        //if (model.Password == passadmin)
                        //{
                        //    //Code giành cho đăng nhập bằng pass admin
                        //    var userpasadmin = dbConn.SingleOrDefault<Users>("UserName = {0} ", model.UserName);
                        //    if (userpasadmin != null)
                        //    {
                        //        SetupFormsAuthTicket(model.UserName, model.RememberMe);
                        //        var employeeinfoa = dbConn.FirstOrDefault<EmployeeInfo>("UserName ={0}", userpasadmin.UserName);
                        //        return RedirectToLocal(returnUrl);
                        //    }
                        //    else
                        //        ModelState.AddModelError("", "Invalid username or password.");
                        //}

                        //var user = dbConn.SingleOrDefault<Users>("UserName = {0} AND Password = {1} AND Active = 1", model.UserName, Helpers.GetMd5Hash.Generate(model.Password));
                        //if (user != null)
                        //{
                        //    //code đăng nhập bình thường
                        //    SetupFormsAuthTicket(model.UserName, model.RememberMe);
                        //    var employeeinfo = dbConn.FirstOrDefault<EmployeeInfo>("UserName ={0}", user.UserName);
                        //    return RedirectToLocal(returnUrl);
                        //}
                        //else
                        //    ModelState.AddModelError("", "Invalid username or password.");
                    }
                }
                else
                {
                    try
                    {
                        using (var client = new HttpClient())
                        {
                            // New code:
                            var apiserver = System.Configuration.ConfigurationManager.AppSettings["apiServer"].ToString().Trim();
                            var userNameE = HelperEncrypt.Encrypt(HelperEncrypt.GetHashKey(HelperEncrypt.passSalt), model.UserName);
                            var passWordE = HelperEncrypt.Encrypt(HelperEncrypt.GetHashKey(HelperEncrypt.passSalt), model.Password);
                            var domainE   = HelperEncrypt.Encrypt(HelperEncrypt.GetHashKey(HelperEncrypt.passSalt), model.Domain);
                            var apiUrl    = apiserver + "//api//Authentication//checkAuthenticate?domain=" + domainE + "&userName="******"&passWord="******"\"", "")) == "success" ? true : false;
                            if (!isSuccessAuthenticate)
                            {
                                ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng.");
                                return(View(model));
                            }
                            using (var dbConn = Helpers.OrmliteConnection.openConn())
                            {
                                var existUser = dbConn.SingleOrDefault <User>("ma_nguoi_dung ={0} and trang_thai = 'true'", model.UserName);
                                if (existUser != null)
                                {
                                    SetupFormsAuthTicket(model.UserName, model.RememberMe);
                                    return(RedirectToLocal(returnUrl));
                                }
                                else
                                {
                                    ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng.");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", "Không thể kết nối đến domain");
                    }
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 5
0
        private void btn_Acceder_Click(object sender, EventArgs e)
        {
            try
            {
                int IdUsuario = 0;
                if (tB_Usuario.Text != "Username")
                {
                    if (tB_Contraseña.Text != "Password")
                    {
                        if (UsuarioBLL.Existe(this.tB_Usuario.Text))
                        {
                            string auxIntentos = tB_Usuario.Text;
                            if (usuarioIngresado.Length == 0)
                            {
                                usuarioIngresado = auxIntentos;
                            }

                            Usuario usuario = UsuarioBLL.GetAdapted(tB_Usuario.Text.Trim());
                            IdUsuario = UsuarioBLL.Validar(this.tB_Usuario.Text, HelperEncrypt.EncodePassword(this.tB_Contraseña.Text, usuario.DigitoVerificador)); //this.tB_Contraseña.Text);//

                            if (!UsuarioBLL.Bloqueado(this.tB_Usuario.Text))
                            {
                                if (IdUsuario == 0)
                                {
                                    if (usuarioIngresado == auxIntentos)
                                    {
                                        intentos = intentos + 1;
                                        MessageBox.Show("Logueo incorrecto.", "Residica", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                    else
                                    {
                                        usuarioIngresado = string.Empty;
                                    }

                                    if (intentos == 3)
                                    {
                                        UsuarioBLL.Bloquear(usuarioIngresado);
                                        BitacoraBLL.GetInstance().RegistrarEnBitacora("Usuario bloqueado por mas de 3 intentos.", /*User._userSession.NombreUsuario*/ usuario.NombreUsuario, string.Empty, System.Diagnostics.TraceEventType.Information);
                                        MessageBox.Show("El usuario ha sido bloqueado", "Residica", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                }
                                else
                                {
                                    this.tB_Usuario.Clear();
                                    this.tB_Contraseña.Clear();
                                    Menu menu = new Menu();
                                    User._userSession = UsuarioBLL.GetAdapted(IdUsuario);
                                    BitacoraBLL.GetInstance().RegistrarEnBitacora("Nuevo logueo en el sistema.", User._userSession.NombreUsuario, string.Empty, System.Diagnostics.TraceEventType.Information);

                                    menu.Show();
                                    this.Hide();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Usuario bloqueado.", "Residica", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Usuario no registrado.", "Residica", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        mensajeerror("Please enter Password");
                    }
                }
                else
                {
                    mensajeerror("Please enter Username");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ha ocurrido un error: " + ex.Message, "Residica", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            void mensajeerror(string msg)
            {
                lb_ErrorMessage.Text    = msg;
                lb_ErrorMessage.Visible = true;
            }
        }
Ejemplo n.º 6
0
        private void btOK_Click(object sender, EventArgs e)
        {
            if (radioGroupTrial.SelectedIndex == 1)
            {
                //- Check selected license file complete?
                // If complete, to check enter license key.
                // If not, show warning message box screen 1022.

                // - Check enter licensed key completed?
                // If complete, to check validate license file and license key.
                // If not, show warning message box screen 1023.

                // - Check validates license file and license key?
                // If valid, show information message box screen 3018, load data from license file to database and show screen 2801-2.
                // If not valid, show warning message box screen 1024.

                if (textEditFile.EditValue == null)
                {
                    utilClass.showPopupMessegeBox(this, getLanguage("_msg_1022"), this.Text);
                    return;
                }

                if (textEditKey1.EditValue != null && textEditKey2.EditValue != null && textEditKey3.EditValue != null && textEditKey4.EditValue != null)
                {
                    string TextKey = textEditKey1.EditValue.ToString() + "-" + textEditKey2.EditValue.ToString() + "-" + textEditKey3.EditValue.ToString() + "-" + textEditKey4.EditValue.ToString();
                    if (TextKey == MainForm.LicObj.LicenseKey)
                    {
                        BusinessLogicBridge.DataStore.updateLicenceKey(MainForm.LicObj.LicenseKey);

                        DataTable GeneralPath = BusinessLogicBridge.DataStore.getGeneralConfig();

                        string dataPath = MainForm.CombinePaths(AppDomain.CurrentDomain.BaseDirectory, "Licence");

                        if (Directory.Exists(dataPath) == false)
                        {
                            Directory.CreateDirectory(dataPath);
                        }

                        try
                        {
                            string descnationfile = Path.Combine(dataPath, "regkey.lic");
                            System.IO.File.Copy(textEditFile.EditValue.ToString(), descnationfile, true);
                            objMEATHLicense LicObj = new objMEATHLicense();
                            LicObj = MainForm.readLicense(descnationfile);
                            BusinessLogicBridge.DataStore.updateADCSerial(LicObj.ADCSN1, LicObj.ADCSN2, LicObj.ADCSN3, LicObj.ADCSN4, LicObj.ADCSN5);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString());
                        }

                        utilClass.showPopupMessegeBox(this, getLanguage("_msg_3018"), this.Text, "info");

                        MainForm.TrialVersion = false;
                        MainForm.HaveLicence  = true;
                        this.DialogResult     = DialogResult.OK;
                    }
                    else
                    {
                        utilClass.showPopupMessegeBox(this, getLanguage("_msg_1024"), this.Text);
                        this.DialogResult = DialogResult.Cancel;
                    }
                }
                else
                {
                    utilClass.showPopupMessegeBox(this, getLanguage("_msg_1023"), this.Text);
                    return;
                }
            }
            else
            {
                // Trial Version
                MainForm.TrialVersion = true;

                string s = BusinessLogicBridge.DataStore.getCheckinCounter();

                if (s == "")
                {
                    s = HelperEncrypt.Encrypt(s, MainForm.hashKey);

                    // Update Counter Checkin
                    BusinessLogicBridge.DataStore.updateCounterCheckin(s);
                }

                this.DialogResult = DialogResult.Ignore;
            }
        }
Ejemplo n.º 7
0
 public Task <SpartanUserListModel> AuthUser(string username, string password)
 {
     return(services.AuthUser(username, HelperEncrypt.EncryptPassword(password)));
 }