示例#1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new BusUser()
                {
                    UserName = model.UserName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> Login(UserModel userModel)
        {
            BusFacCore busFacCore = new BusFacCore(_settings);
            BusUser    busUser    = new BusUser();

            if ((!string.IsNullOrEmpty(userModel.Username)) && (!string.IsNullOrEmpty(userModel.Password)) &&
                (busUser.IsValidUsername(userModel.Username)) && (busUser.IsValidPasswd(userModel.Password)))
            {
                bool UserExist = busFacCore.Exist(userModel.Username);
                if (UserExist)
                {
                    User user = busFacCore.UserAuthenticate(userModel.Username, userModel.Password);
                    if ((user != null) && (user.UserID > 0))
                    {
                        var claims = new[] {
                            new Claim("name", userModel.Username)
                        };

                        var principal = new ClaimsPrincipal(
                            new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme));

                        await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal);

                        return(RedirectToAction("Index", "Dashboard"));
                    }
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
示例#3
0
        /// <summary>
        /// UserGet
        /// </summary>
        /// <param name="">pLngUserID</param>
        /// <returns>User</returns>
        ///
        public User UserGet(long pLngUserID)
        {
            User user = new User()
            {
                UserID = pLngUserID
            };
            bool          bConn = false;
            SqlConnection conn  = getDBConnection();

            if (conn != null)
            {
                BusUser busUser = null;
                busUser = new BusUser(conn);
                busUser.Load(user);
                // close the db connection
                bConn     = CloseConnection(conn);
                _hasError = busUser.HasError;
                if (busUser.HasError)
                {
                    // error
                    ErrorCode error = new ErrorCode();
                }
            }
            return(user);
        }
示例#4
0
        private async Task SignInAsync(BusUser user, bool isPersistent)
        {
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
            var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = isPersistent
            }, identity);
        }
示例#5
0
        public async Task <IActionResult> Register(UserModel userModel)
        {
            try
            {
                BusFacCore      busFacCore      = new BusFacCore(_settings);
                UtilsValidation utilsValidation = new UtilsValidation();
                BusUser         busUser         = new BusUser();
                if ((!string.IsNullOrEmpty(userModel.Username)) && (!string.IsNullOrEmpty(userModel.Password)) &&
                    (utilsValidation.IsValidEmail(userModel.Username)) && (busUser.IsValidPasswd(userModel.Password)))
                {
                    if (!(userModel.Password.Equals(userModel.ConfirmPassword, StringComparison.Ordinal)))
                    {
                        ViewData["PasswordMatch"] = true;
                    }
                    else
                    {
                        bool UserExist = busFacCore.Exist(userModel.Username);
                        if (!UserExist)
                        {
                            User user = busFacCore.UserCreate(userModel.Username, userModel.Password);
                            if ((user != null) && (user.UserID > 0))
                            {
                                var claims = new[] {
                                    new Claim("name", userModel.Username)
                                };

                                var principal = new ClaimsPrincipal(
                                    new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme));

                                await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal);

                                return(RedirectToAction("Index", "Dashboard"));
                            }
                            else
                            {
                                ViewData["HasError"] = true;
                            }
                        }
                        else
                        {
                            ViewData["UserExist"] = true;
                        }
                    }
                }
                else
                {
                    ViewData["InvalidCredentials"] = true;
                }
            }
            catch (Exception ex)
            {
                ViewData["HasError"] = true;
            }
            return(RedirectToAction("Index", "Home"));
        }
