This commit is contained in:
David Štaleker
2024-02-25 20:09:43 +01:00
parent 28d1630749
commit 4df426dc10
614 changed files with 121469 additions and 7647 deletions

View File

@@ -0,0 +1,62 @@
@page "{handler?}"
@model ZpcBulletinBoard.Pages.Boards.AddEditModel
@{
ViewData["Title"] = "Edit board";
Layout = "~/Pages/Shared/_Layout.cshtml";
}
<!-- Editor -->
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
<span>
<span class="text-muted font-weight-light">Nalog /</span>
@if (Model.Board.IdBulletinBoard > 0)
{
<span>Urejanje</span>
}
else
{
<span>Vnos</span>
}
</span>
</h4>
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-body">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Board.IdBulletinBoard" />
<input type="hidden" asp-for="Board.Guid" />
<div class="form-group">
<label asp-for="Board.Name" class="control-label"></label>
<input asp-for="Board.Name" class="form-control" />
<span asp-validation-for="Board.Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Board.Ratio" class="control-label"></label>
<select asp-for="Board.Ratio" class="form-control" asp-items="Html.GetEnumSelectList<Models.Editor.BulletinBoard.RatioEnum>()"></select>
<span asp-validation-for="Board.Ratio" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>
</div>
</div>
</div>
</div>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<!-- Editor -->
<script>
</script>
}

View File

@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using ZpcBulletinBoard.Data;
using ZpcBulletinBoard.Models;
using ZpcBulletinBoard.Models.Editor;
namespace ZpcBulletinBoard.Pages.Boards
{
//[Authorize(Roles = "Administrator,TransportThingUser,InvoicingUser")]
public class AddEditModel(ApplicationDbContext context)
//public class AddEditModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
: PageModel
{
[BindProperty]
public BulletinBoard Board { get; set; }
public async Task<IActionResult> OnGetAsync(Guid? guid)
{
//var user = userManager.GetUserAsync(User).Result;
if (guid == null)
{
Board = new BulletinBoard
{
Ratio = BulletinBoard.RatioEnum.Ratio16To9,
Guid = Guid.NewGuid(),
Notes = new List<Note>()
};
return Page();
}
var tmpBoard = await context.BulletinBoards.Include(x => x.Notes)
.FirstOrDefaultAsync(m => m.Guid == guid);
if (tmpBoard == null)
{
return NotFound();
}
Board = tmpBoard;
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
System.Diagnostics.Debug.WriteLine("OnPost");
//var user = userManager.GetUserAsync(User).Result;
//Board.Notes = new List<Note>();
//if (!ModelState.IsValid)
//{
// System.Diagnostics.Debug.WriteLine(string.Join(",", ModelState.Where(a => a.Value.Errors.Count > 0)
// .Select(b => $"{b.Key} {b.Value.Errors}")));
// return Page();
//}
if (Board.IdBulletinBoard > 0)
{
context.Attach(Board).State = EntityState.Modified;
try
{
await context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!BoardExists(Board.IdBulletinBoard))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToPage("./Index");
}
// OrderNumber and OrderYear
context.BulletinBoards.Add(Board);
await context.SaveChangesAsync();
return RedirectToPage("./Index");
}
private bool BoardExists(int id)
{
return context.BulletinBoards.Any(e => e.IdBulletinBoard == id);
}
}
}

View File

