Skip to content

Commit

Permalink
Revisão e layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ferronicardoso committed Jun 1, 2024
1 parent 00ac859 commit e8888ed
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 37 deletions.
21 changes: 2 additions & 19 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
source "https://rubygems.org"
# Hello! This is where you manage which Jekyll version is used to run.
# When you want to use a different version, change it below, save the
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
#
# bundle exec jekyll serve
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
#gem "jekyll", "~> 4.3.3"
# This is the default theme for new Jekyll sites. You may change this to anything you like.
#gem "minima", "~> 2.5"
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.

gem "github-pages", "~> 231", group: :jekyll_plugins
# If you have any plugins, put them here!

group :jekyll_plugins do
gem "jekyll-paginate"
gem "jekyll-feed", "~> 0.12"
end

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
platforms :mingw, :x64_mingw, :mswin, :jruby do
gem "tzinfo", ">= 1", "< 3"
gem "tzinfo-data"
end

gem 'jekyll-seo-tag'
gem "webrick"
# Performance-booster for watching directories on Windows
gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin]
# Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
# do not have a Java counterpart.
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]
16 changes: 16 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,26 @@ defaults:
values:
layout: "post"

markdown: kramdown
highlighter: rouge

kramdown:
input: GFM
# https://github.com/jekyll/jekyll/pull/4090
syntax_highlighter: rouge
syntax_highlighter_opts:
css_class: 'highlight'
span:
line_numbers: false
block:
line_numbers: true
start_line: 1

# Plugins
plugins:
- jekyll-paginate
- jekyll-seo-tag
- kramdown-syntax-coderay

# Custom variables
version: "1.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Para que possamos iniciar o desenvolvido, é necessário instalar algumas ferram

Quanto o uso da IDE, poderá utilizar qualquer uma das citadas. Vale ressaltar que diferente do Visual Studio Code e do MonoDevelop, o Microsoft Visual Studio é exclusivo do Windows. Sendo assim, para Mac e Linux deverá fazer uso dos outros dois citados.

[![](/contents/2018/08/0_mono_develop-1024x576.jpg)](/contents/2018/08/0_mono_develop.jpg)
[](/contents/2018/08/0_mono_develop-1024x576.jpg)

Caso esteja utilizando o Mac, o SQL Server deverá ser executado em um Container no Docker, já para sistemas Linux, também poderá ser executado em um Container ou instalado diretamente caso sua versão seja suportada.

Expand Down Expand Up @@ -110,7 +110,7 @@ Repare que temos os diretórios, _Home_ e _Secure_. No _Home_ temos o _Index_ do

Em relação ao banco de dados, criaremos a tabela _Usuario_. Para essa primeira parte iremos somente autenticar no painel.

```
```sql
CREATE TABLE Usuario
(
IdUsuario INT IDENTITY(1, 1) NOT NULL,
Expand All @@ -125,13 +125,13 @@ GO

Vamos incluir também o usuário administrador

```
```sql
INSERT INTO Usuario (Nome, Login, Senha) VALUES ('Administrador', 'admin', '123456')
```

Para a camada de Dados, criamos o ApplicationContext e o repositório de usuários. O ApplicationContext é a classe que implementa o DbContext que é responsável por abrir conexão de nossa aplicação com o banco de dados. Já o repositório nos permitirá utilizar o ApplicationContext para interagir com nossas tabelas realizando operações de consulta, inclusão, exclusão e atualização. Inicialmente teremos somente o repositório de usuário para que possamos implementar a autenticação.

```
```csharp
using System;
using CriandoAplicacaoAspNetCore.Data.Mapping;
using CriandoAplicacaoAspNetCore.Model.Entities;
Expand All @@ -155,7 +155,7 @@ namespace CriandoAplicacaoAspNetCore.Data
}
}
}
``````
```csharp
using System;
using CriandoAplicacaoAspNetCore.Model.Entities;
using CriandoAplicacaoAspNetCore.Model.Interfaces;
Expand All @@ -174,7 +174,7 @@ namespace CriandoAplicacaoAspNetCore.Data.Repositories

Repare que nosso repositório de usuário não possui nenhum metodo implementado. Ele herda do GenericRepository todas os métodos necessários.

```
```csharp
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -210,7 +210,8 @@ namespace CriandoAplicacaoAspNetCore.Data.Repositories
return this._dbSet.Find(id);
}

