Skip to content

Commit be7da14

Browse files
authored
Merge pull request #5 from PosteroOrg/dev
Improve UI and UX
2 parents 0f8b762 + ccf51a3 commit be7da14

36 files changed

+353
-111
lines changed

PosteroOrg.Mural/App_Start/RouteConfig.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public class RouteConfig
1212
public static void RegisterRoutes(RouteCollection routes)
1313
{
1414
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
15-
15+
routes.LowercaseUrls = true;
1616
routes.MapRoute(
1717
name: "Default",
18-
url: "{controller}/{action}/{id}",
18+
url: "{action}/{id}",
1919
defaults: new { controller = "Main", action = "Index", id = UrlParameter.Optional }
2020
);
2121
}
Loading

PosteroOrg.Mural/Controllers/MainController.cs

+67-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Web;
66
using System.Web.Mvc;
77
using DevOne.Security.Cryptography.BCrypt;
8+
using System.Text.RegularExpressions;
89

910
namespace PosteroOrg.Mural.Controllers
1011
{
@@ -38,25 +39,62 @@ public ActionResult Login(string username, string password)
3839
if (user != null && BCryptHelper.CheckPassword(password, user.Password))
3940
{
4041
Session["User"] = user;
42+
Alert("Você foi autenticado com sucesso.", type: "success");
43+
}
44+
else
45+
{
46+
Alert("Note que ambos os campos diferenciam letras maiúsculas e minúsculas.", "Não reconhecemos suas credenciais.", "danger");
4147
}
4248
}
49+
else
50+
{
51+
Alert("Parece que você esqueceu de informar seu usuário ou sua senha.", "Ops.", "danger");
52+
}
4353
return RedirectToAction("");
4454
}
4555

