Na most van kész a 2 faktoros authentikáció ! :)
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
@model WorkFlowCheck.Web.Pages.Account.LoginModel
|
||||
@using WorkFlowCheck.Common.Helper
|
||||
@using WorkFlowCheck.Common.DTO
|
||||
@using Microsoft.AspNetCore.Antiforgery
|
||||
@inject IAntiforgery Antiforgery
|
||||
@{
|
||||
Layout = null;
|
||||
ViewData["Title"] = "Bejelentkezés";
|
||||
@@ -27,20 +29,30 @@
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
|
||||
<input type="hidden" asp-for="User2FADTO.Token2FA" />
|
||||
<div class="mb-3">
|
||||
<label asp-for="UserSimpleDTO.UserName" class="form-label">Felhasználónév</label>
|
||||
<input asp-for="UserSimpleDTO.UserName" class="form-control" />
|
||||
<span asp-validation-for="UserSimpleDTO.UserName" class="text-danger small"></span>
|
||||
<label asp-for="User2FADTO.UserName" class="form-label">Felhasználónév</label>
|
||||
<input asp-for="User2FADTO.UserName" class="form-control" />
|
||||
<span asp-validation-for="User2FADTO.UserName" class="text-danger small"></span>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="UserSimpleDTO.Password" class="form-label">Jelszó</label>
|
||||
<input asp-for="UserSimpleDTO.Password" type="password" class="form-control" />
|
||||
<span asp-validation-for="UserSimpleDTO.Password" class="text-danger small"></span>
|
||||
<label asp-for="User2FADTO.Password" class="form-label">Jelszó</label>
|
||||
<input asp-for="User2FADTO.Password" type="password" class="form-control" />
|
||||
<span asp-validation-for="User2FADTO.Password" class="text-danger small"></span>
|
||||
</div>
|
||||
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">Bejelentkezés</button>
|
||||
<div id="VerificationCode" class="mb-3">
|
||||
<label asp-for="User2FADTO.Code" class="form-label">Megerősítő kód</label>
|
||||
<input asp-for="User2FADTO.Code" class="form-control" />
|
||||
<span asp-validation-for="User2FADTO.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>
|
||||
@@ -50,7 +62,91 @@
|
||||
<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();
|
||||
|
||||
$('#Login2F1Btn').on('click', function () {
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||
const userName = $('#User2FADTO_UserName').val();
|
||||
const password = $('#User2FADTO_Password').val();
|
||||
|
||||
$.ajax({
|
||||
url: '/Account/Login?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();
|
||||
$('#User2FADTO_Token2FA').val(result.data)
|
||||
} else {
|
||||
alert('Hibás felhasználónév vagy jelszó!');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
alert('Hiba történt a kérés során.');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$('#Login2F2Btn').on('click', function () {
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||
|
||||
const userName = $('#User2FADTO_UserName').val();
|
||||
const password = $('#User2FADTO_Password').val();
|
||||
const code = $('#User2FADTO_Code').val();
|
||||
const token2FA = $('#User2FADTO_Token2FA').val();
|
||||
|
||||
$.ajax({
|
||||
url: '/Account/Login?handler=Login2F2',
|
||||
type: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
UserName: userName,
|
||||
Password: password,
|
||||
Code: code,
|
||||
Token2FA: token2FA
|
||||
}),
|
||||
success: function (result) {
|
||||
if (result.success) {
|
||||
window.location.href = `/Index`;
|
||||
} else {
|
||||
alert('Hibás felhasználónév vagy jelszó!');
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
console.log(xhr.status);
|
||||
console.log(xhr.responseText);
|
||||
alert('Hiba történt a kérés során.');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<partial name="_ValidationScriptsPartial" />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user