public virtual IQueryable Get(Expression<Func<TEntity, bool>> expression = null, Func<iqueryable, IOrderedQueryable> orderby = null, string includes = "", bool noTracking = false)
public virtual IQueryable Get(Expression<Func<TEntity, bool>> expression = null,
Func<iqueryable, IOrderedQueryable> orderby = null, string includes = "", bool noTracking = false)
{
IQueryable query = this._dbSet;

Expand Down Expand Up @@ -277,7 +278,7 @@ namespace CriandoAplicacaoAspNetCore.Data.Repositories

Na camada de negócio, criamos o código que irá autenticar o usuário.

```
```csharp
using System;
using System.Linq;
using System.Linq.Expressions;
Expand All @@ -298,7 +299,8 @@ namespace CriandoAplicacaoAspNetCore.Business

public virtual UsuarioDto Autenticar(LoginDto loginDto)
{
Expression<Func<Usuario, bool>> expression = q => q.Login.ToLower().Equals(loginDto.Usuario) && q.Senha.Equals(loginDto.Senha);
Expression<Func<Usuario, bool>> expression = q => q.Login.ToLower().Equals(loginDto.Usuario) &&
q.Senha.Equals(loginDto.Senha);
var usuarioDto = this._unitOfWork.UsuarioRepository
.Get(expression)
.Select(s => new UsuarioDto
Expand All @@ -320,7 +322,7 @@ Não me preocupei muito com a parte de segurança nesse momento. Então, nossa s

Tendo agora nossa camada de dados e de negócio pronta, poderemos criar o controller que será o reponsável por interagir com a nossa view. Criamos então o controller do login em nosso Web Application.

```
```csharp
using System;
using System.Collections.Generic;
using System.Security.Claims;
Expand Down Expand Up @@ -378,7 +380,9 @@ namespace CriandoAplicacaoAspNetCore.WebApp.Areas.Painel.Controllers
ExpiresUtc = DateTime.UtcNow.AddMinutes(2)
};

await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, authProperties);
await HttpContext
.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
principal, authProperties);

return RedirectToAction("Index", "Home");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ Criaremos também a view referente a tela de consulta de usuários.

<div class="row mt-4 mb-4">
<div class="col">
<a class="btn btn-primary" asp-area="Painel" asp-controller="Usuario" asp-action="Novo"><i class="fas fa-plus-circle"></i> Novo</a>
<a class="btn btn-primary" asp-area="Painel" asp-controller="Usuario" asp-action="Novo">
<i class="fas fa-plus-circle"></i> Novo
</a>
</div>
</div>

Expand All @@ -101,8 +103,16 @@ Criaremos também a view referente a tela de consulta de usuários.
{
<tr>
<th scope="row">
<a class="btn btn-info btn-sm" asp-area="Painel" asp-controller="Usuario" asp-action="Editar" asp-route-id="@item.IdUsuario"><i class="fas fa-pen-alt"></i></a>
<a class="btn btn-danger btn-sm" asp-area="Painel" asp-controller="Usuario" asp-action="Excluir" asp-route-id="@item.IdUsuario"><i class="fas fa-trash-alt"></i></a>
<a class="btn btn-info btn-sm" asp-area="Painel"
asp-controller="Usuario" asp-action="Editar"
asp-route-id="@item.IdUsuario">
<i class="fas fa-pen-alt"></i>
</a>
<a class="btn btn-danger btn-sm" asp-area="Painel"
asp-controller="Usuario" asp-action="Excluir"
asp-route-id="@item.IdUsuario">
<i class="fas fa-trash-alt"></i>
</a>
</th>
<td>@item.Nome</td>
<td>@item.Login</td>
Expand Down Expand Up @@ -153,9 +163,9 @@ namespace CriandoAplicacaoAspNetCore.Utils

public static string CreateHash(string value, string salt)
{
var valueBytes = KeyDerivation.Pbkdf2(password: value, salt: Encoding.UTF8.GetBytes(salt),
prf: KeyDerivationPrf.HMACSHA512, iterationCount: ITERATION_COUNT,
numBytesRequested: 256 / 8);
var valueBytes = KeyDerivation
.Pbkdf2(password: value, salt: Encoding.UTF8.GetBytes(salt),
prf: KeyDerivationPrf.HMACSHA512, iterationCount: ITERATION_COUNT, numBytesRequested: 256 / 8);
return Convert.ToBase64String(valueBytes);
}

Expand All @@ -178,7 +188,9 @@ ALTER TABLE usuario ADD Salt VARCHAR(256)
E atualizaremos a senha do usuário _**Admin**_ para a senha padrão _**123456**_, porém, será armazenado somente o Hash e o Salt. Não teremos mais a senha gravada.

```sql
UPDATE Usuario SET Hash = 'NLAZBttBU8HbUrODUPQxViEDr1d7RMi4B/2F6yaKOrQ=', Salt = 'Nkt8krN4/TBHUJXu4zEm6A=='
UPDATE Usuario SET
Hash = 'NLAZBttBU8HbUrODUPQxViEDr1d7RMi4B/2F6yaKOrQ=',
Salt = 'Nkt8krN4/TBHUJXu4zEm6A=='
WHERE Login = 'admin'
```

Expand Down

0 comments on commit e8888ed

Please sign in to comment.