示例#6
0
        private void DibujarLogin()
        {
            try
            {
                User u = new User();
                u.Usuario    = "";
                u.Contraseña = "";

                List <User> lstUser = new BusUser().getUsersList(u);
                foreach (var item in lstUser)
                {
                    Label      label   = new Label();
                    Panel      panel   = new Panel();
                    PictureBox picture = new PictureBox();

                    label.Text      = item.Usuario;
                    label.Name      = item.Id.ToString();
                    label.Size      = new Size(175, 25);
                    label.Font      = new Font("Microsoft Sans Serif", 13);
                    label.FlatStyle = FlatStyle.Flat;
                    label.BackColor = Color.FromArgb(176, 196, 222);
                    label.ForeColor = Color.Black;
                    label.Dock      = DockStyle.Bottom;
                    label.TextAlign = ContentAlignment.MiddleCenter;
                    label.Cursor    = Cursors.Hand;

                    panel.Size        = new Size(90, 90);
                    panel.BorderStyle = BorderStyle.None;
                    panel.Dock        = DockStyle.Top;
                    panel.BackColor   = Color.FromArgb(176, 196, 222);

                    picture.Size            = new Size(80, 80);
                    picture.Dock            = DockStyle.Top;
                    picture.BackgroundImage = null;
                    byte[]       b  = item.Foto;
                    MemoryStream ms = new MemoryStream(b);
                    picture.Image    = Image.FromStream(ms);
                    picture.SizeMode = PictureBoxSizeMode.Zoom;
                    picture.Tag      = item.Usuario;
                    picture.Cursor   = Cursors.Hand;

                    panel.Controls.Add(label);
                    panel.Controls.Add(picture);
                    label.BringToFront();
                    flowLayoutPanelUsuarios.Controls.Add(panel);

                    label.Click   += new EventHandler(myLabelEvent);
                    picture.Click += new EventHandler(myPictureEvent);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#7
0
        public async Task <ActionResult> Create(CreateUserViewModels userViewModels, params string[] selectedRoles)
        {
            if (ModelState.IsValid)
            {
                var appDbContext = HttpContext.GetOwinContext().Get <ApplicationDbContext>();
                using (var transaction = appDbContext.Database.BeginTransaction())
                {
                    try
                    {
                        var user = new BusUser
                        {
                            UserName     = userViewModels.UserName,
                            Email        = userViewModels.Email,
                            PasswordHash = userViewModels.Password,
                            PhoneNumber  = userViewModels.PhoneNumber
                        };
                        var adminresult = await UserManager.CreateAsync(user, userViewModels.Password);

                        if (adminresult.Succeeded)
                        {
                            if (selectedRoles != null)
                            {
                                var result = await UserManager.AddToRolesAsync(user.Id, selectedRoles);

                                if (!result.Succeeded)
                                {
                                    ModelState.AddModelError("", "Failed to add roles");
                                    ViewBag.RolesList = new SelectList(await RoleManager.Roles.ToListAsync(), "Name", "Name", "Admin");
                                    transaction.Rollback();
                                    return(View());
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "UserName is exists");
                            ViewBag.RolesList = new SelectList(RoleManager.Roles, "Name", "Name", "Admin");
                            transaction.Rollback();
                            return(View());
                        }
                        transaction.Commit();
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception)
                    {
                        ModelState.AddModelError("", "Have an error when created user");
                        transaction.Rollback();
                        return(null);
                    }
                }
            }
            ViewBag.RolesList = new SelectList(RoleManager.Roles, "Name", "Name", "Admin");
            return(View());
        }
示例#8
0
 private void Listar_Usuarios()
 {
     try
     {
         List <User> lstUsuarios = new BusUser().ListarUsuarios();
         EstadoConexion = "CONECTADO";
     }
     catch (Exception)
     {
         EstadoConexion = "-";
         // MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#9
0
 public async Task <IActionResult> Register(UserModel userModel)
 {
     try
     {
         BusFacCore      busFacCore      = new BusFacCore(_settings);
         UtilsValidation utilsValidation = new UtilsValidation();
         BusUser         busUser         = new BusUser();
         if ((!string.IsNullOrEmpty(userModel.Username)) && (!string.IsNullOrEmpty(userModel.Password)) &&
             (utilsValidation.IsValidEmail(userModel.Username)) && (busUser.IsValidPasswd(userModel.Password)))
         {
             if (!(userModel.Password.Equals(userModel.ConfirmPassword, StringComparison.Ordinal)))
             {
                 ViewData["PasswordMatch"] = true;
             }
             else
             {
                 bool UserExist = busFacCore.Exist(userModel.Username);
                 if (!UserExist)
                 {
                     User user = busFacCore.UserCreate(userModel.Username, userModel.Password);
                     if ((user != null) && (user.UserID > 0))
                     {
                         return(RedirectToAction("Login", userModel));
                     }
                     else
                     {
                         ViewData["HasError"] = true;
                     }
                 }
                 else
                 {
                     ViewData["UserExist"] = true;
                 }
             }
         }
         else
         {
             ViewData["InvalidCredentials"] = true;
         }
     }
     catch (Exception ex)
     {
         ViewData["HasError"] = true;
     }
     return(RedirectToAction("Index"));
 }
示例#10
0
        private void ListarUsuarios()
        {
            User u = new User();
            //u.Usuario = "";
            //u.Contraseña = "";
            List <User> lstUsuarios = new BusUser().getUsersList(u);

            gdvUsuarios.DataSource = lstUsuarios;

            gdvUsuarios.Columns[0].Width    = 15;
            gdvUsuarios.Columns[0].Width    = 15;
            gdvUsuarios.Columns[2].Visible  = false;
            gdvUsuarios.Columns[6].Visible  = false;
            gdvUsuarios.Columns[7].Visible  = false;
            gdvUsuarios.Columns[11].Visible = false;
            gdvUsuarios.Columns[12].Visible = false;
            gdvUsuarios.ClearSelection();

            // DataTablePersonalizado.Multilinea(ref gdvUsuarios);
        }
示例#11
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new BusUser()
                {
                    UserName = model.UserName
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
示例#12
0
        /// <summary>
        /// UserGetList
        /// </summary>
        /// <param name="">pEnumUser</param>
        /// <returns>ArrayList</returns>
        ///
        public ArrayList UserGetList(EnumUser pEnumUser)
        {
            ArrayList     items = null;
            bool          bConn = false;
            SqlConnection conn  = getDBConnection();

            if (conn != null)
            {
                BusUser busUser = null;
                busUser = new BusUser(conn);
                items   = busUser.Get(pEnumUser);
                // close the db connection
                bConn     = CloseConnection(conn);
                _hasError = busUser.HasError;
                if (busUser.HasError)
                {
                    // error
                    ErrorCode error = new ErrorCode();
                }
            }
            return(items);
        }
示例#13
0
        public async Task <IActionResult> Login(UserModel userModel)
        {
            BusFacCore busFacCore = new BusFacCore(_settings);
            BusUser    busUser    = new BusUser();

            if ((!string.IsNullOrEmpty(userModel.Username)) && (!string.IsNullOrEmpty(userModel.Password)) &&
                (busUser.IsValidUsername(userModel.Username)) && (busUser.IsValidPasswd(userModel.Password)))
            {
                bool UserExist = busFacCore.Exist(userModel.Username);
                if (UserExist)
                {
                    User user = busFacCore.UserAuthenticate(userModel.Username, userModel.Password);
                    if ((user != null) && (user.UserID > 0))
                    {
                        userModel.DisplayName = userModel.Username;
                        if ((!string.IsNullOrEmpty(userModel.FirstName)) && (!string.IsNullOrEmpty(userModel.LastName)))
                        {
                            userModel.DisplayName = userModel.LastName + ", " + userModel.FirstName;
                        }

                        var claims = new[] {
                            new Claim("name", userModel.Username),
                            new Claim(ClaimTypes.Name, userModel.DisplayName, ClaimValueTypes.String)
                        };

                        var principal = new ClaimsPrincipal(
                            new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme));

                        await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal);

                        return(RedirectToAction("Index", "Dashboard"));
                    }
                }
            }

            ViewData["InvalidCredentials"] = true;
            return(View("Index"));
        }
示例#14
0
        /// <summary>
        /// UserRemove
        /// </summary>
        /// <param name="">pUserID</param>
        /// <returns>void</returns>
        ///
        public void UserRemove(long pUserID)
        {
            bool bConn = false;

            SqlConnection conn = getDBConnection();

            if (conn != null)
            {
                User user = new User();
                user.UserID = pUserID;
                BusUser bus = null;
                bus = new BusUser(conn);
                bus.Delete(user);
                // close the db connection
                bConn     = CloseConnection(conn);
                _hasError = bus.HasError;
                if (bus.HasError)
                {
                    // error
                    ErrorCode error = new ErrorCode();
                }
            }
        }
示例#15
0
        //------------------------------------------
        /// <summary>
        /// UserCreateOrModify
        /// </summary>
        /// <param name="">pUser</param>
        /// <returns>long</returns>
        ///
        public long UserCreateOrModify(User pUser)
        {
            long          lID   = 0;
            bool          bConn = false;
            SqlConnection conn  = getDBConnection();

            if (conn != null)
            {
                BusUser busUser = null;
                busUser = new BusUser(conn);
                busUser.Save(pUser);
                // close the db connection
                bConn     = CloseConnection(conn);
                lID       = pUser.UserID;
                _hasError = busUser.HasError;
                if (busUser.HasError)
                {
                    // error
                    ErrorCode error = new ErrorCode();
                }
            }
            return(lID);
        }
示例#16
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            List <User> lstUsuarios     = new BusUser().ListarUsuarios();
            int         contadorUsuario = lstUsuarios.Count;
            string      INDICADOR       = DatUser.AUX_CONEXION;

            //   MessageBox.Show(INDICADOR);

            if (DatUser.AUX_CONEXION == "CORRECTO")
            {
                if (contadorUsuario == 0 || lstUsuarios == null)
                {
                    Hide();
                    frmRegistroEmpresa registroEmpresa = new frmRegistroEmpresa();
                    registroEmpresa.ShowDialog();
                    this.Dispose();
                }
            }

            if (DatUser.AUX_CONEXION == "INCORRECTO")
            {
                Hide();
                frmServidorRemoto servidorRemoto = new frmServidorRemoto();
                servidorRemoto.ShowDialog();
                this.Dispose();
            }

            try
            {
                ManagementObject mos = new ManagementObject(@"Win32_PhysicalMedia='\\.\PHYSICALDRIVE0'");
                //foreach (ManagementObject getSerial in mos.Get())
                //{
                serialPC = mos.Properties["SerialNumber"].Value.ToString().Trim();
                IdCaja   = new BusBox().showBoxBySerial(serialPC).Id;
                // }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            try
            {
                Licencia licencia = new BusLicencia().Obtener_LicenciaTemporal();

                dtpVencimiento.Value = Convert.ToDateTime(EncriptarTexto.Desencriptar(licencia.FechaVencimiento));
                string serial = EncriptarTexto.Desencriptar(licencia.Serial);
                string estado = EncriptarTexto.Desencriptar(licencia.Estado);
                dtpFechaActivacion.Value = Convert.ToDateTime(EncriptarTexto.Desencriptar(licencia.FechaActivacion));

                label3.Text = estado;
                label2.Text = serial;
                //dtpFechaActivacion.Value = Convert.ToDateTime( fechaActivacion );
                // dtpVencimiento.Value = Convert.ToDateTime( VencimientoLicencia );
                dtpFechaActivacion.Format = DateTimePickerFormat.Custom;
                dtpVencimiento.Format     = DateTimePickerFormat.Custom;

                if (estado != "VENCIDO")
                {
                    string   fechaActual = Convert.ToString(DateTime.Now);
                    DateTime hoy         = Convert.ToDateTime(fechaActual.Split(' ')[0]);

                    if (dtpVencimiento.Value >= hoy)
                    {
                        int mes       = dtpFechaActivacion.Value.Month;
                        int mesActual = hoy.Month;
                        if (mes <= mesActual)
                        {
                            if (estado.Equals("?ACTIVO?"))
                            {
                                lblLicencia.Text = "Licencia activada hasta el : " + dtpVencimiento.Value.ToString("dd/MM/yyyy");
                            }
                            else if (estado.Equals("?ACTIVADO PREMIUM?"))
                            {
                                lblLicencia.Text = "Licencia profesional Activada hasta el : " + dtpVencimiento.Value.ToString("dd/MM/yyyy");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#17
0
        static void Main(string[] args)
        {
            var bus = new BusUser();

            bus.Login();
        }
示例#18
0
        private void btnAbonar_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtMontoAbonar.Text))
                {
                    MessageBox.Show("Ingrese la cantidad a Abonar", "Datos necesarios", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    txtMontoAbonar.Focus();
                }
                else
                {
                    string  _strEstadoPago = Convert.ToDecimal(txtMontoAbonar.Text) >= Convert.ToDecimal(txtSaldoActual.Text) ? "PAGADO" : "PENDIENTE";
                    decimal _saldo         = Convert.ToDecimal(txtPendienteLiquidar.Text) <= 0 ? 0 : Convert.ToDecimal(txtPendienteLiquidar.Text);
                    int     _idVenta       = Convert.ToInt32(lblIdVenta.Text);
                    decimal abonado        = Convert.ToDecimal(txtPendienteLiquidar.Text) <= 0 ? Convert.ToDecimal(txtSaldoActual.Text) : Convert.ToDecimal(txtMontoAbonar.Text);
                    decimal efectivo       = Convert.ToDecimal(lblTotalAbonado.Text) + Convert.ToDecimal(txtMontoAbonar.Text);

                    new BusVentas().Actualizar_VentaACredito(_idVenta, _saldo, _strEstadoPago, efectivo);

                    #region BITACORA PAGO CLIENTE

                    ManagementObject mos      = new ManagementObject(@"Win32_PhysicalMedia='\\.\PHYSICALDRIVE0'");
                    string           serialPC = mos.Properties["SerialNumber"].Value.ToString().Trim();
                    int idUsuario             = new BusUser().ObtenerUsuario(EncriptarTexto.Encriptar(serialPC)).Id;

                    DatCatGenerico.Agregar_BitacoraCliente(_idVenta, idUsuario, abonado);
                    #endregion


                    #region TICKET
                    rptComprobanteAbono _rpt = new rptComprobanteAbono();
                    DataTable           dt   = new DatVenta().Obtener_ComprobanteCredito(_idVenta, abonado);
                    _rpt.tbCobro.DataSource = dt;
                    _rpt.DataSource         = dt;

                    reportViewer1.Report = _rpt;
                    reportViewer1.RefreshReport();

                    pnlVistaTicket.Visible = true;
                    #endregion


                    try
                    {
                        string impresora = DatBox.Obtener_ImpresoraTicket(serialPC, "TICKET");
                        TICKET = new PrintDocument();
                        TICKET.PrinterSettings.PrinterName = impresora;

                        if (TICKET.PrinterSettings.IsValid)
                        {
                            PrinterSettings printerSettings = new PrinterSettings();
                            printerSettings.PrinterName = impresora;

                            ReportProcessor reportProcessor = new ReportProcessor();
                            reportProcessor.PrintReport(reportViewer1.ReportSource, printerSettings);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error al imprimir el ticket : " + ex.Message, "Error de impresión", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }


                    LimpiarCampos();
                    ListarVentar_PorCobrar("");
                    MessageBox.Show("Abono realizado correctamente", "Éxito!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex.Message, "Error de actulizacion de pagos a crédito", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }