public IEnumerable <PermisoEntity> GetPermisoList() { if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS") { return(null); } else { try { return(Permiso.GetAll()); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, HttpStatusCode.ExpectationFailed); } } }
private void CargarUsuarios() { dataGridViewUsuarios.AutoGenerateColumns = false; int index = dataGridViewUsuarios.Columns.Add("Usuario", "Usuario"); dataGridViewUsuarios.Columns[index].DataPropertyName = "Usuario"; dataGridViewUsuarios.Columns[index].ReadOnly = true; dataGridViewUsuarios.Columns[index].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; index = dataGridViewUsuarios.Columns.Add(CreateCheckBoxColumn("Maestros", "Maestros")); index = dataGridViewUsuarios.Columns.Add(CreateCheckBoxColumn("Articulos", "Articulos")); index = dataGridViewUsuarios.Columns.Add(CreateCheckBoxColumn("Terceros", "Terceros")); index = dataGridViewUsuarios.Columns.Add(CreateCheckBoxColumn("Documentos", "Documentos")); index = dataGridViewUsuarios.Columns.Add(CreateCheckBoxColumn("Terminal PV", "TerminalPV")); index = dataGridViewUsuarios.Columns.Add(CreateCheckBoxColumn("Comprobantes", "Comprobantes")); index = dataGridViewUsuarios.Columns.Add(CreateCheckBoxColumn("Informes", "Informes")); index = dataGridViewUsuarios.Columns.Add(CreateCheckBoxColumn("Preferencias", "Preferencias")); bindingSource2.DataSource = Permiso.GetAll(); dataGridViewUsuarios.DataSource = bindingSource2; }
public UsuarioEntity LogOn() { if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS") { return(null); } if (WebOperationContext.Current.IncomingRequest.Headers["Authorization"] == null) { WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authenticate: Basic realm=\"myrealm\""); throw new WebFaultException <string>("Acceso no autorizado, favor de validar autenticación", HttpStatusCode.Unauthorized); } else // Decode the header, check password { string encodedUnamePwd = GetEncodedCredentialsFromHeader(); if (!string.IsNullOrEmpty(encodedUnamePwd)) { // Decode the credentials byte[] decodedBytes = null; try { decodedBytes = Convert.FromBase64String(encodedUnamePwd); } catch (FormatException) { } string credentials = ASCIIEncoding.ASCII.GetString(decodedBytes); // Validate User and Password string[] authParts = credentials.Split(':'); Usuario objUsuario = new Usuario(); UsuarioEntity objUsr = Usuario.GetusuarioByUserAndPass(authParts[0], authParts[1]); if (objUsr != null) { List <SessionEntity> lstSessions = Session.GetAll(); if (lstSessions.Any(x => x.IdUsuario == objUsr.IdUsuario)) { foreach (SessionEntity i in lstSessions.Where(x => x.IdUsuario == objUsr.IdUsuario)) { Session.Delete(i.IdSession); } } byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary()); byte[] key = Guid.NewGuid().ToByteArray(); string token = Convert.ToBase64String(time.Concat(key).ToArray()); Session.Add(new SessionEntity() { IdUsuario = objUsr.IdUsuario.Value, Token = token }); objUsr.Token = token; objUsr.Password = ""; var R = objUsr.IdRol.Value; var U = objUsr.IdUsuario.Value; List <UsuarioEntity> usua = Usuario.GetAll(); var usua2 = usua.Where(x => x.IdUsuario == U); var total = usua2.Count(); List <PermisoEntity> per = Permiso.GetAll(); List <PermisoEntity> per2 = per.Where(x => x.IdRol == R).ToList(); objUsr.permiso2 = per2; return(objUsr); } else { WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authenticate: Basic realm=\"myrealm\""); throw new WebFaultException <string>("Acceso no autorizado, favor de validar autenticación", HttpStatusCode.Unauthorized); } } } return(new UsuarioEntity()); }
public IEnumerable <PermisoEntity> GetPermisoList() { return(Permiso.GetAll()); }