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(() =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user