Fixed login & auth

This commit is contained in:
2018-12-18 18:03:05 +01:00
parent 5bdc0dcba7
commit 663b695da4
14 changed files with 235 additions and 210 deletions

View File

@@ -1,93 +1,107 @@
@model string
@inject IHttpContextAccessor HttpContextAccessor
@model string
@{
ViewBag.Title = "Hello Razor";
var session = HttpContextAccessor.HttpContext.Session;
// Questa variabile serve a sapere se si e' autorizzati o meno.
// Per ora e' semplice ma magari si puo' peggiorare utilizzando il ruolo di Doc... etc
// (Utilizzare inject DbContext)
bool auth = session.GetString("username").Equals(Model);
}
<div id="chart"></div>
@if (!auth)
{
<p class="box-title text-red">Non sei autorizzato a vedere i dati di @Model</p>
}
else
{
// Aggiungere un qualcosa per scegliere le ore da vedere (Max 48?)
<div id="chart"></div>
<script>
var base_url = "@Url.Content("~/api/")";
var end_url = "/@Model/last/48";
<script>
var base_url = "@Url.Content("~/api/")";
var end_url = "/@Model/last/48";
$.getJSON(base_url + "heartbeat" + end_url, function (heartbeat) {
$.getJSON(base_url + "step" + end_url, function (steps) {
$.getJSON(base_url + "sleep" + end_url, function (sleep) {
var sleepArr = [];
sleep.forEach( function (el) {
sleepArr.push({ "time": el.time, "value": 1 });
var base_time = new Date(el.time).getTime();
$.getJSON(base_url + "heartbeat" + end_url, function (heartbeat) {
$.getJSON(base_url + "step" + end_url, function (steps) {
$.getJSON(base_url + "sleep" + end_url, function (sleep) {
var sleepArr = [];
sleep.forEach( function (el) {
sleepArr.push({ "time": el.time, "value": 1 });
var base_time = new Date(el.time).getTime();
for (var i = 60000; i <= el.value; i += 60000) {
sleepArr.push({ "time": new Date(base_time + i), "value": 1 });
}
});
$("#chart").kendoChart({
title: { text: "Visualizzazione attivita' di @Model" },
legend: { position: "bottom" },
seriesDefaults: {
type: "line",
style: "smooth"
},
series: [{
name: "Battito",
field: "value",
color: "red",
axis: "Heartbeat",
categoryField: "time",
data: heartbeat,
tooltip: {
visible: true,
format: "{0}%",
template: "Media di: #= value # bpm"
for (var i = 60000; i <= el.value; i += 60000) {
sleepArr.push({ "time": new Date(base_time + i), "value": 1 });
}
}, {
name: "Passi",
field: "value",
color: "blue",
axis: "Steps",
categoryField: "time",
data: steps,
tooltip: {
visible: true,
format: "{0}%",
template: "#= series.name #: #= value #"
}
}, {
type: "area",
name: "Sonno",
field: "value",
color: "black",
axis: "Sleep",
categoryField: "time",
data: sleepArr
}],
categoryAxis: {
labels: {
rotation: +45,
dateFormats: {
hours: "HH:mm"
}
});
$("#chart").kendoChart({
title: { text: "Visualizzazione attivita' di @Model" },
legend: { position: "bottom" },
seriesDefaults: {
type: "line",
style: "smooth"
},
type: "Date",
baseUnit: "hours"
},
valueAxes: [{
name: "Heartbeat",
color: "red"
}, {
name: "Steps",
color: "blue"
}, {
name: "Sleep",
color: "gray",
visible: false,
max: 1,
min: 0
}]
series: [{
name: "Battito",
field: "value",
color: "red",
axis: "Heartbeat",
categoryField: "time",
data: heartbeat,
tooltip: {
visible: true,
format: "{0}%",
template: "Media di: #= value # bpm"
}
}, {
name: "Passi",
field: "value",
color: "blue",
axis: "Steps",
categoryField: "time",
data: steps,
tooltip: {
visible: true,
format: "{0}%",
template: "#= series.name #: #= value #"
}
}, {
type: "area",
name: "Sonno",
field: "value",
color: "black",
axis: "Sleep",
categoryField: "time",
data: sleepArr
}],
categoryAxis: {
labels: {
rotation: +45,
dateFormats: {
hours: "HH:mm"
}
},
type: "Date",
baseUnit: "hours"
},
valueAxes: [{
name: "Heartbeat",
color: "red"
}, {
name: "Steps",
color: "blue"
}, {
name: "Sleep",
color: "gray",
visible: false,
max: 1,
min: 0
}]
})
})
})
})
});
</script>
});
</script>
}

View File

@@ -5,23 +5,29 @@ logo sito
disattivare l-aside e le opzioni
se non loggato deve tornare qua
-->
@model string
@inject IHttpContextAccessor HttpContextAccessor
@{
ViewBag.Title = "Hello Razor";
string session = HttpContextAccessor.HttpContext.Session.GetString("username");
}
<div class="content">
@if (session == null)
{
@if (Model != null)
{
<p class="text-red box-title">Per poter accedere alla pagina [@Model] e' necessario essere loggati</p>
}
<div class="login-box">
@{ await Html.RenderPartialAsync("Login"); }
</div>
<div class="login-box">
@{ await Html.RenderPartialAsync("Register");
}
@{ await Html.RenderPartialAsync("Register"); }
</div>
}
else
{

View File

@@ -1,13 +1,9 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<!-- The user image in the navbar-->
<!-- hidden-xs hides the username on small devices so only the image appears. -->
</a>
<ul style="list-style-type:none">
<ul style="list-style-type:none">
<li class="user-header">
<input type="text" id="username" placeholder="username" />
<input type="password" id="password" placeholder="password" />
<div>
<button class="btn-default btn btn-flat" id="login-btn">Login</button>
<button class="btn-default btn btn-flat" id="login-btn">Login</button>
</div>
<p id="msg" class="login-box-msg"></p>
</li>
@@ -23,19 +19,17 @@
dataType: "json",
type: "POST",
success: function (data) {
console.log(data);
var msg = $("#msg");
if (data.success) {
msg.hide();
// app.navigate("");
window.location.reload();
} else {
msg.html(data.message).show();
$("#user-menu").addClass("open");
}
return false;
},
error: function (xhr, status, error) {
alert(xhr.responseText)
alert(xhr.status+" "+xhr.responseText)
}
})
});

View File

@@ -1,5 +1,4 @@
@model User
@inject IHttpContextAccessor HttpContextAccessor
@inject IHttpContextAccessor HttpContextAccessor
@{
var session = HttpContextAccessor.HttpContext.Session;

View File

@@ -1,8 +1,10 @@
<ul style="list-style: none">
<li class="user-header">
<input type="text" id="regUsername" placeholder="username" />
<input type="password" id="regPassword" placeholder="password" />
<input type="email" id="regEmail" placeholder="example@qualcosa.qualcosa" />
<input type="text" id="regUsername" placeholder="Username" required />
<input type="text" id="regName" placeholder="Name" />
<input type="text" id="regLastname" placeholder="Lastname" />
<input type="password" id="regPassword" placeholder="Password" required />
<input type="email" id="regEmail" placeholder="Email" required />
<label>Doc?</label><input type="checkbox" id="regDoctor" />
<div>
<button class="btn-default btn btn-flat" id="register-btn">Register</button>
@@ -13,20 +15,26 @@
<script>
$("#register-btn").on("click", function () {
var regUsername = $("#regUsername").val();
var regPassword = $("#regPassword").val();
var regEmail = $("#regEmail").val();
var regDoctor = $("#regDoctor").is(":checked");
var username = $("#regUsername").val();
var name = $("#regName").val();
var lastname = $("#regLastname").val();
var password = $("#regPassword").val();
var email = $("#regEmail").val();
var role = $("#regDoctor").is(":checked")? "Doctor":"User";
$.ajax({
url: "/Account/_register",
data: { Username: regUsername, Password: regPassword, Email: regEmail},
data: {
Username: username,
Name: name,
Lastname: lastname,
Password: password,
Email: email,
Role: role
},
dataType: "json",
type: "POST",
success: function (data) {
//se data.success->reload
//se data.fail->indica errori
console.log(data);
var msg = $("#msg-reg");
if (data.success) {
window.location.reload();

View File

@@ -1,9 +1,18 @@
@inject IEnumerable<IMenuItem> Menu
@inject IList<IMenuItem> Menu
@inject IHttpContextAccessor HttpContextAccessor
@{
string session = HttpContextAccessor.HttpContext.Session.GetString("username");
if (session != null) {
Menu = new List<IMenuItem>(Menu);
Menu.Insert(1, new MenuItem("Personal Data", "/user/" + session));
}
}
<ul class="sidebar-menu" data-widget="tree">
@foreach(var menuItem in Menu)
@foreach (var menuItem in Menu)
{
switch(menuItem)
switch (menuItem)
{
case MenuItem single:
<li>

View File

@@ -17,7 +17,7 @@ scratch. This page gets rid of all links and provides the needed markup only.
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>@ViewBag.Title</title>
<title>SeniorAssistant @ViewBag.Title</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="~/AdminLTE-2.4.3/bower_components/bootstrap/dist/css/bootstrap.min.css">