4656
// POST: /register
4757
[HttpPost]
4858
public ActionResult Register(string username, string password, string passwordCheck)
4959
{
50-
if (!String.IsNullOrWhiteSpace(username) && db.Users.Find(username) == null && !String.IsNullOrWhiteSpace(password) && password == passwordCheck)
60+
if (!String.IsNullOrWhiteSpace(username) && !String.IsNullOrWhiteSpace(password))
5161
{
52-
User user = new User() {
53-
Username = username.Trim(),
54-
Password = BCryptHelper.HashPassword(password, BCryptHelper.GenerateSalt()),
55-
DtRegister = DateTimeOffset.Now
56-
};
57-
db.Users.Add(user);
58-
db.SaveChanges();
59-
Session["User"] = user;
62+
if (password == passwordCheck)
63+
{
64+
if (Regex.IsMatch(username, @"^[a-zA-Z0-9_]{6,}$") && Regex.IsMatch(password, @"(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"))
65+
{
66+
if (db.Users.Find(username) == null)
67+
{
68+
User user = new User()
69+
{
70+
Username = username.Trim(),
71+
Password = BCryptHelper.HashPassword(password, BCryptHelper.GenerateSalt()),
72+
DtRegister = DateTimeOffset.Now
73+
};
74+
db.Users.Add(user);
75+
db.SaveChanges();
76+
Session["User"] = user;
77+
Alert("Você foi cadastrado com sucesso.", "Bem vindo.", "success");
78+
}
79+
else
80+
{
81+
Alert("Parece que alguém já escolheu esse nome de usuário.", "Usuário já existe.", "danger");
82+
}
83+
}
84+
else
85+
{
86+
Alert("Note que sua senha deve ter pelo menos um número, uma letra maiúscula, uma letra minúscula e 8 caractéres ou mais. E escolha seu nome de usuário utilizando apenas caractéres alfanuméricos e traço baixo, e deve ter pelo menos 6 caractéres.", "Informações inválidas.", "danger");
87+
}
88+
}
89+
else
90+
{
91+
Alert("Parece que você sua senha não confere com a confirmação.", "Ops.", "danger");
92+
}
93+
94+
}
95+
else
96+
{
97+
Alert("Parece que você esqueceu de informar um nome de usuário ou uma senha.", "Ops.", "danger");
6098
}
6199
return RedirectToAction("");
62100
}
@@ -65,6 +103,7 @@ public ActionResult Register(string username, string password, string passwordCh
65103
public ActionResult Logout()
66104
{
67105
Session["User"] = null;
106+
Alert("Você foi desconectado com sucesso.", "Desconectado.");
68107
return RedirectToAction("");
69108
}
70109

@@ -76,15 +115,33 @@ public ActionResult New(string note)
76115
if (Session["User"] != null && !String.IsNullOrWhiteSpace(note))
77116
{
78117
User user = db.Users.Find((Session["User"] as User).Username);
79-
user.Notes.Add(new Note() {
118+
user.Notes.Add(new Note()
119+
{
80120
PureContent = note,
81121
DtNote = DateTimeOffset.Now
82122
});
83123
db.SaveChanges();
124+
Alert("Sua nova nota foi registrada com sucesso.", "Salvo.", "success");
125+
}
126+
else
127+
{
128+
Alert("Parece que você esqueceu de escrever a nota.", "Ops.", "danger");
84129
}
85130
return RedirectToAction("");
86131
}
87132

133+
protected void Alert(string message, string title = "", string type = "")
134+
{
135+
var alerts = TempData["Alerts"] != null ? (List<Models.Alert>)TempData["Alerts"] : new List<Models.Alert>();
136+
alerts.Add(new Models.Alert
137+
{
138+
Message = message,
139+
Title = title,
140+
Type = type
141+
});
142+
TempData["Alerts"] = alerts;
143+
}
144+
88145
protected override void Dispose(bool disposing)
89146
{
90147
if (disposing)
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Web;
5-
using MarkdownSharp;
1+
using MarkdownSharp;
62

73
namespace PosteroOrg.Mural
84
{
95
public static class DynamicMarkdown
106
{
7+
private static MarkdownOptions Options = new MarkdownOptions
8+
{
9+
AutoHyperlink = true
10+
};
11+
1112
public static string MarkdownTransform(this string content)
1213
{
13-
return new Markdown().Transform(content);
14+
return new Markdown(Options).Transform(content);
1415
}
1516
}
1617
}

PosteroOrg.Mural/Models/Alert.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace PosteroOrg.Mural.Models
7+
{
8+
public class Alert
9+
{
10+
public string Type { get; set; }
11+
public string Title { get; set; }
12+
public string Message { get; set; }
13+
}
14+
}

PosteroOrg.Mural/PosteroOrg.Mural.csproj

+29-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,34 @@
107107
</Reference>
108108
</ItemGroup>
109109
<ItemGroup>
110+
<Content Include="android-icon-144x144.png" />
111+
<Content Include="android-icon-192x192.png" />
112+
<Content Include="android-icon-36x36.png" />
113+
<Content Include="android-icon-48x48.png" />
114+
<Content Include="android-icon-72x72.png" />
115+
<Content Include="android-icon-96x96.png" />
116+
<Content Include="apple-icon-114x114.png" />
117+
<Content Include="apple-icon-120x120.png" />
118+
<Content Include="apple-icon-144x144.png" />
119+
<Content Include="apple-icon-152x152.png" />
120+
<Content Include="apple-icon-180x180.png" />
121+
<Content Include="apple-icon-57x57.png" />
122+
<Content Include="apple-icon-60x60.png" />
123+
<Content Include="apple-icon-72x72.png" />
124+
<Content Include="apple-icon-76x76.png" />
125+
<Content Include="apple-icon-precomposed.png" />
126+
<Content Include="apple-icon.png" />
127+
<Content Include="browserconfig.xml" />
128+
<Content Include="Content\Images\Layout\og-image.PNG" />
129+
<Content Include="favicon-16x16.png" />
130+
<Content Include="favicon-32x32.png" />
131+
<Content Include="favicon-96x96.png" />
132+
<Content Include="favicon.ico" />
110133
<Content Include="Global.asax" />
134+
<Content Include="ms-icon-144x144.png" />
135+
<Content Include="ms-icon-150x150.png" />
136+
<Content Include="ms-icon-310x310.png" />
137+
<Content Include="ms-icon-70x70.png" />
111138
<Content Include="Web.config" />
112139
</ItemGroup>
113140
<ItemGroup>
@@ -118,6 +145,7 @@
118145
</Compile>
119146
<Compile Include="Helpers\DynamicMarkdown.cs" />
120147
<Compile Include="Helpers\ConfigurationManager.cs" />
148+
<Compile Include="Models\Alert.cs" />
121149
<Compile Include="Models\Database.cs" />
122150
<Compile Include="Models\Note.cs" />
123151
<Compile Include="Models\User.cs" />
@@ -129,6 +157,7 @@
129157
<Content Include="Views\_ViewStart.cshtml" />
130158
<Content Include="Views\Shared\_Layout.cshtml" />
131159
<Content Include="Views\Main\Index.cshtml" />
160+
<Content Include="manifest.json" />
132161
<None Include="Web.Debug.config">
133162
<DependentUpon>Web.config</DependentUpon>
134163
</None>
@@ -138,7 +167,6 @@
138167
</ItemGroup>
139168
<ItemGroup>
140169
<Folder Include="App_Data\" />
141-
<Folder Include="Content\" />
142170
</ItemGroup>
143171
<PropertyGroup>
144172
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>

PosteroOrg.Mural/Views/Main/Index.cshtml

+28-15
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
ViewBag.Title = "Mural";
55
}
66

7-
<div id="modal-nota" class="modal">
8-
<div class="modal-content">
9-
</div>
10-
<div class="modal-footer">
11-
<button class="modal-action modal-close waves-effect waves-red btn-flat">Fechar</button>
7+
<div id="modalNota" class="modal fade" role="dialog" aria-labelledby="modalNotaLabel">
8+
<div class="modal-dialog" role="document">
9+
<div class="modal-content">
10+
<div class="modal-header">
11+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
12+
<h4 class="modal-title" id="modalNotaLabel"></h4>
13+
</div>
14+
<div class="modal-body md-content">
15+
</div>
16+
<div class="modal-footer">
17+
<button type="reset" class="btn btn-default" data-dismiss="modal">Fechar</button>
18+
</div>
19+
</div>
1220
</div>
1321
</div>
1422

@@ -17,14 +25,16 @@
1725
<div class="row">
1826
@foreach (Note note in Model.OrderByDescending(n => n.DtNote))
1927
{
20-
<div class="col s12">
21-
<p><time class="grey-text text-lighten-1" datetime="@note.DtNote.ToString("u")"></time></p>
22-
<div class="card">
23-
<div class="card-content md-content" style="max-height:25em; overflow-y:auto">
28+
<div class="col-12 col-md-6 col-lg-4">
29+
<div class="panel panel-default nota">
30+
<div class="panel-heading text-right">
31+
<time class="text-muted" datetime="@note.DtNote.ToString("u")"></time>
32+
</div>
33+
<div class="panel-body md-content" style="max-height:10em; overflow:hidden">
2434
@Html.Raw(note.PureContent.MarkdownTransform())
2535
</div>
26-
<div class="card-action">
27-
<a class="open waves-effect btn-flat">Abrir</a>
36+
<div class="panel-footer">
37+
<button type="button" class="btn btn-default">Abrir</button>
2838
</div>
2939
</div>
3040
</div>
@@ -39,10 +49,13 @@ else
3949
@section Scripts {
4050
<script>
4151
$(function () {
42-
$('.card-action .open').on('click', function openNote() {
43-
var content = $(this).closest('.card').find('.card-content').html();
44-
$('#modal-nota .modal-content').html(content);
45-
$('#modal-nota').openModal();
52+
$('.nota button').on('click', function openNote() {
53+
var time = $(this).closest('.nota').find('.panel-heading time').clone();
54+
var content = $(this).closest('.nota').find('.md-content').html();
55+
$('#modalNota .modal-header time').remove();
56+
$('#modalNota .modal-header h4').append(time);
57+
$('#modalNota .modal-body').html(content);
58+
$('#modalNota').modal('show');
4659
});
4760
});
4861
</script>

0 commit comments

Comments
 (0)