Fixes
- Added forgot option - added modify user - moved login and register
This commit is contained in:
@@ -29,7 +29,7 @@ namespace IdentityDemo.Controllers
|
||||
private static readonly string UploadsDirec = "/uploads/";
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> _login(string username, string password)
|
||||
public async Task<IActionResult> _login(string username, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -70,19 +70,21 @@ namespace IdentityDemo.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult _logout()
|
||||
public IActionResult _logout()
|
||||
{
|
||||
HttpContext.Session.Clear();
|
||||
return Json(OkJson);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> _register(User user, string code = "")
|
||||
public async Task<IActionResult> _register(User user, Forgot forgot, string code = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
user.Avatar = DefaultImage;
|
||||
forgot.Username = user.Username;
|
||||
Db.Insert(user);
|
||||
Db.Insert(forgot);
|
||||
if (code != null && code.Equals("444442220"))
|
||||
{
|
||||
Db.Insert(new Doctor
|
||||
@@ -103,7 +105,41 @@ namespace IdentityDemo.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> _notification(string username, string message, string redirectUrl = "#")
|
||||
public async Task<IActionResult> _modify(User user)
|
||||
{
|
||||
return await LoggedAccessDataOf(user.Username, false, () => {
|
||||
var usr = Db.Users.Where(u => u.Username.Equals(user.Username)).FirstOrDefault();
|
||||
|
||||
if (user.Password.Equals(""))
|
||||
user.Password = usr.Password;
|
||||
if (user.Avatar.Equals(""))
|
||||
user.Avatar = usr.Avatar;
|
||||
if (user.Email.Equals(""))
|
||||
user.Email = usr.Email;
|
||||
if (user.LastName.Equals(""))
|
||||
user.LastName = usr.LastName;
|
||||
if (user.Name.Equals(""))
|
||||
user.Name = usr.Name;
|
||||
|
||||
Db.UpdateAsync(user);
|
||||
return Json(OkJson);
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> _checkQuestion(string username, string answer)
|
||||
{
|
||||
var forgot = Db.Forgot.Where(f => f.Username.Equals(username) && f.Answer.Equals(answer)).FirstOrDefault();
|
||||
if(forgot != null)
|
||||
{
|
||||
var user = (from u in Db.Users where u.Username.Equals(forgot.Username) select u).FirstOrDefault();
|
||||
return await _login(user.Username, user.Password);
|
||||
}
|
||||
return Json(new JsonResponse(false, "Risposta sbagliata"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> _notification(string username, string message, string redirectUrl = "#")
|
||||
{
|
||||
return await LoggedAction(() =>
|
||||
{
|
||||
@@ -120,7 +156,7 @@ namespace IdentityDemo.Controllers
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<ActionResult> _notification(int id)
|
||||
public async Task<IActionResult> _notification(int id)
|
||||
{
|
||||
return await LoggedAction(() =>
|
||||
{
|
||||
@@ -142,7 +178,7 @@ namespace IdentityDemo.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> _addDoc(string doctor)
|
||||
public async Task<IActionResult> _addDoc(string doctor)
|
||||
{
|
||||
return await LoggedAction(() =>
|
||||
{
|
||||
@@ -175,7 +211,7 @@ namespace IdentityDemo.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> _sendMessage(string receiver, string body)
|
||||
public async Task<IActionResult> _sendMessage(string receiver, string body)
|
||||
{
|
||||
return await LoggedAction(() => {
|
||||
string username = HttpContext.Session.GetString(Username);
|
||||
@@ -194,7 +230,7 @@ namespace IdentityDemo.Controllers
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<ActionResult> _addNote(string patient, string text)
|
||||
public async Task<IActionResult> _addNote(string patient, string text)
|
||||
{
|
||||
return await LoggedAccessDataOf(patient, true, () =>
|
||||
{
|
||||
@@ -208,7 +244,7 @@ namespace IdentityDemo.Controllers
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<ActionResult> _minHeartToPatient(string patient, int value)
|
||||
public async Task<IActionResult> _minHeartToPatient(string patient, int value)
|
||||
{
|
||||
return await LoggedAccessDataOf(patient, true, () =>
|
||||
{
|
||||
@@ -221,7 +257,7 @@ namespace IdentityDemo.Controllers
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<ActionResult> _maxHeartToPatient(string patient, int value)
|
||||
public async Task<IActionResult> _maxHeartToPatient(string patient, int value)
|
||||
{
|
||||
return await LoggedAccessDataOf(patient, true, () =>
|
||||
{
|
||||
@@ -234,7 +270,7 @@ namespace IdentityDemo.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> _save(IEnumerable<IFormFile> files)
|
||||
public async Task<IActionResult> _save(IEnumerable<IFormFile> files)
|
||||
{
|
||||
return await LoggedAction(() =>
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using LinqToDB;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
|
||||
namespace SeniorAssistant.Controllers
|
||||
@@ -9,8 +10,10 @@ namespace SeniorAssistant.Controllers
|
||||
[Route("")]
|
||||
[Route("Home")]
|
||||
[Route("Index")]
|
||||
public IActionResult Index()
|
||||
public IActionResult Login()
|
||||
{
|
||||
if (IsLogged())
|
||||
return View("Profile");
|
||||
return View();
|
||||
}
|
||||
|
||||
@@ -52,13 +55,36 @@ namespace SeniorAssistant.Controllers
|
||||
{
|
||||
return CheckAuthorized("Message", user);
|
||||
}
|
||||
|
||||
[Route("Profile")]
|
||||
public IActionResult Profile()
|
||||
{
|
||||
return CheckAuthorized("Profile");
|
||||
}
|
||||
|
||||
[Route("Register")]
|
||||
public IActionResult Register()
|
||||
{
|
||||
if (IsLogged())
|
||||
return View("Profile");
|
||||
return View();
|
||||
}
|
||||
|
||||
private IActionResult CheckAuthorized(string view, object model = null)
|
||||
[Route("Forgot")]
|
||||
public IActionResult Forgot(string username = "")
|
||||
{
|
||||
if (IsLogged())
|
||||
return View("Profile");
|
||||
var forgot = Db.Forgot.Where(f => f.Username.Equals(username)).FirstOrDefault();
|
||||
return View(forgot);
|
||||
}
|
||||
|
||||
protected IActionResult CheckAuthorized(string view, object model = null)
|
||||
{
|
||||
if (!IsLogged())
|
||||
{
|
||||
view = "Login";
|
||||
model = "/" + view;
|
||||
view = "Index";
|
||||
}
|
||||
return View(view, model);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using SeniorAssistant.Models.Users;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using SeniorAssistant.Models;
|
||||
|
||||
namespace SeniorAssistant.Controllers
|
||||
{
|
||||
@@ -37,8 +38,8 @@ namespace SeniorAssistant.Controllers
|
||||
{
|
||||
return HttpContext.Session.GetString(Username) != null;
|
||||
}
|
||||
|
||||
protected async Task<ActionResult> LoggedAction(Func<ActionResult> success)
|
||||
|
||||
protected async Task<IActionResult> LoggedAction(Func<IActionResult> success)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -56,12 +57,12 @@ namespace SeniorAssistant.Controllers
|
||||
return Json(new JsonResponse()
|
||||
{
|
||||
Success = false,
|
||||
Message = e.Message + Environment.NewLine
|
||||
Message = e.Message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<ActionResult> LoggedAccessDataOf(string username, bool patients, Func<ActionResult> success)
|
||||
protected async Task<IActionResult> LoggedAccessDataOf(string username, bool patients, Func<IActionResult> success)
|
||||
{
|
||||
return await LoggedAction(() =>
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace SeniorAssistant.Data
|
||||
public ITable<Patient> Patients => GetTable<Patient>();
|
||||
public ITable<Notification> Notifications => GetTable<Notification>();
|
||||
public ITable<Message> Messages => GetTable<Message>();
|
||||
public ITable<Forgot> Forgot => GetTable<Forgot>();
|
||||
|
||||
public T[] GetLastMessages<T>(ITable<T> table, string receiver, ref int numNotSeen, int max = 10)
|
||||
where T : IHasMessage
|
||||
|
||||
16
SeniorAssistant/Models/Forgot.cs
Normal file
16
SeniorAssistant/Models/Forgot.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using LinqToDB.Mapping;
|
||||
|
||||
namespace SeniorAssistant.Models
|
||||
{
|
||||
public class Forgot : IHasUsername
|
||||
{
|
||||
[Column(IsPrimaryKey = true, CanBeNull = false)]
|
||||
public string Username { get; set; }
|
||||
|
||||
[Column(CanBeNull = false)]
|
||||
public string Question { get; set; }
|
||||
|
||||
[Column(CanBeNull = false)]
|
||||
public string Answer { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,7 @@ namespace SeniorAssistant
|
||||
db.CreateTableIfNotExists<Patient>();
|
||||
db.CreateTableIfNotExists<Notification>();
|
||||
db.CreateTableIfNotExists<Message>();
|
||||
db.CreateTableIfNotExists<Forgot>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,8 +176,17 @@ namespace SeniorAssistant
|
||||
db.InsertOrReplace(patient);
|
||||
}
|
||||
|
||||
var forgot = new Forgot()
|
||||
{
|
||||
Question = "Quale animale ti piace di piu'?",
|
||||
Answer = "Rayquaza"
|
||||
};
|
||||
foreach (var user in users)
|
||||
{
|
||||
forgot.Username = user.Username;
|
||||
db.InsertOrReplace(forgot);
|
||||
db.InsertOrReplace(user);
|
||||
}
|
||||
|
||||
DateTime now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
|
||||
now = now.AddHours(DateTime.Now.Hour).AddMinutes(30);
|
||||
|
||||
29
SeniorAssistant/Views/Home/Forgot.cshtml
Normal file
29
SeniorAssistant/Views/Home/Forgot.cshtml
Normal file
@@ -0,0 +1,29 @@
|
||||
@model Forgot
|
||||
|
||||
<p>Se indovini la risposta allora verrai loggato. Li poi potrai modificare la password.</p>
|
||||
<label>Domanda di sicurezza: </label><p>@Model.Question</p>
|
||||
<label>Risposta: </label><input id="answer" type="text" placeholder="Risposta"/>
|
||||
<p id="error"></p>
|
||||
<button id="send-answ">Invia</button>
|
||||
|
||||
<script>
|
||||
$("#send-answ").on("click", function () {
|
||||
var answer = $("#answer").val();
|
||||
|
||||
$.ajax({
|
||||
url: "/Account/_checkQuestion",
|
||||
dataType: "json",
|
||||
type: "POST",
|
||||
data: {
|
||||
Username: "@Model.Username",
|
||||
Answer: answer
|
||||
},
|
||||
success: function (data) {
|
||||
if (data.success)
|
||||
window.location.reload();
|
||||
else
|
||||
$("#error").html(data.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
56
SeniorAssistant/Views/Home/Login.cshtml
Normal file
56
SeniorAssistant/Views/Home/Login.cshtml
Normal file
@@ -0,0 +1,56 @@
|
||||
@model string
|
||||
|
||||
<div class="content">
|
||||
@if (Model != null)
|
||||
{
|
||||
<p class="text-red box-title">Per poter accedere alla pagina [@Model] e' necessario essere loggati</p>
|
||||
}
|
||||
<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>
|
||||
</div>
|
||||
<p id="msg" class="login-box-msg"></p>
|
||||
</li>
|
||||
</ul>
|
||||
<button id="forgot">Dimanticato la passw?</button>
|
||||
<form id="div-forgot" style="display:none" action="/Forgot" method="get">
|
||||
<label>Username</label><input name="username" type="text" />
|
||||
<input type="submit" id="ok-forgot" value="OK" />
|
||||
</form>
|
||||
|
||||
@Html.ActionLink("Oppure registrati", "Register")
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$("#forgot").on("click", function () {
|
||||
$("#div-forgot").css("display", "block");
|
||||
});
|
||||
|
||||
$("#ok-forgot").on("click", function () {
|
||||
$("#div-forgot").css("display", "block");
|
||||
});
|
||||
|
||||
$("#login-btn").on("click", function () {
|
||||
var username = $("#username").val();
|
||||
var password = $("#password").val();
|
||||
$.ajax({
|
||||
url: "/Account/_login",
|
||||
data: { Username: username, Password: password },
|
||||
dataType: "json",
|
||||
type: "POST",
|
||||
success: function (data) {
|
||||
var msg = $("#msg");
|
||||
if (data.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
msg.html(data.message).show();
|
||||
$("#user-menu").addClass("open");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
@@ -6,6 +6,8 @@
|
||||
<input type="password" id="regPassword" placeholder="Password" required />
|
||||
<input type="email" id="regEmail" placeholder="Email" required />
|
||||
<input type="text" id="regDoctor" placeholder="Doctor only (543210)" />
|
||||
<input type="text" id="passwQues" placeholder="Domanda di sicurezza" required />
|
||||
<input type="text" id="passwAnsw" placeholder="Risposta di sicurezza" required />
|
||||
<div>
|
||||
<button class="btn-default btn btn-flat" id="register-btn">Register</button>
|
||||
</div>
|
||||
@@ -13,6 +15,8 @@
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@Html.ActionLink("Oppure fai il login", "Login")
|
||||
|
||||
<script>
|
||||
$("#register-btn").on("click", function () {
|
||||
var username = $("#regUsername").val();
|
||||
@@ -22,6 +26,9 @@
|
||||
var email = $("#regEmail").val();
|
||||
var code = $("#regDoctor").val();
|
||||
|
||||
var quest = $("#passwQues").val();
|
||||
var answ = $("#passwAnsw").val();
|
||||
|
||||
$.ajax({
|
||||
url: "/Account/_register",
|
||||
data: {
|
||||
@@ -32,6 +39,10 @@
|
||||
Lastname: lastname,
|
||||
Password: password,
|
||||
Email: email
|
||||
},
|
||||
Forgot: {
|
||||
Question: quest,
|
||||
Answer: answ
|
||||
}
|
||||
},
|
||||
dataType: "json",
|
||||
@@ -132,9 +132,6 @@ else
|
||||
&& Object.keys(sleep).length == 0)
|
||||
$("#chart-data").html("Nessun dato");
|
||||
else {
|
||||
/* se checked #show-table allora crea dati come data.cshtml for () {
|
||||
allData.push({"time"});
|
||||
}*/
|
||||
$("#chart-data").html("");
|
||||
console.log(heartbeat[0].time);
|
||||
console.log("min = " +new Date(heartbeat[0].time).getTime());
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
@{
|
||||
var controller = ViewContext.RouteData.Values["Controller"];
|
||||
var action = ViewContext.RouteData.Values["Action"];
|
||||
var controller = ViewContext.RouteData.Values["Controller"].ToString();
|
||||
var action = ViewContext.RouteData.Values["Action"].ToString();
|
||||
}
|
||||
|
||||
<div class="breadcrumb">
|
||||
@Html.ActionLink("Home", "Index", "Home")
|
||||
@if (controller.ToString() != "Home")
|
||||
@if (controller != "Home")
|
||||
{
|
||||
@:> @Html.ActionLink(controller.ToString(), "Index", controller.ToString())
|
||||
@:> @Html.ActionLink(controller, "Index", controller)
|
||||
}
|
||||
@if (action.ToString() != "Index")
|
||||
@if (action != "Index")
|
||||
{
|
||||
@:> @Html.ActionLink(action.ToString(), action.ToString(), controller.ToString())
|
||||
@:> @Html.ActionLink(action, action, controller)
|
||||
}
|
||||
|
||||
</div>
|
||||
@@ -1,33 +0,0 @@
|
||||
<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>
|
||||
</div>
|
||||
<p id="msg" class="login-box-msg"></p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<script>
|
||||
$("#login-btn").on("click", function () {
|
||||
var username = $("#username").val();
|
||||
var password = $("#password").val();
|
||||
$.ajax({
|
||||
url: "/Account/_login",
|
||||
data: { Username: username, Password: password },
|
||||
dataType: "json",
|
||||
type: "POST",
|
||||
success: function (data) {
|
||||
var msg = $("#msg");
|
||||
if (data.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
msg.html(data.message).show();
|
||||
$("#user-menu").addClass("open");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
@@ -5,10 +5,12 @@
|
||||
var session = HttpContextAccessor.HttpContext.Session;
|
||||
string search = HttpContextAccessor.HttpContext.Request.Query["q"];
|
||||
string username = session.GetString("username");
|
||||
|
||||
|
||||
if (username != null)
|
||||
{
|
||||
var isDoc = session.GetString("role").Equals("doctor");
|
||||
var MaxPatients = 30;
|
||||
var Menu = new List<IMenuItem>();
|
||||
Menu.Add(new MenuItem("Profilo", "/"));
|
||||
Menu.Add(new MenuItem("Dati personali", "/user/" + username));
|
||||
@@ -19,7 +21,18 @@
|
||||
where p.Doctor.Equals(username)
|
||||
join u in db.Users on p.Username equals u.Username
|
||||
select new { Username = p.Username, Name = u.Name + " " + u.LastName }).ToArray();
|
||||
var sub = new SubMenu() { Text = "Pazienti", Items = new List<MenuItem>() };
|
||||
|
||||
if(search != null)
|
||||
{
|
||||
patients = (from p in patients
|
||||
where p.Name.StartsWith(search)
|
||||
select p).ToArray();
|
||||
}
|
||||
|
||||
patients.Take(MaxPatients);
|
||||
|
||||
var num = patients.Count();
|
||||
var sub = new SubMenu() { Text = num + " pazienti link rapido", Items = new List<MenuItem>() };
|
||||
foreach (var p in patients)
|
||||
{
|
||||
sub.Items.Add(new MenuItem(p.Name, "/user/" + p.Username));
|
||||
@@ -32,7 +45,10 @@
|
||||
var patient = (from p in db.Patients
|
||||
where p.Username.Equals(username)
|
||||
select p).FirstOrDefault();
|
||||
Menu.Add(new MenuItem("Invia un messaggio al dottore", "/Message/" + patient.Doctor));
|
||||
if (patient != null)
|
||||
{
|
||||
Menu.Add(new MenuItem("Invia un messaggio al dottore", "/Message/" + patient.Doctor));
|
||||
}
|
||||
}
|
||||
<aside class="main-sidebar">
|
||||
<!-- sidebar: style can be found in sidebar.less -->
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user