@@ -0,0 +1,69 @@
@page
@model ZpcBulletinBoard.Pages.Boards.IndexModel
@{
ViewData["Title"] = "Oglasne deske - Pregled";
Layout = "~/Pages/Shared/_Layout.cshtml";
}
@section Styles {
<link rel="stylesheet" href="~/vendor/libs/bootstrap-material-datetimepicker/bootstrap-material-datetimepicker.css">
<style type="text/css">
.table > tbody > tr > td:nth-child(2),
.table > thead > tr > th:nth-child(2),
.table > tbody > tr > td:nth-child(3),
.table > thead > tr > th:nth-child(3) {
width: 100px
}
</style>
}
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
<span>
<span class="text-muted font-weight-light">
<i>Oglasne deske</i>
/</span> Pregled
</span>
</h4>
<div class="card">
<h6 class="card-header">
Seznam oglasnih desk
</h6>
<table class="table card-table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Boards[0].Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Boards[0].Ratio)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Boards)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Ratio)
</td>
<td>
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" asp-page="AddEdit" asp-route-guid="@item.Guid" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
</td>
</tr>
}
</tbody>
</table>
<div class="card-footer py-3 text-right">
<a asp-page="AddEdit" class="btn btn-primary">Dodaj novo</a>
</div>
</div>
@section Scripts {
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authorization;
using ZpcBulletinBoard.Data;
using ZpcBulletinBoard.Models.Editor;
namespace ZpcBulletinBoard.Pages.Boards
{
//[Authorize]
public class IndexModel(ApplicationDbContext context) : PageModel
{
public IList<BulletinBoard> Boards { get;set; }
public async Task OnGetAsync()
{
Boards = await context.BulletinBoards.ToListAsync();
}
}
}

View File

@@ -0,0 +1,73 @@
@page
@model EditMainModel
@{
ViewData["Title"] = "Urejanje";
}
@section Styles
{
<link rel="stylesheet" href="~/lib/summernote/summernote-bs4.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/css/editor/editor-main.css" asp-append-version="true"/>
}
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body div-main-body">
<div class="form-inline div-tools">
<select class="form-control input-xs">
<option id="1">Prvi board</option>
<option id="2">Drugi</option>
<option id="3">sad</option>
</select>
<div class="btn-group">
<button type="button" class="btn btn-default btn-sm">
<i class="far fa-plus"></i>
</button>
<button type="button" class="btn btn-default btn-sm">
<i class="fas fa-trash-alt"></i>
</button>
</div>
<button class="btn btn-sm btn-primary">Shrani</button>
</div>
<hr/>
<div id="divPlaceholder">
</div>
</div>
</div>
</div>
</div>
<div id="divModalEditNote" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Urejanje zapiska</h5>
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<input id="inpModalEditNoteIdNote" class="input-hidden"/>
<div id="divModalEditNoteSummernote"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="saveModalEditNote();">Save changes</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@section Scripts
{
<script src="~/lib/summernote/summernote-bs4.js" asp-append-version="true"></script>
<script src="~/lib/html-to-image/dist/html-to-image.js" asp-append-version="true"></script>
<script src="~/js/editor/note.js" asp-append-version="true"></script>
<script src="~/js/editor/edit-main.js" asp-append-version="true"></script>
}

View File

@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ZpcBulletinBoard.Pages.Editor
{
public class EditMainModel(ILogger<EditMainModel> logger) : PageModel
{
private readonly ILogger<EditMainModel> _logger = logger;
public void OnGet()
{
}
}
}

View File

@@ -12,9 +12,9 @@ namespace ZpcBulletinBoard.Pages
_logger = logger;
}
public void OnGet()
public IActionResult OnGet()
{
return Redirect("~/Editor/EditMain");
}
}
}

View File

@@ -15,8 +15,11 @@
<div class="sidenav-divider mt-0"></div>
<ul class="sidenav-inner">
<li class="sidenav-item@(currentPage == "/Index" ? " active" : "")">
<li class="sidenav-item@(currentPage.StartsWith("/Editor")? " active" : "")">
<a asp-page="/Index" class="sidenav-link"><i class="sidenav-icon fas fa-home"></i><div>Urejevalnik</div></a>
</li>
<li class="sidenav-item@(currentPage.StartsWith("/Boards") ? " active" : "")">
<a asp-page="/Boards/Index" class="sidenav-link"><i class="sidenav-icon fas fa-home"></i><div>Oglasne deske</div></a>
</li>
</ul>
</div>

View File

