Abbellimento #2
@@ -6,10 +6,10 @@ using LinqToDB;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
using SeniorAssistant.Models.Users;
|
using SeniorAssistant.Models.Users;
|
||||||
using SeniorAssistant.Data;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace IdentityDemo.Controllers
|
namespace IdentityDemo.Controllers
|
||||||
{
|
{
|
||||||
@@ -25,35 +25,48 @@ namespace IdentityDemo.Controllers
|
|||||||
private static readonly string AlreadyPatie = "Sei gia' un paziente";
|
private static readonly string AlreadyPatie = "Sei gia' un paziente";
|
||||||
private static readonly string DocNotExists = "Il dottore selezionato non esiste";
|
private static readonly string DocNotExists = "Il dottore selezionato non esiste";
|
||||||
private static readonly string InsertAsDoct = "Ti ha inserito come il suo dottore: ";
|
private static readonly string InsertAsDoct = "Ti ha inserito come il suo dottore: ";
|
||||||
|
private static readonly string DefaultImage = "/uploads/default.jpg";
|
||||||
|
private static readonly string UploadsDirec = "/uploads/";
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ActionResult> _login(string username, string password)
|
public async Task<ActionResult> _login(string username, string password)
|
||||||
{
|
{
|
||||||
var result = await (from u in Db.Users
|
try
|
||||||
where u.Username.Equals(username)
|
|
||||||
&& u.Password.Equals(password)
|
|
||||||
select u).ToListAsync();
|
|
||||||
|
|
||||||
if (result.Count == 1)
|
|
||||||
{
|
{
|
||||||
User user = result.First();
|
var user = await (from u in Db.Users
|
||||||
HttpContext.Session.SetString(Username, username);
|
where u.Username.Equals(username)
|
||||||
HttpContext.Session.SetString("email", user.Email);
|
&& u.Password.Equals(password)
|
||||||
HttpContext.Session.SetString("name", user.Name);
|
select u).FirstOrDefaultAsync();
|
||||||
HttpContext.Session.SetString("lastname", user.LastName);
|
|
||||||
|
|
||||||
var isDoc = (from d in Db.Doctors
|
|
||||||
where d.Username.Equals(username)
|
|
||||||
select d).ToArray().FirstOrDefault() != null;
|
|
||||||
HttpContext.Session.SetString("role", isDoc? "doctor":"patient");
|
|
||||||
|
|
||||||
return Json(OkJson);
|
if (user != null)
|
||||||
|
{
|
||||||
|
HttpContext.Session.SetString(Username, username);
|
||||||
|
HttpContext.Session.SetString("email", user.Email);
|
||||||
|
HttpContext.Session.SetString("name", user.Name);
|
||||||
|
HttpContext.Session.SetString("lastname", user.LastName);
|
||||||
|
HttpContext.Session.SetString("avatar", user.Avatar ?? DefaultImage);
|
||||||
|
|
||||||
|
var isDoc = (from d in Db.Doctors
|
||||||
|
where d.Username.Equals(username)
|
||||||
|
select d).ToArray().FirstOrDefault() != null;
|
||||||
|
HttpContext.Session.SetString("role", isDoc ? "doctor" : "patient");
|
||||||
|
|
||||||
|
return Json(OkJson);
|
||||||
|
}
|
||||||
|
return Json(new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = InvalidLogIn
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return Json(new JsonResponse()
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Success = false,
|
return Json(new JsonResponse()
|
||||||
Message = InvalidLogIn
|
{
|
||||||
});
|
Success = false,
|
||||||
|
Message = e.Message + " " +e.Source + "</br>"+ e.StackTrace
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@@ -68,6 +81,7 @@ namespace IdentityDemo.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
user.Avatar = DefaultImage;
|
||||||
Db.Insert(user);
|
Db.Insert(user);
|
||||||
if (code != null && code.Equals("444442220"))
|
if (code != null && code.Equals("444442220"))
|
||||||
{
|
{
|
||||||
@@ -218,18 +232,51 @@ namespace IdentityDemo.Controllers
|
|||||||
return Json(OkJson);
|
return Json(OkJson);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ActionResult> _save(IFormFile file)
|
public async Task<ActionResult> _save(IEnumerable<IFormFile> files)
|
||||||
{
|
{
|
||||||
return LoggedAction(() =>
|
return await LoggedAction(() =>
|
||||||
{
|
{
|
||||||
var loggedUser = HttpContext.Session.GetString(Username);
|
if (files != null)
|
||||||
|
{
|
||||||
|
var loggedUser = HttpContext.Session.GetString(Username);
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
|
||||||
|
|
||||||
|
// We are only interested in the file name.
|
||||||
|
var fileName = loggedUser + Path.GetExtension(fileContent.FileName.ToString().Trim('"'));
|
||||||
|
|
||||||
|
var physicalPath = "wwwroot" + UploadsDirec;
|
||||||
|
Directory.CreateDirectory(physicalPath);
|
||||||
|
|
||||||
|
physicalPath = Path.Combine(physicalPath, fileName);
|
||||||
|
var externalPath = Path.Combine(UploadsDirec, fileName);
|
||||||
|
|
||||||
|
using (var fileStream = new FileStream(physicalPath, FileMode.Create))
|
||||||
|
{
|
||||||
|
file.CopyTo(fileStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = (from u in Db.Users
|
||||||
|
where u.Username.Equals(loggedUser)
|
||||||
|
select u).FirstOrDefault();
|
||||||
|
user.Avatar = externalPath;
|
||||||
|
HttpContext.Session.SetString("avatar", externalPath);
|
||||||
|
Db.Update(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Json(OkJson);
|
||||||
|
/*
|
||||||
|
|
||||||
if (file.Length > 0)
|
if (file.Length > 0)
|
||||||
{
|
{
|
||||||
|
var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
|
||||||
|
|
||||||
var name = loggedUser + ".jpg";
|
var name = loggedUser + ".jpg";
|
||||||
var path = Path.Combine(("~/uploads/"), name);
|
var path = Path.Combine(("/uploads/"), name);
|
||||||
var stream = new FileStream(path, FileMode.Create);
|
var stream = new FileStream(path, FileMode.Create);
|
||||||
file.CopyTo(stream);
|
file.CopyTo(stream);
|
||||||
var user = (from u in Db.Users
|
var user = (from u in Db.Users
|
||||||
@@ -261,6 +308,7 @@ namespace IdentityDemo.Controllers
|
|||||||
}
|
}
|
||||||
return Json(new JsonResponse());
|
return Json(new JsonResponse());
|
||||||
*/
|
*/
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,6 @@
|
|||||||
<LangVersion>7.1</LangVersion>
|
<LangVersion>7.1</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="wwwroot\uploads\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="linq2db" Version="2.5.4" />
|
<PackageReference Include="linq2db" Version="2.5.4" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
ViewBag.Title = "Hello Razor";
|
ViewBag.Title = "Hello Razor";
|
||||||
var session = HttpContextAccessor.HttpContext.Session;
|
var session = HttpContextAccessor.HttpContext.Session;
|
||||||
var username = session.GetString("username");
|
var username = session.GetString("username");
|
||||||
|
bool filter = HttpContextAccessor.HttpContext.Request.Query["from"] != (String)null;
|
||||||
|
|
||||||
bool auth = username.Equals(Model.Username);
|
bool auth = username.Equals(Model.Username);
|
||||||
bool isDoc = session.GetString("role").Equals("doctor");
|
bool isDoc = session.GetString("role").Equals("doctor");
|
||||||
@@ -29,6 +30,14 @@ else
|
|||||||
<div>
|
<div>
|
||||||
<input id="hours-data" type="text" placeholder="hours" value="24" />
|
<input id="hours-data" type="text" placeholder="hours" value="24" />
|
||||||
<button id="refresh-hours" class="fc-button">Cambia ora</button>
|
<button id="refresh-hours" class="fc-button">Cambia ora</button>
|
||||||
|
|
||||||
|
<input id="date-from" type="date" value="@HttpContextAccessor.HttpContext.Request.Query["from"]" />
|
||||||
|
<input id="date-to" type="date" value="@HttpContextAccessor.HttpContext.Request.Query["to"]" />
|
||||||
|
<button id="refresh-date" class="fc-button">Cambia data</button>
|
||||||
|
|
||||||
|
<label>Mostra dati sottoforma tabella</label>
|
||||||
|
<input type="checkbox" id="show-table"/>
|
||||||
|
|
||||||
<div id="chart-data"></div>
|
<div id="chart-data"></div>
|
||||||
</div>
|
</div>
|
||||||
@if (isDoc && patient != null)
|
@if (isDoc && patient != null)
|
||||||
@@ -89,9 +98,20 @@ else
|
|||||||
});
|
});
|
||||||
$("#refresh-hours").on("click", function () {
|
$("#refresh-hours").on("click", function () {
|
||||||
var hours = $("#hours-data").val();
|
var hours = $("#hours-data").val();
|
||||||
var base_url = "@Url.Content("~/api/")";
|
|
||||||
var end_url = "/@Model.Username/last/" + hours;
|
var end_url = "/@Model.Username/last/" + hours;
|
||||||
|
kendoUpdate(end_url);
|
||||||
|
});
|
||||||
|
$("#refresh-date").on("click", function () {
|
||||||
|
var from = $("#date-from").val();
|
||||||
|
var to = $("#date-to").val();
|
||||||
|
var end_url = "/@Model.Username/"+from+"/"+to;
|
||||||
|
kendoUpdate(end_url);
|
||||||
|
});
|
||||||
|
|
||||||
|
var toRefresh = "@if (filter) { @Html.Raw("#refresh-date") } else { @Html.Raw("#refresh-hours") }";
|
||||||
|
$(toRefresh).click();
|
||||||
|
|
||||||
|
function kendoUpdate(end_url, base_url = "@Url.Content("~/api/")") {
|
||||||
$.getJSON(base_url + "heartbeat" + end_url, function (heartbeat) {
|
$.getJSON(base_url + "heartbeat" + end_url, function (heartbeat) {
|
||||||
$.getJSON(base_url + "step" + end_url, function (steps) {
|
$.getJSON(base_url + "step" + end_url, function (steps) {
|
||||||
$.getJSON(base_url + "sleep" + end_url, function (sleep) {
|
$.getJSON(base_url + "sleep" + end_url, function (sleep) {
|
||||||
@@ -110,7 +130,9 @@ else
|
|||||||
&& Object.keys(steps).length == 0
|
&& Object.keys(steps).length == 0
|
||||||
&& Object.keys(sleep).length == 0)
|
&& Object.keys(sleep).length == 0)
|
||||||
$("#chart-data").html("Nessun dato");
|
$("#chart-data").html("Nessun dato");
|
||||||
else
|
else {
|
||||||
|
/* se checked #show-table allora crea dati come data.cshtml */
|
||||||
|
/**/
|
||||||
$("#chart-data").kendoChart({
|
$("#chart-data").kendoChart({
|
||||||
title: { text: "Visualizzazione attivita' di @Model.Name @Model.LastName" },
|
title: { text: "Visualizzazione attivita' di @Model.Name @Model.LastName" },
|
||||||
legend: { position: "bottom" },
|
legend: { position: "bottom" },
|
||||||
@@ -175,10 +197,10 @@ else
|
|||||||
min: 0
|
min: 0
|
||||||
}]
|
}]
|
||||||
}); /* Kendo */
|
}); /* Kendo */
|
||||||
|
} /* else */
|
||||||
}); /* sleep */
|
}); /* sleep */
|
||||||
}); /* steps */
|
}); /* steps */
|
||||||
}); /* heart */
|
}); /* heart */
|
||||||
}); /* click */
|
}
|
||||||
$("#refresh-hours").click();
|
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
@@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$("#login-btn").on("click", function () {
|
$("#login-btn").on("click", function () {
|
||||||
var userName = $("#username").val();
|
var username = $("#username").val();
|
||||||
var password = $("#password").val();
|
var password = $("#password").val();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/Account/_login",
|
url: "/Account/_login",
|
||||||
data: { UserName: userName, Password: password, RememberMe: false },
|
data: { Username: username, Password: password },
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
@@ -27,9 +27,6 @@
|
|||||||
$("#user-menu").addClass("open");
|
$("#user-menu").addClass("open");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
|
||||||
error: function (xhr, status, error) {
|
|
||||||
alert(xhr.status+" "+xhr.responseText)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
<!-- The user image in the navbar-->
|
<!-- The user image in the navbar-->
|
||||||
<img src="~/AdminLTE-2.4.3/dist/img/user2-160x160.jpg" class="user-image" alt="User Image">
|
<img src="@session.GetString("avatar")" class="user-image" alt="User Image">
|
||||||
<!-- hidden-xs hides the username on small devices so only the image appears. -->
|
<!-- hidden-xs hides the username on small devices so only the image appears. -->
|
||||||
<span id="user-name" class="hidden-xs">@Model</span>
|
<span id="user-name" class="hidden-xs">@Model</span>
|
||||||
</a>
|
</a>
|
||||||
@@ -47,8 +47,14 @@
|
|||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$("#files").kendoUpload({
|
$("#files").kendoUpload({
|
||||||
async: {
|
async: {
|
||||||
saveUrl: "save",
|
saveUrl: "/Account/_save",
|
||||||
autoUpload: true
|
autoUpload: true
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
if (data.response.success)
|
||||||
|
window.location.reload();
|
||||||
|
else
|
||||||
|
console.log(data.response.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Binary file not shown.
BIN
SeniorAssistant/wwwroot/uploads/default.jpg
Normal file
BIN
SeniorAssistant/wwwroot/uploads/default.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
BIN
SeniorAssistant/wwwroot/uploads/vecchio0.jpg
Normal file
BIN
SeniorAssistant/wwwroot/uploads/vecchio0.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 408 KiB |
Reference in New Issue
Block a user