Пример #1
0
        public ClienteDetailsView(tblLeitor leitor, FuncionarioEditView.EditContext ctx)
        {
            _context = ctx;

            InitializeComponent();

            txtNome.Text     = leitor.Nome;
            txtEmail.Text    = leitor.Email;
            txtCPF.Text      = leitor.CPF.ApplyCPFMask();
            txtCargo.Text    = leitor.tblTipoLeitor.TipoLeitor;
            txtEndereço.Text = leitor.Endereco;
            txtRG.Text       = leitor.RG.ApplyRGMask();
            txtTel.Text      = leitor.Telefone.ApplyTelMask();
            txtID.Text       = $"ID: {leitor.IDLeitor}";

            _currentLeitor = leitor;
            var converter = new ByteToImageConverter();

            imgFuncionario.Source = (ImageSource)converter.Convert(leitor.ImagemLeitor, typeof(ImageSource), null, null);

            if (_context == FuncionarioEditView.EditContext.Creating)
            {
                txtHeader.Text = "Vamos adcionar este novo membro na nossa equipe! Essas informações estão corretas?";
            }
        }
Пример #2
0
 public IHttpActionResult Put(int id, tblLeitor leitor)
 {
     using (var db = new TccSettings())
         try
         {
             tblLeitor _leitor = db.tblLeitor.Include("tblEmprestimo").Include("tblFavoritos").First(l => l.IDLeitor == id);
             _leitor.Nome         = leitor.Nome ?? _leitor.Nome;
             _leitor.CPF          = leitor.CPF ?? _leitor.CPF;
             _leitor.RG           = leitor.RG ?? _leitor.RG;
             _leitor.DataNasc     = leitor.DataNasc ?? _leitor.DataNasc;
             _leitor.IDTipoLeitor = leitor.IDTipoLeitor ?? _leitor.IDTipoLeitor;
             _leitor.Email        = leitor.Email ?? _leitor.Email;
             _leitor.Telefone     = leitor.Telefone ?? _leitor.Telefone;
             _leitor.Endereco     = leitor.Endereco ?? _leitor.Endereco;
             _leitor.ImagemLeitor = leitor.ImagemLeitor ?? _leitor.ImagemLeitor;
             db.SaveChanges();
             return(Ok());
         }
         catch (Exception e)
         {
             return(Json(new
             {
                 Code = 404,
                 e.Message
             }));
         }
 }
Пример #3
0
 public void GoBack(object _, RoutedEventArgs e, tblLeitor leitor = null)
 {
     if (_context == FuncionarioEditView.EditContext.Editing)
     {
         StateRepository.currentView.Set(new ClienteDetailsView(leitor ?? _currentLeitor, _context));
     }
     else
     {
         StateRepository.currentView.Set(new ClientesView());
     }
 }
Пример #4
0
        public ClienteEditView(tblLeitor leitor, FuncionarioEditView.EditContext ctx)
        {
            _currentLeitor = leitor;
            _context       = ctx;

            InitializeComponent();

            using var db = new TCCFEntities();
            var tiposLeitor = db.tblTipoLeitor.Select(t => t.TipoLeitor).ToList();

            foreach (var tipo in tiposLeitor)
            {
                cbxCargo.Items.Add(tipo);
            }

            if (_context == FuncionarioEditView.EditContext.Creating)
            {
                txtHeader.Text = "Vamos adicionar este leitor na nossa equipe";
            }
            else
            {
                txtNome.Text     = _currentLeitor.Nome;
                txtEmail.Text    = _currentLeitor.Email;
                txtCPF.Text      = _currentLeitor.CPF;
                txtEndereço.Text = _currentLeitor.Endereco;
                txtRG.Text       = _currentLeitor.RG;
                txtTel.Text      = _currentLeitor.Telefone;
                txtID.Text       = $"ID: {_currentLeitor.IDLeitor}";

                cbxCargo.Text = _currentLeitor.tblTipoLeitor.TipoLeitor;

                if (_currentLeitor.IDLeitor != StateRepository.loggedInUser.Get().IDFuncionario)
                {
                    StackPanel panelSenha = (StackPanel)txtSenha.Parent;
                    panelSenha.Visibility = Visibility.Collapsed;

                    StackPanel panelConfirmarSenha = (StackPanel)txtConfirmarSenha.Parent;
                    panelConfirmarSenha.Visibility = Visibility.Collapsed;
                }

                var converter = new ByteToImageConverter();

                if (_currentLeitor.ImagemLeitor != null)
                {
                    if (_currentLeitor.ImagemLeitor != new byte[] { 0x00 })
                    {
                        imgFuncionario.Source =
                            (ImageSource)converter.Convert(_currentLeitor.ImagemLeitor, typeof(ImageSource), null,
                                                           null);
                    }
                }
            }
        }
