Jelszó módosítása
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using Serilog;
|
||||
using System.Net.Http;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
|
||||
namespace WorkFlowCheck.Web.Helpers
|
||||
{
|
||||
public static class SystemHelper
|
||||
{
|
||||
public static string DatabaseName = "";
|
||||
public async static Task GetAPIInfoAsync(IConfiguration configuration)
|
||||
{
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
|
||||
|
||||
var apiBaseUrl = configuration["ApiBaseUrl"]; // API-cím elérése a konfigurációból
|
||||
httpClient.BaseAddress = new Uri(apiBaseUrl);
|
||||
|
||||
var apiKey = configuration["ApiKey"];
|
||||
httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
|
||||
|
||||
string endpoint = $"{httpClient.BaseAddress}api/System/GetDatabaseAndVersionInfo";
|
||||
var retVal = new RoleDTO();
|
||||
try
|
||||
{
|
||||
var response = await httpClient.GetFromJsonAsync<ApiResponseDTO<string>>(endpoint);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
DatabaseName = response.Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
@page "{userId:int?}"
|
||||
@model WorkFlowCheck.Web.Pages.Account.ChangePasswordModel
|
||||
@using WorkFlowCheck.Common.Helper
|
||||
@using WorkFlowCheck.Common.DTO
|
||||
@using Microsoft.AspNetCore.Antiforgery
|
||||
@inject IAntiforgery Antiforgery
|
||||
@{
|
||||
Layout = null;
|
||||
ViewData["Title"] = "Jelszó módosítása";
|
||||
}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="hu">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>@ViewData["Title"]</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-light d-flex justify-content-center align-items-center vh-100">
|
||||
<div class="card shadow p-4" style="min-width: 350px; max-width: 400px; width: 100%;">
|
||||
<h2 class="mb-4 text-center">Jelszó módosítása</h2>
|
||||
|
||||
<div id="errorMessageContainer" class="alert alert-danger" style="display:none;"></div>
|
||||
|
||||
<form method="post">
|
||||
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
|
||||
<input type="hidden" asp-for="UserChangePassword2FADTO.UserId" />
|
||||
<input type="hidden" asp-for="UserChangePassword2FADTO.Token2FA" />
|
||||
<div class="mb-3">
|
||||
<label asp-for="UserChangePassword2FADTO.UserName" class="form-label"></label>
|
||||
<input asp-for="UserChangePassword2FADTO.UserName" class="form-control" disabled />
|
||||
<span asp-validation-for="UserChangePassword2FADTO.UserName" class="text-danger small"></span>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="UserChangePassword2FADTO.OldPassword" class="form-label"></label>
|
||||
<input asp-for="UserChangePassword2FADTO.OldPassword" type="password" class="form-control" />
|
||||
<span asp-validation-for="UserChangePassword2FADTO.OldPassword" class="text-danger small"></span>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="UserChangePassword2FADTO.NewPassword1" class="form-label"></label>
|
||||
<input asp-for="UserChangePassword2FADTO.NewPassword1" type="password" class="form-control" />
|
||||
<span asp-validation-for="UserChangePassword2FADTO.NewPassword1" class="text-danger small"></span>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="UserChangePassword2FADTO.NewPassword2" class="form-label"></label>
|
||||
<input asp-for="UserChangePassword2FADTO.NewPassword2" type="password" class="form-control" />
|
||||
<span asp-validation-for="UserChangePassword2FADTO.NewPassword2" class="text-danger small"></span>
|
||||
</div>
|
||||
<div id="VerificationCode" class="mb-3">
|
||||
<label asp-for="UserChangePassword2FADTO.Code" class="form-label"></label>
|
||||
<input asp-for="UserChangePassword2FADTO.Code" class="form-control" />
|
||||
<span asp-validation-for="UserChangePassword2FADTO.Code" class="text-danger small"></span>
|
||||
</div>
|
||||
<hr class="mt-4 mb-3 border-secondary">
|
||||
<div id="login2F1" class="d-grid">
|
||||
<button id="Login2F1Btn" type="button" class="btn btn-primary">Bejelentkezés</button>
|
||||
</div>
|
||||
<div id="login2F2" class="d-grid">
|
||||
<button id="Login2F2Btn" type="button" class="btn btn-primary">Megerősítés</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Message Modal -->
|
||||
<div class="modal fade" id="messageModal" tabindex="-1" aria-labelledby="messageModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="messageModalLabel">Üzenet</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Bezárás"></button>
|
||||
</div>
|
||||
<div class="modal-body" id="messageModalBody">
|
||||
Ez egy információs üzenet.
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" id="messageModalOkBtn" data-bs-dismiss="modal">OK</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/jquery.validate.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery-validation-unobtrusive@4.0.0/dist/jquery.validate.unobtrusive.min.js"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#VerificationCode').hide();
|
||||
$('#login2F2').hide();
|
||||
$('#Login2F2Btn').hide();
|
||||
|
||||
$('#UserChangePassword2FADTO_UserName').attr('readonly', true);
|
||||
|
||||
$('#Login2F1Btn').on('click', function () {
|
||||
// $('#Login2F1Btn, #Login2F2Btn').prop('disabled', true);
|
||||
$('#errorMessageContainer').hide().text('');
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||
const userName = $('#UserChangePassword2FADTO_UserName').val();
|
||||
const password = $('#UserChangePassword2FADTO_OldPassword').val();
|
||||
|
||||
$.ajax({
|
||||
url: '/Account/ChangePassword?handler=Login2F1',
|
||||
type: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
UserName: userName,
|
||||
Password: password
|
||||
}),
|
||||
success: function (result) {
|
||||
if (result.success) {
|
||||
$('#login2F1').hide();
|
||||
$('#Login2F1Btn').hide();
|
||||
$('#VerificationCode').show();
|
||||
$('#login2F2').show();
|
||||
$('#Login2F2Btn').show();
|
||||
$('#UserChangePassword2FADTO_Token2FA').val(result.data)
|
||||
} else {
|
||||
$('#errorMessageContainer').text('Hibás felhasználónév vagy jelszó!').show();
|
||||
// $('#Login2F1Btn, #Login2F2Btn')
|
||||
// .prop('disabled', false)
|
||||
// .removeAttr('disabled')
|
||||
// .removeClass('disabled');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$('#errorMessageContainer').text('Hiba történt a kérés során.').show();
|
||||
// $('#Login2F1Btn, #Login2F2Btn')
|
||||
// .prop('disabled', false)
|
||||
// .removeAttr('disabled')
|
||||
// .removeClass('disabled');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$('#Login2F2Btn').on('click', function () {
|
||||
// $('#Login2F1Btn, #Login2F2Btn').prop('disabled', true);
|
||||
$('#errorMessageContainer').hide().text('');
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||
|
||||
const userName = $('#UserChangePassword2FADTO_UserName').val();
|
||||
const password = $('#UserChangePassword2FADTO_OldPassword').val();
|
||||
const newpassword1 = $('#UserChangePassword2FADTO_NewPassword1').val();
|
||||
const newpassword2 = $('#UserChangePassword2FADTO_NewPassword2').val();
|
||||
const code = $('#UserChangePassword2FADTO_Code').val();
|
||||
const token2FA = $('#UserChangePassword2FADTO_Token2FA').val();
|
||||
|
||||
$.ajax({
|
||||
url: '/Account/ChangePassword?handler=Login2F2',
|
||||
type: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
UserId: 0,
|
||||
UserName: userName,
|
||||
OldPassword: password,
|
||||
NewPassword1: newpassword1,
|
||||
NewPassword2: newpassword2,
|
||||
Code: code,
|
||||
Token2FA: token2FA
|
||||
}),
|
||||
success: function (result) {
|
||||
if (result.success) {
|
||||
showMessageModal({
|
||||
title: 'Információ',
|
||||
message: 'A jelszó módosítása sikerült!',
|
||||
okText: 'Értettem',
|
||||
redirectUrl: '/Index'
|
||||
});
|
||||
} else {
|
||||
$('#errorMessageContainer').text('Hibás felhasználónév vagy jelszó!').show();
|
||||
// $('#Login2F1Btn, #Login2F2Btn')
|
||||
// .prop('disabled', false)
|
||||
// .removeAttr('disabled')
|
||||
// .removeClass('disabled');
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
console.log(xhr.status);
|
||||
console.log(xhr.responseText);
|
||||
$('#errorMessageContainer').text('Hiba történt a kérés során.').show();
|
||||
// $('#Login2F1Btn, #Login2F2Btn')
|
||||
// .prop('disabled', false)
|
||||
// .removeAttr('disabled')
|
||||
// .removeClass('disabled');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('input').on('input', function () {
|
||||
$('#errorMessageContainer').hide().text('');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<partial name="_ValidationScriptsPartial" />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity.Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Security.Claims;
|
||||
using System.Text.Json;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.Web.Services.Interfaces;
|
||||
|
||||
namespace WorkFlowCheck.Web.Pages.Account
|
||||
{
|
||||
[Authorize]
|
||||
[ValidateAntiForgeryToken]
|
||||
public class ChangePasswordModel : PageModel
|
||||
{
|
||||
private readonly IUserService _userService;
|
||||
|
||||
[BindProperty]
|
||||
public UserChangePassword2FADTO UserChangePassword2FADTO { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public ChangePasswordModel(IUserService userService)
|
||||
{
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task OnGet()
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var user = await _userService.GetUser(int.Parse(userId));
|
||||
if (user != null && user.Id > 0)
|
||||
{
|
||||
|
||||
UserChangePassword2FADTO = new UserChangePassword2FADTO()
|
||||
{
|
||||
UserName = user.UserName,
|
||||
UserId = user.Id,
|
||||
};
|
||||
}
|
||||
}
|
||||
public async Task<IActionResult> OnPostLogin2F1([FromBody] UserSimpleDTO userSimpleDTO)
|
||||
{
|
||||
|
||||
if (userSimpleDTO != null)
|
||||
{
|
||||
var response = await _userService.Authenticate2F1(userSimpleDTO.UserName, userSimpleDTO.Password);
|
||||
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
return new JsonResult(new { success = true, data = response.Data });
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = "Hibás bejelentkezés!";
|
||||
return new JsonResult(new { success = false });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = "Hibás bejelentkezés!";
|
||||
return new JsonResult(new { success = false });
|
||||
}
|
||||
}
|
||||
public async Task<IActionResult> OnPostLogin2F2([FromBody] UserChangePassword2FADTO userChangePassword2FADTO)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var user = await _userService.GetUser(int.Parse(userId));
|
||||
userChangePassword2FADTO.UserId = user.Id;
|
||||
var response = await _userService.Authenticate2F2ChangePassword(userChangePassword2FADTO.UserName,
|
||||
userChangePassword2FADTO.OldPassword,
|
||||
userChangePassword2FADTO.NewPassword1,
|
||||
userChangePassword2FADTO.Code,
|
||||
userChangePassword2FADTO.Token2FA);
|
||||
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
|
||||
var token = response.Data.JwtToken;
|
||||
|
||||
Response.Cookies.Append("AuthToken", token, new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Expires = DateTimeOffset.UtcNow.AddMinutes(30)
|
||||
});
|
||||
|
||||
return new JsonResult(new { success = true });
|
||||
}
|
||||
|
||||
ErrorMessage = "Hibás bejelentkezés!";
|
||||
return new JsonResult(new { success = false });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="hu">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
@@ -64,11 +66,24 @@
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" href="#" data-bs-toggle="modal" data-bs-target="#logoutModal">
|
||||
<i class="bi bi-box-arrow-right"></i>Logout (@User.Identity.Name)
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle text-dark" href="#" id="accountDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Adataim
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="accountDropdown">
|
||||
<li class="dropdown-item">
|
||||
<a class="nav-link text-dark" href="#" data-bs-toggle="modal" data-bs-target="#logoutModal">
|
||||
<i class="bi bi-box-arrow-right"></i>Logout (@User.Identity.Name)
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" asp-area="" asp-page="/Account/ChangePassword">
|
||||
Jelszó módosítása
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -138,7 +153,7 @@
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© @DateTime.Now.Year - Workflow Check App - Version v1.1.003 <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
© @DateTime.Now.Year - Workflow Check App - Version v1.1.003 (@SystemHelper.DatabaseName)<a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@using WorkFlowCheck.Web
|
||||
@using WorkFlowCheck.Web.Helpers
|
||||
@namespace WorkFlowCheck.Web.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.IdentityModel.Tokens;
|
||||
using Serilog;
|
||||
using System.Text;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.Web.Helpers;
|
||||
using WorkFlowCheck.Web.Middleware;
|
||||
using WorkFlowCheck.Web.Services;
|
||||
using WorkFlowCheck.Web.Services.Interfaces;
|
||||
@@ -61,6 +62,11 @@ builder.WebHost.ConfigureKestrel(options =>
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var config = scope.ServiceProvider.GetRequiredService<IConfiguration>();
|
||||
await SystemHelper.GetAPIInfoAsync(config);
|
||||
}
|
||||
|
||||
//----------------- Munkakönyvtárak létrehozása -----------------------------
|
||||
string imageDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Images");
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace WorkFlowCheck.Web.Services.Interfaces
|
||||
Task<ApiResponseDTO<UserDTO>> UpdateUser(UserDTO userDTO);
|
||||
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
|
||||
Task<ApiResponseDTO<string>> Authenticate2F1(string username, string password);
|
||||
Task<ApiResponseDTO<UserDTO>> Authenticate2F2(string userName, string password, string code, string token2FA);
|
||||
Task<ApiResponseDTO<UserDTO>> Authenticate2F2(string username, string password, string code, string token2FA);
|
||||
Task<ApiResponseDTO<UserDTO>> Authenticate2F2ChangePassword(string username, string oldpassword,string newpassword, string code, string token2FA);
|
||||
Task<bool> DeleteUser(int id);
|
||||
|
||||
Task<RoleDTO> GetRole(int id);
|
||||
|
||||
@@ -195,6 +195,48 @@ namespace WorkFlowCheck.Web.Services
|
||||
};
|
||||
}
|
||||
}
|
||||
public async Task<ApiResponseDTO<UserDTO>> Authenticate2F2ChangePassword(string username, string oldpassword, string newpassword, string code, string token2FA)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/Authenticate2F2ChangePassword";
|
||||
|
||||
var userSimpleDTO = new UserChangePassword2FADTO()
|
||||
{
|
||||
UserName = username,
|
||||
OldPassword = oldpassword,
|
||||
NewPassword1 = newpassword,
|
||||
NewPassword2 = newpassword,
|
||||
Code = code,
|
||||
Token2FA = token2FA
|
||||
};
|
||||
|
||||
|
||||
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userSimpleDTO))
|
||||
{
|
||||
httpResponseMessage.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
var response = JsonConvert.DeserializeObject<ApiResponseDTO<UserDTO>>(jsonString);
|
||||
|
||||
return response ?? new ApiResponseDTO<UserDTO>
|
||||
{
|
||||
IsSuccess = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
return new ApiResponseDTO<UserDTO>
|
||||
{
|
||||
IsSuccess = false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> DeleteUser(int id)
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/DeleteUser/{id}";
|
||||
@@ -522,6 +564,6 @@ namespace WorkFlowCheck.Web.Services
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ function showMessageModal(options) {
|
||||
var defaults = {
|
||||
title: 'Üzenet',
|
||||
message: 'Ez egy információs üzenet.',
|
||||
okText: 'OK'
|
||||
okText: 'OK',
|
||||
redirectUrl: null
|
||||
};
|
||||
|
||||
var settings = $.extend({}, defaults, options);
|
||||
@@ -87,6 +88,12 @@ function showMessageModal(options) {
|
||||
$('#messageModalBody').html(settings.message);
|
||||
$('#messageModalOkBtn').text(settings.okText);
|
||||
|
||||
$('#messageModalOkBtn').off('click').on('click', function () {
|
||||
if (settings.redirectUrl) {
|
||||
window.location.href = settings.redirectUrl;
|
||||
}
|
||||
});
|
||||
|
||||
// Modal megnyitása
|
||||
var modal = new bootstrap.Modal(document.getElementById('messageModal'), {
|
||||
backdrop: 'static',
|
||||
|
||||
Reference in New Issue
Block a user