From 1739314aefd58b458454a0ca017643392fffd3fa Mon Sep 17 00:00:00 2001 From: Giacomo Date: Tue, 4 Dec 2018 16:40:24 +0100 Subject: [PATCH] Migliorato login/logout Ma forse si passa alla versione con modelli per login e register in futuro --- .../Controllers/AccountController.cs | 131 +----------------- SeniorAssistant/Controllers/HomeController.cs | 8 +- .../Views/Home/{User.cshtml => Data.cshtml} | 0 SeniorAssistant/Views/Home/Index.cshtml | 63 ++------- SeniorAssistant/Views/Home/Users.cshtml | 53 +++++++ SeniorAssistant/Views/Shared/Login.cshtml | 23 ++- SeniorAssistant/Views/Shared/Logout.cshtml | 46 +++++- .../Views/Shared/NavbarRightMenu.cshtml | 44 +----- SeniorAssistant/Views/Shared/Register.cshtml | 45 ++++++ .../Views/Shared/Register.cshtml.cs | 16 +++ SeniorAssistant/senior.db | Bin 196608 -> 196608 bytes 11 files changed, 194 insertions(+), 235 deletions(-) rename SeniorAssistant/Views/Home/{User.cshtml => Data.cshtml} (100%) create mode 100644 SeniorAssistant/Views/Home/Users.cshtml create mode 100644 SeniorAssistant/Views/Shared/Register.cshtml create mode 100644 SeniorAssistant/Views/Shared/Register.cshtml.cs diff --git a/SeniorAssistant/Controllers/AccountController.cs b/SeniorAssistant/Controllers/AccountController.cs index 744ab7a..d33ac8b 100644 --- a/SeniorAssistant/Controllers/AccountController.cs +++ b/SeniorAssistant/Controllers/AccountController.cs @@ -71,137 +71,14 @@ namespace IdentityDemo.Controllers return Json(new JsonResponse()); } + public ActionResult _register() + { + return Json(new JsonResponse()); + } internal class JsonResponse { public bool Success { get; internal set; } public string Message { get; internal set; } } - /* - [HttpPost] - [AllowAnonymous] - [ValidateAntiForgeryToken] - public async Task Login(LoginViewModel model, string returnUrl = null) - { - ViewData["ReturnUrl"] = returnUrl; - if (ModelState.IsValid) - { - // This doesn't count login failures towards account lockout - // To enable password failures to trigger account lockout, set lockoutOnFailure: true - var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false); - if (result.Succeeded) - { - _logger.LogInformation("User logged in."); - return RedirectToLocal(returnUrl); - } - if (result.IsLockedOut) - { - _logger.LogWarning("User account locked out."); - return RedirectToAction(nameof(Lockout)); - } - else - { - ModelState.AddModelError(string.Empty, "Invalid login attempt."); - return View(model); - } - } - - // If we got this far, something failed, redisplay form - return View(model); - } - - [HttpGet] - [AllowAnonymous] - public IActionResult Lockout() - { - return View(); - } - - [HttpGet] - [AllowAnonymous] - public IActionResult Register(string returnUrl = null) - { - ViewData["ReturnUrl"] = returnUrl; - return View(); - } - - [HttpPost] - [AllowAnonymous] - [ValidateAntiForgeryToken] - public async Task Register(RegisterViewModel model, string returnUrl = null) - { - ViewData["ReturnUrl"] = returnUrl; - if (ModelState.IsValid) - { - var user = new User { UserName = model.Email, Email = model.Email }; - var result = await _userManager.CreateAsync(user, model.Password); - if (result.Succeeded) - { - await _signInManager.SignInAsync(user, isPersistent: false); - _logger.LogInformation("User created a new account with password."); - return RedirectToLocal(returnUrl); - } - AddErrors(result); - } - - // If we got this far, something failed, redisplay form - return View(model); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Logout() - { - await _signInManager.SignOutAsync(); - _logger.LogInformation("User logged out."); - return RedirectToAction(nameof(HomeController.Index), "Home"); - } - - [HttpGet] - [AllowAnonymous] - public async Task ConfirmEmail(string userId, string code) - { - if (userId == null || code == null) - { - return RedirectToAction(nameof(HomeController.Index), "Home"); - } - var user = await _userManager.FindByIdAsync(userId); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{userId}'."); - } - var result = await _userManager.ConfirmEmailAsync(user, code); - return View(result.Succeeded ? "ConfirmEmail" : "Error"); - } - - [HttpGet] - public IActionResult AccessDenied() - { - return View(); - } - - #region Helpers - - private void AddErrors(IdentityResult result) - { - foreach (var error in result.Errors) - { - ModelState.AddModelError(string.Empty, error.Description); - } - } - - private IActionResult RedirectToLocal(string returnUrl) - { - if (Url.IsLocalUrl(returnUrl)) - { - return Redirect(returnUrl); - } - else - { - return RedirectToAction(nameof(HomeController.Index), "Home"); - } - } - - #endregion - */ } } \ No newline at end of file diff --git a/SeniorAssistant/Controllers/HomeController.cs b/SeniorAssistant/Controllers/HomeController.cs index 56a2439..4ee48c6 100644 --- a/SeniorAssistant/Controllers/HomeController.cs +++ b/SeniorAssistant/Controllers/HomeController.cs @@ -38,10 +38,16 @@ namespace SeniorAssistant.Controllers return View(); } + [Route("Users")] + public IActionResult Users() + { + return View(); + } + [Route("User/{User}")] public IActionResult SingleUser(string user) { - return View("user", user); + return View("data", user); } } } \ No newline at end of file diff --git a/SeniorAssistant/Views/Home/User.cshtml b/SeniorAssistant/Views/Home/Data.cshtml similarity index 100% rename from SeniorAssistant/Views/Home/User.cshtml rename to SeniorAssistant/Views/Home/Data.cshtml diff --git a/SeniorAssistant/Views/Home/Index.cshtml b/SeniorAssistant/Views/Home/Index.cshtml index 4c30ece..8733407 100644 --- a/SeniorAssistant/Views/Home/Index.cshtml +++ b/SeniorAssistant/Views/Home/Index.cshtml @@ -1,53 +1,10 @@ -@model IEnumerable -@{ - ViewBag.Title = "Hello Razor"; -} - -
- - \ No newline at end of file + +