Пример #5
0
        public static string GenerateJWT(tblLeitor leitor)
        {
            var tokenHandler = new JwtSecurityTokenHandler();
            var claims       = new[] {
                new Claim("UserId", $"{leitor.IDLeitor}")
            };

            var token = tokenHandler.CreateJwtSecurityToken(
                subject: new ClaimsIdentity(claims),
                signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Convert.FromBase64String(WebApiApplication.JWTSecret)), "HS256")
                );

            return(tokenHandler.WriteToken(token));
        }
Пример #6
0
        public static bool LogUserIn(tblLeitor user, string plaintextPassword)
        {
            Rfc2898DeriveBytes hash;

            (string digestedSalt, string digestedHash) = ("", "");

            using (var db = new TccSettings())
            {
                dynamic credentials = new {};
                try
                {
                    credentials = db.tblLeitor.Where(l => l.IDLeitor == user.IDLeitor)
                                  .Select(l => new { l.Salt, l.Senha }).First();
                }
                catch (Exception)
                {
                    return(false);
                }

                digestedHash = credentials.Senha;
                digestedSalt = credentials.Salt;
            }

            var saltBytes = StringToByteArray(digestedSalt);

            hash = new Rfc2898DeriveBytes(plaintextPassword, saltBytes, ITERATIONS);

            var digestedHashedPassword = BitConverter.ToString(hash.GetBytes(16)).Replace("-", "").ToLower();

            hash.Dispose();
            if (digestedHashedPassword != digestedHash)
            {
                return(false);
            }


            return(true);
        }
Пример #7
0
        public static bool RegisterUser(tblLeitor user, string plaintextPassword)
        {
            Rfc2898DeriveBytes hash;
            var generatedSaltBytes = new byte[16];

            rng.GetBytes(generatedSaltBytes);

            hash = new Rfc2898DeriveBytes(plaintextPassword, generatedSaltBytes, ITERATIONS);

            var digestedHashedPassword = BitConverter.ToString(hash.GetBytes(16)).Replace("-", "").ToLower();

            hash.Dispose();

            using (var db = new TccSettings())
            {
                var leitor = db.tblLeitor.First(l => l.IDLeitor == user.IDLeitor);
                leitor.Salt  = BitConverter.ToString(generatedSaltBytes).Replace("-", "").ToLower();
                leitor.Senha = digestedHashedPassword;

                db.SaveChanges();
            }

            return(true);
        }
Пример #8
0
        private void ConfirmCreate()
        {
            var textContainer = (WrapPanel)txtNome.FindCommonVisualAncestor(txtCPF);

            foreach (var _panel in textContainer.Children)
            {
                if (_panel is StackPanel panel)
                {
                    foreach (var child in panel.Children)
                    {
                        if (child is TextBox tbox)
                        {
                            if (tbox.Text == "")
                            {
                                MessageBox.Show("Todos os campos devem estar corretamente preenchidos.");
                                return;
                            }
                        }
                        else if (child is PasswordBox pbox)
                        {
                            if (pbox.Password == "")
                            {
                                MessageBox.Show("Todos os campos devem estar corretamente preenchidos.");
                                return;
                            }
                        }
                    }
                }
            }

            if (txtSenha.Password != txtConfirmarSenha.Password)
            {
                WarnText(txtConfirmarSenha);
                return;
            }


            using var db = new TCCFEntities();

            var(senha, salt) = Authentication.RegisterUser(txtSenha.Password);

            var leitor = new tblLeitor()
            {
                Nome          = txtNome.Text,
                CPF           = txtCPF.StripMask(),
                Email         = txtEmail.Text,
                Endereco      = txtEndereço.Text,
                RG            = txtRG.StripMask(),
                Telefone      = txtTel.StripMask(),
                Senha         = senha,
                Salt          = salt,
                tblTipoLeitor = db.tblTipoLeitor.First(f => f.TipoLeitor == cbxCargo.Text),
                ImagemLeitor  = (byte[])new ByteToImageConverter().ConvertBack(imgFuncionario.Source, typeof(byte[]), null, CultureInfo.CurrentCulture)
            };

            db.tblLeitor.Add(leitor);
            db.SaveChanges();

            leitor = db.tblLeitor.Find(leitor.IDLeitor);

            StateRepository.currentView.Set(new ClienteDetailsView(leitor, _context));
        }