@@ -14,6 +14,8 @@
<!-- jQuery -->
<script src="~/lib/jquery/dist/jquery.min.js" asp-append-version="true"></script>
<script src="~/lib/jquery-ui/dist/jquery-ui.min.js" asp-append-version="true"></script>
<link href="~/lib/jquery-ui/dist/themes/base/jquery-ui.css" asp-append-version="true"></link>
@* <script src="~/lib/jquery-ajax-unobtrusive/dist/jquery.unobtrusive-ajax.min.js"></script> *@
<!-- Icons -->
@@ -51,7 +53,7 @@
@await Html.PartialAsync("Shared/_ValidationScriptsPartial")
<!-- Libs -->
@* <script src="~/node_modules/popper/popper.js" asp-append-version="true"></script> *@
<script src="~/lib/popper/popper.js" asp-append-version="true"></script>
<script src="~/lib/perfect-scrollbar/dist/perfect-scrollbar.js" asp-append-version="true"></script>
<script src="~/lib/bootstrap-select/dist/js/bootstrap-select.js" asp-append-version="true"></script>
<script src="~/lib/moment/min/moment.min.js" asp-append-version="true"></script>
@@ -64,7 +66,7 @@
<script src="~/lib/sweetalert2/dist/sweetalert2.js"></script>
<!-- Custom -->
<script src="~/lib/jquery/dist/jquery.min.js"></script>
@* <script src="~/lib/jquery/dist/jquery.min.js"></script> *@
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>

View File

