Skip to content

Commit

Permalink
Merge pull request #105 from Coderberg/feature/2fa
Browse files Browse the repository at this point in the history
Feature/2fa
  • Loading branch information
Coderberg authored May 5, 2023
2 parents d2d9e3b + 33ca869 commit 32c968c
Show file tree
Hide file tree
Showing 73 changed files with 1,790 additions and 178 deletions.
10 changes: 6 additions & 4 deletions assets/js/bottom-bar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
(function ($) {

'use strict';

const $phone = $('#phone');
const $email = $('#email');

$('body').append(`<div class="bottom-bar">
<a class="btn-right" href="${$phone.attr('href')}">${$phone.attr('title')}</a>
<a class="btn-left" href="${$email.attr('href')}">${$email.attr('title')}</a>
<a class="btn-right" href="${$phone.attr(
'href'
)}">${$phone.attr('title')}</a>
<a class="btn-left" href="${$email.attr(
'href'
)}">${$email.attr('title')}</a>
</div>`);

})(window.jQuery);
4 changes: 3 additions & 1 deletion assets/js/user/_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
$('.list-group-item-action:eq(2)').addClass('active');
} else if (currentUrl.indexOf('unpublished') !== -1) {
$('.list-group-item-action:eq(1)').addClass('active');
} else if (currentUrl.indexOf('security') !== -1) {
$('.list-group-item-action:eq(3)').addClass('active');
} else {
$('.list-group-item-action:eq(0)').addClass('active');
}
})($);
})(window.jQuery);
89 changes: 89 additions & 0 deletions assets/js/user/two_factor/google_authenticator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
(function ($) {
'use strict';

const $form = $('#generate_google_auth_secret');
const token = $('[name="auth_token"]').val();
const $secret = $('[name="generatedSecret"]');
const $authentication_code = $('[name="authentication_code"]');

// Open modal window
$('#setUpAuthenticatorButton').click(function () {
if ($form.data('generate-new-secret') === true) {
$.ajax({
method: 'GET',
url: '/en/user/google_authenticator_code',
data: { csrf_token: token }
}).done(function (response) {
const { secret, qr_code } = response;
const image = new Image();
image.src = qr_code;

$secret.val(secret);
$('#generatedQrCode').html(image);
$('#generatedSecret').html(secret);
});
}
});

// Enable 2fa
$('#enable2fa').click(function () {
let authentication_code = $authentication_code.val().trim();

if (!authentication_code) {
$authentication_code.addClass('is-invalid').focus();

return;
}

$.ajax({
method: 'PUT',
url: $form.attr('action'),
data: {
csrf_token: token,
secret: $secret.val(),
authentication_code: authentication_code
}
})
.done(function () {
location.reload();
})
.fail(function (data) {
showError(data.responseJSON.message);
});
});

// Disable 2fa
$('#disable2fa').click(function () {
$.ajax({
method: 'DELETE',
url: $form.attr('action'),
data: { csrf_token: token }
})
.done(function () {
location.reload();
})
.fail(function () {
location.reload();
});
});

$authentication_code.keyup(function () {
$(this).removeClass('is-invalid');
});

// Reset form state
$('#setUpAuthenticator').on('hidden.bs.modal', function () {
resetFormState();
});

function resetFormState() {
$authentication_code.val('').removeClass('is-invalid');
$('#twoFactorAuthErrorMessage').text('').addClass('d-none');
}

function showError(message) {
$('#twoFactorAuthErrorMessage')
.text(message)
.removeClass('d-none');
}
})(window.jQuery);
6 changes: 6 additions & 0 deletions assets/styles/user/security.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.security-buttons a i {
background-color: #fff;
padding: 20px;
border-radius: 50%;
color: #BDC3C7;
}
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
"doctrine/doctrine-bundle": "^2.8",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.13",
"endroid/qr-code": "^4.8",
"gregwar/image": "master",
"knplabs/knp-paginator-bundle": "^5.6",
"phpdocumentor/reflection-docblock": "^5.2",
"scheb/2fa-bundle": "^6.8",
"scheb/2fa-google-authenticator": "^6.8",
"symfony/asset": "^6.2",
"symfony/cache": "^6.2",
"symfony/console": "^6.2",
Expand Down Expand Up @@ -59,6 +62,7 @@
"dbrekelmans/bdi": "^1.0",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"friendsofphp/php-cs-fixer": "^3.2",
"phpgangsta/googleauthenticator": "dev-master",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.5",
"symfony/browser-kit": "^6.2",
Expand Down
Loading

0 comments on commit 32c968c

Please sign in to comment.