Fixes
- Added forgot option - added modify user - moved login and register
This commit is contained in:
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>
|
||||
138
SeniorAssistant/Views/Home/Profile.cshtml
Normal file
138
SeniorAssistant/Views/Home/Profile.cshtml
Normal file
@@ -0,0 +1,138 @@
|
||||
@inject IHttpContextAccessor HttpContextAccessor
|
||||
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||
|
||||
@{
|
||||
var session = HttpContextAccessor.HttpContext.Session;
|
||||
var db = dbFactory.Create();
|
||||
var username = session.GetString("username");
|
||||
var patientData = db.Patients.Where(p => p.Username.Equals(username)).ToArray().FirstOrDefault();
|
||||
var hasDoc = patientData != null;
|
||||
}
|
||||
|
||||
<div class="content">
|
||||
<div class="pull-left" , style="width: 50%">
|
||||
<h2 class="alert-success" style="text-align:center">
|
||||
Welcome @username
|
||||
</h2>
|
||||
name: @session.GetString("name")<br />
|
||||
lastname: @session.GetString("lastname")<br />
|
||||
email: @session.GetString("email")<br />
|
||||
</div>
|
||||
|
||||
<div class="box pull-right" , style="width: 45%">
|
||||
@if (hasDoc) // is patient and has doc, must show doc data
|
||||
{
|
||||
var doctor = (from u in db.Users
|
||||
join d in db.Doctors on u.Username equals d.Username
|
||||
where d.Username.Equals(patientData.Doctor)
|
||||
select new { u.Username, u.Name, u.LastName, d.Location }).ToArray().First();
|
||||
|
||||
<p class="text-bold">Dottore: @doctor.Name @doctor.LastName</p>
|
||||
<p class="text-fuchsia">Dove mi puoi trovare? @doctor.Location</p>
|
||||
<textarea class="progress-text" placeholder="Nessuna nuova nota" readonly>@patientData.Notes</textarea>
|
||||
|
||||
<a class="" href="/Message/@doctor.Username">Invia un messaggio al tuo dottore</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic[] data;
|
||||
Type type = null;
|
||||
string title = null;
|
||||
var docData = db.Doctors.Where(d => d.Username.Equals(username)).ToArray().FirstOrDefault();
|
||||
|
||||
if (docData != null) // is DOC
|
||||
{
|
||||
// see all the patient of the doc
|
||||
title = "Lista dei pazienti";
|
||||
var patients = (from u in db.Users
|
||||
join p in db.Patients on u.Username equals p.Username
|
||||
where p.Doctor.Equals(docData.Username)
|
||||
select new { u.Username, u.Name, u.LastName, p.Notes, Profile = "<a href=\\\"/user/" + u.Username + "\\\">Profile</a>" }).ToArray();
|
||||
data = patients;
|
||||
type = patients.FirstOrDefault()?.GetType();
|
||||
}
|
||||
else // is a patient and need to choose a doctor
|
||||
{
|
||||
// choose which doc you want
|
||||
title = "Scegli un Doc";
|
||||
var docs = (from u in db.Users
|
||||
join d in db.Doctors on u.Username equals d.Username
|
||||
select new { u.Username, u.Name, u.LastName, d.Location, Choose = "<a id=\\\"choose-" + u.Username + "\\\" href=#>Scegli</a>" }).ToArray();
|
||||
data = docs;
|
||||
type = docs.FirstOrDefault().GetType();
|
||||
}
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
|
||||
var fields = new List<string>();
|
||||
|
||||
foreach (var field in type.GetProperties())
|
||||
{
|
||||
fields.Add(field.Name);
|
||||
}
|
||||
|
||||
<p>@title</p>
|
||||
<div id="var-table"></div>
|
||||
<script>
|
||||
var datas = [
|
||||
@foreach (var el in data)
|
||||
{
|
||||
@:{
|
||||
@foreach (var field in fields)
|
||||
{
|
||||
@field@:: "@Html.Raw(type.GetProperty(field).GetValue(el, null))",
|
||||
}
|
||||
@:},
|
||||
}
|
||||
];
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#var-table").kendoGrid({
|
||||
dataSource: {
|
||||
data: datas,
|
||||
schema: {
|
||||
model: {
|
||||
fields: {
|
||||
@foreach (var field in fields)
|
||||
{
|
||||
@field@: : { type: "@field.GetType().Name" },
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scrollable: true,
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
columns: [
|
||||
@foreach (var field in fields)
|
||||
{
|
||||
@:{ field: "@field", title: "@field", template: "#=@field#" },
|
||||
}
|
||||
]
|
||||
});
|
||||
@if(docData == null) // choose a doc
|
||||
{
|
||||
<text>
|
||||
$('[id^="choose-"]').on("click", function () {
|
||||
var id = this.id.replace("choose-", '');
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/Account/_addDoc",
|
||||
data: { doctor: id },
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
</text>
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
16
SeniorAssistant/Views/Home/Profile.cshtml.cs
Normal file
16
SeniorAssistant/Views/Home/Profile.cshtml.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace SeniorAssistant.Views.Shared
|
||||
{
|
||||
public class SuccessModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
63
SeniorAssistant/Views/Home/Register.cshtml
Normal file
63
SeniorAssistant/Views/Home/Register.cshtml
Normal file
@@ -0,0 +1,63 @@
|
||||
<ul style="list-style: none">
|
||||
<li class="user-header">
|
||||
<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 />
|
||||
<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>
|
||||
<p id="msg-reg" class="login-box-msg"></p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@Html.ActionLink("Oppure fai il login", "Login")
|
||||
|
||||
<script>
|
||||
$("#register-btn").on("click", function () {
|
||||
var username = $("#regUsername").val();
|
||||
var name = $("#regName").val();
|
||||
var lastname = $("#regLastname").val();
|
||||
var password = $("#regPassword").val();
|
||||
var email = $("#regEmail").val();
|
||||
var code = $("#regDoctor").val();
|
||||
|
||||
var quest = $("#passwQues").val();
|
||||
var answ = $("#passwAnsw").val();
|
||||
|
||||
$.ajax({
|
||||
url: "/Account/_register",
|
||||
data: {
|
||||
Code: code,
|
||||
User: {
|
||||
Username: username,
|
||||
Name: name,
|
||||
Lastname: lastname,
|
||||
Password: password,
|
||||
Email: email
|
||||
},
|
||||
Forgot: {
|
||||
Question: quest,
|
||||
Answer: answ
|
||||
}
|
||||
},
|
||||
dataType: "json",
|
||||
type: "POST",
|
||||
success: function (data) {
|
||||
var msg = $("#msg-reg");
|
||||
if (data.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
msg.html(data.message).show();
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert(error)
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
16
SeniorAssistant/Views/Home/Register.cshtml.cs
Normal file
16
SeniorAssistant/Views/Home/Register.cshtml.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace SeniorAssistant.Views.Shared
|
||||
{
|
||||
public class RegisterModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user