+ ciao noob +

\ No newline at end of file diff --git a/SeniorAssistant/Views/Home/Users.cshtml b/SeniorAssistant/Views/Home/Users.cshtml new file mode 100644 index 0000000..4c30ece --- /dev/null +++ b/SeniorAssistant/Views/Home/Users.cshtml @@ -0,0 +1,53 @@ +@model IEnumerable +@{ + ViewBag.Title = "Hello Razor"; +} + +
+ + \ No newline at end of file diff --git a/SeniorAssistant/Views/Shared/Login.cshtml b/SeniorAssistant/Views/Shared/Login.cshtml index d61cf90..ca1aefd 100644 --- a/SeniorAssistant/Views/Shared/Login.cshtml +++ b/SeniorAssistant/Views/Shared/Login.cshtml @@ -1,9 +1,18 @@ -
- - - - -
+ + + + + + \ No newline at end of file + diff --git a/SeniorAssistant/Views/Shared/Logout.cshtml b/SeniorAssistant/Views/Shared/Logout.cshtml index 30351db..a8c161e 100644 --- a/SeniorAssistant/Views/Shared/Logout.cshtml +++ b/SeniorAssistant/Views/Shared/Logout.cshtml @@ -1,6 +1,44 @@ -
- -
+@model string + + + User Image + + + + \ No newline at end of file diff --git a/SeniorAssistant/Views/Shared/Register.cshtml.cs b/SeniorAssistant/Views/Shared/Register.cshtml.cs new file mode 100644 index 0000000..c7f3879 --- /dev/null +++ b/SeniorAssistant/Views/Shared/Register.cshtml.cs @@ -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() + { + } + } +} \ No newline at end of file diff --git a/SeniorAssistant/senior.db b/SeniorAssistant/senior.db index b3d5cc582ec875eea4e8ebc9ed97cb625d1759a0..7a770588d4ca15f36060e22d6707608652ec13c3 100644 GIT binary patch delta 1279 zcmb`FT}V@57=ZV_+u6?Mne*RG96QU)s7-}`-mfDi}> z!2;yD{=zD@MjCHAGDb9p^a&07T$U@AR!dbhODwTK9yyP*<+~qDdNi}Fh2SXI$o>I% zZl3+8E16R^I@FE^<&vu~I_4^Mr%>)Bs*$1cQz$NhqUmlHbj&g|{6%H_gF1bx6S>dI z_Shq3{+;#OjGn5!$VaoLr*!1uz--)FUg9oyyS3g$C+Qm)qV}(jg8!~k?RxmK*T@{Y zG;xh_6Y&zXqEVqv33}8y2`c$S3+0H*NPZtXf2$A5=&Wyrghc*6mZ-Q6y!ze;8};jm zYlF?Z^?s&i86Z9kH_*~Ux5H4W{s_YhK#fLyI1FzDiig2!Do&22HZgEz%(a-H$>-o+ zGew;o2Y08g4U04skf6YX_pt>p;w~&w4##ZDwu}vG^A3Clbkd0enHRt$l#0tvbp#9S zJxNhCsm)b5WL_Uq9S(V*jkq9oVA@OS3gQX%QxNZ&U?&wVi`$;s9%0L z_2eHwtNMEoIo(?7@3VUCF|?5(j86r8i+8aPo6v){Nbf$-I^_lmji6On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