@@ -0,0 +1,76 @@
@page "{handler?}"
@using Microsoft.AspNetCore.Http.Extensions
@using Microsoft.AspNetCore.Http
@model ZpcBulletinBoard.Pages.User.LoginModel
@{
ViewData["Title"] = "Prijava";
Layout = "~/Pages/Shared/_Layout.cshtml";
}
@section Styles {
<link rel="stylesheet" href="~/vendor/css/pages/authentication.css">
<style>
.help-block ul {
list-style-type: none;
}
</style>
}
<div class="authentication-wrapper authentication-3">
<div class="authentication-inner">
<div class="d-none d-lg-flex col-lg-9 align-items-center ui-bg-cover ui-bg-overlay-container p-5" style="background-image: url('/img/bg/login.jpg');">
<div class="ui-bg-overlay bg-dark opacity-50"></div>
<div class="w-100 text-white px-5">
<h1 class="display-2 font-weight-bolder mb-4">
EveryThing
</h1>
<div class="text-large font-weight-light">
Oblačna aplikacija
</div>
</div>
</div>
<div class="d-flex col-lg-3 align-items-center bg-white p-5">
<div class="d-flex col-sm-7 col-md-5 col-lg-12 px-0 px-xl-4 mx-auto">
<div class="w-100">
<div class="text-center">
<span style="font-size: 6rem" class="fas fa-user"></span>
</div>
<h4 class="text-center text-light font-weight-normal mt-5 mb-0">Prijava uporabnika</h4>
<form asp-antiforgery="false" method="post" class="my-5">
<div class="form-group">
<label asp-for="Input.UserName" class="form-label"></label>
<input asp-for="Input.UserName" type="text" class="form-control" />
<span asp-validation-for="Input.UserName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Password" class="form-label"></label>
<input asp-for="Input.Password" type="password" class="form-control" />
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="d-flex justify-content-between align-items-center m-0">
<label class="custom-control custom-checkbox m-0">
<input type="checkbox" asp-for="Input.RememberLogin" class="custom-control-input">
<span class="custom-control-label">Zapomni si prijavo</span>
</label>
<button type="submit" class="btn btn-primary">Prijava</button>
</div>
</form>
<div class="text-center text-muted">
Ste pozabili geslo? <a href="javascript:void(0)">Kliknite tukaj za ponastavitev</a>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,291 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using ZpcBulletinBoard.Models;
namespace ZpcBulletinBoard.Pages.User
{
[IgnoreAntiforgeryToken(Order = 1005)]
[AllowAnonymous]
public class LoginModel : PageModel
{
private readonly UserManager<IdentityApplicationUser> _userManager;
private readonly SignInManager<IdentityApplicationUser> _loginManager;
private readonly RoleManager<IdentityApplicationRole> _roleManager;
//private readonly ILogger<LogoutModel> _logger;
public LoginModel(UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager)
{
_userManager = userManager;
_loginManager = loginManager;
_roleManager = roleManager;
//_logger = logger;
}
[BindProperty]
public InputModel Input { get; set; }
public IActionResult OnGetToken()
{
return new ObjectResult(new {id = 0});
}
public IActionResult OnGet()
{
//IdentityApplicationUser identityApplicationUser = new IdentityApplicationUser
//{
// Name = "Master",
// Surname = "Admin",
// UserName = "admin",
// NormalizedUserName = "admin",
// Email = "admin@domain.com",
// NormalizedEmail = "admin@domain.com",
// EmailConfirmed = true,
// DateCreated = DateTime.Now,
// DateValidUntil = DateTime.MaxValue,
// PhoneNumber = "123456789",
// PhoneNumberConfirmed = true,
// Active = true,
// IdCompanyFk = 1
//};
//IdentityResult identityResult = _userManager.CreateAsync(identityApplicationUser, "Master#Admin22!").Result;
//if (identityResult.Succeeded)
//{
// if (!_roleManager.RoleExistsAsync("TransportThingUser").Result)
// {
// IdentityApplicationRole normalUserRole = new IdentityApplicationRole
// {
// Name = "TransportThingUser",
// Description = "TransporThing uporabniki"
// };
// _roleManager.CreateAsync(normalUserRole).Wait();
// }
// if (!_roleManager.RoleExistsAsync("ProjecThingUser").Result)
// {
// IdentityApplicationRole normalUserRole = new IdentityApplicationRole
// {
// Name = "ProjecThingUser",
// Description = "ProjecThing uporabniki"
// };
// _roleManager.CreateAsync(normalUserRole).Wait();
// }
// if (!_roleManager.RoleExistsAsync("Administrator").Result)
// {
// IdentityApplicationRole normalUserRole = new IdentityApplicationRole
// {
// Name = "Administrator",
// Description = "Administratorji"
// };
// _roleManager.CreateAsync(normalUserRole).Wait();
// }
// _userManager.AddToRoleAsync(identityApplicationUser, "Administrator").Wait();
// //return RedirectToPage("/Administration/Users/Index");
//}
//else
//{
// ModelState.AddModelError("", string.Join(",", identityResult.Errors.Select(x => x.Description)));
//}
return Page();
}
public async Task<IActionResult> OnPostAsync(string returnUrl)
{
returnUrl ??= Url.Content("~/");
if (!ModelState.IsValid)
{
return Page();
}
if (ModelState.IsValid)
{
var result = await _loginManager.PasswordSignInAsync(Input.UserName, Input.Password, Input.RememberLogin, false);
if (result.Succeeded)
{
// to get current user info
//var user = await _userManager.FindByNameAsync(Input.UserName);
//var user = await _userManager.GetUserAsync(User);
//_logger.LogInformation($"Login: {user.Name} {user.Surname} - {user.Company.Title}");
return RedirectToPage("/Index");
}
if (result.IsLockedOut)
{
//var user = await _userManager.GetUserAsync(User); //TODO: ?? verjetno ne bo delalo
//_logger.LogInformation($"LoginLocked: {user.Name} {user.Surname} - {user.Company.Title}");
ModelState.AddModelError("", "Uporabnik je zaklenjen!");
}
else
{
//_logger.LogInformation($"LoginFail: {Input.UserName}");
ModelState.AddModelError("", "Nepravilna prijava!");
}
}
return Page();
}
//public async Task<IActionResult> Login([FromBody] UserLoginRequest user)
//{
// if (ModelState.IsValid)
// {
// // check if the user with the same email exist
// var existingUser = await _userManager.FindByEmailAsync(user.Email);
// if (existingUser == null)
// {
// // We dont want to give to much information on why the request has failed for security reasons
// return BadRequest(new RegistrationResponse()
// {
// Result = false,
// Errors = new List<string>(){
// "Invalid authentication request"
// }
// });
// }
// // Now we need to check if the user has inputed the right password
// var isCorrect = await _userManager.CheckPasswordAsync(existingUser, user.Password);
// if (isCorrect)
// {
// var jwtToken = GenerateJwtToken(existingUser);
// return Ok(new RegistrationResponse()
// {
// Result = true,
// Token = jwtToken
// });
// }
// else
// {
// // We dont want to give to much information on why the request has failed for security reasons
// return BadRequest(new RegistrationResponse()
// {
// Result = false,
// Errors = new List<string>(){
// "Invalid authentication request"
// }
// });
// }
// }
// return BadRequest(new RegistrationResponse()
// {
// Result = false,
// Errors = new List<string>(){
// "Invalid payload"
// }
// });
//}
//private string GenerateJwtToken(IdentityUser user)
//{
// // Now its ime to define the jwt token which will be responsible of creating our tokens
// var jwtTokenHandler = new JwtSecurityTokenHandler();
// // We get our secret from the appsettings
// var key = Encoding.ASCII.GetBytes(_jwtConfig.Secret);
// // we define our token descriptor
// // We need to utilise claims which are properties in our token which gives information about the token
// // which belong to the specific user who it belongs to
// // so it could contain their id, name, email the good part is that these information
// // are generated by our server and identity framework which is valid and trusted
// var tokenDescriptor = new SecurityTokenDescriptor
// {
// Subject = new ClaimsIdentity(new[]
// {
// new Claim("Id", user.Id),
// new Claim(JwtRegisteredClaimNames.Sub, user.Email),
// new Claim(JwtRegisteredClaimNames.Email, user.Email),
// // the JTI is used for our refresh token which we will be convering in the next video
// new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
// }),
// // the life span of the token needs to be shorter and utilise refresh token to keep the user signedin
// // but since this is a demo app we can extend it to fit our current need
// Expires = DateTime.UtcNow.AddHours(6),
// // here we are adding the encryption alogorithim information which will be used to decrypt our token
// SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha512Signature)
// };
// var token = jwtTokenHandler.CreateToken(tokenDescriptor);
// var jwtToken = jwtTokenHandler.WriteToken(token);
// return jwtToken;
//}
//public async Task<IActionResult> OnPostTokenAsync(string userName, string password)
//{
// var user = await _userManager.FindByNameAsync(userName);
// if (user != null)
// {
// var result = await _loginManager.UserManager.CheckPasswordAsync(user, password);
// if (result)
// {
// var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("!Appli$cation#2021#!"));
// var claims = new []
// {
// new Claim(JwtRegisteredClaimNames.Name, user.Name),
// new Claim(JwtRegisteredClaimNames.Email, user.Email),
// new Claim(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(DateTime.Now.AddDays(1)).ToUnixTimeSeconds()}"), //TODO skrajšaj
// new Claim(JwtRegisteredClaimNames.Iss, "EveryThing"),
// new Claim(JwtRegisteredClaimNames.Aud, "Android"),
// new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"),
// new Claim(JwtRegisteredClaimNames.Iat, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"),
// new Claim(JwtRegisteredClaimNames.Jti, $"{Guid.NewGuid()}")
// };
// var token = new JwtSecurityToken(new JwtHeader(new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256)), new JwtPayload(claims));
// string jwtToken = new JwtSecurityTokenHandler().WriteToken(token);
// return new ObjectResult(jwtToken);
// }
// }
// return BadRequest();
//}
public class InputModel
{
[Required(ErrorMessage = "Polje uporabniško ime je obvezno")]
[Display(Name = "Uporabniško ime")]
public string UserName { get; set; }
[Required(ErrorMessage = "Polje geslo je obvezno")]
[DataType(DataType.Password)]
[Display(Name = "Geslo")]
public string Password { get; set; }
public bool RememberLogin { get; set; }
}
}
}

View File

@@ -0,0 +1,6 @@
@page
@model ZpcBulletinBoard.Pages.User.LogoutModel
@{
ViewData["Title"] = "Odjava";
Layout = "~/Pages/Shared/_Layout.cshtml";
}

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using ZpcBulletinBoard.Models;
namespace ZpcBulletinBoard.Pages.User
{
[Authorize]
public class LogoutModel : PageModel
{
private readonly UserManager<IdentityApplicationUser> _userManager;
private readonly SignInManager<IdentityApplicationUser> _signInManager;
private readonly ILogger<LogoutModel> _logger;
public LogoutModel(UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> signInManager, ILogger<LogoutModel> logger)
{
_userManager = userManager;
_signInManager = signInManager;
_logger = logger;
}
public async Task<IActionResult> OnGetAsync()
{
var user = await _userManager.GetUserAsync(User);
await _signInManager.SignOutAsync();
//_logger.LogInformation($"Logout: {user.Name} {user.Surname} - {user.Company.Title}");
//if (returnUrl != null)
//{
// return LocalRedirect(returnUrl);
//}
return RedirectToPage();
}
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
var user = await _userManager.GetUserAsync(User);
await _signInManager.SignOutAsync();
_logger.LogInformation($"Logout: {user.Name} {user.Surname}");
if (returnUrl != null)
{
return LocalRedirect(returnUrl);
}
return RedirectToPage();
}
}
}