|
| 1 | +// Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +// of this software and associated documentation files (the "Software"), to deal |
| 5 | +// in the Software without restriction, including without limitation the rights |
| 6 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +// copies of the Software, and to permit persons to whom the Software is |
| 8 | +// furnished to do so, subject to the following conditions: |
| 9 | +// |
| 10 | +// The above copyright notice and this permission notice shall be included in all |
| 11 | +// copies or substantial portions of the Software. |
| 12 | +// |
| 13 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | +// SOFTWARE. |
| 20 | +$(document).ready(function () { |
| 21 | + $('#close_reload').click(function () { |
| 22 | + location.reload(); |
| 23 | + }); |
| 24 | + $('#do_2fa').submit(function (event) { |
| 25 | + event.preventDefault(); |
| 26 | + |
| 27 | + $.ajax({ |
| 28 | + type: 'PUT', |
| 29 | + url: Router.route('account.security.totp'), |
| 30 | + headers: { |
| 31 | + 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'), |
| 32 | + } |
| 33 | + }).done(function (data) { |
| 34 | + var image = new Image(); |
| 35 | + image.src = data.qrImage; |
| 36 | + $(image).load(function () { |
| 37 | + $('#hide_img_load').slideUp(function () { |
| 38 | + $('#qr_image_insert').attr('src', image.src).slideDown(); |
| 39 | + }); |
| 40 | + }); |
| 41 | + $('#2fa_secret_insert').html(data.secret); |
| 42 | + $('#open2fa').modal('show'); |
| 43 | + }).fail(function (jqXHR) { |
| 44 | + alert('An error occured while attempting to load the 2FA setup modal. Please try again.'); |
| 45 | + console.error(jqXHR); |
| 46 | + }); |
| 47 | + |
| 48 | + }); |
| 49 | + $('#2fa_token_verify').submit(function (event) { |
| 50 | + event.preventDefault(); |
| 51 | + $('#submit_action').html('<i class="fa fa-spinner fa-spin"></i> Submit').addClass('disabled'); |
| 52 | + |
| 53 | + $.ajax({ |
| 54 | + type: 'POST', |
| 55 | + url: Router.route('account.security.totp'), |
| 56 | + headers: { |
| 57 | + 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'), |
| 58 | + }, |
| 59 | + data: { |
| 60 | + token: $('#2fa_token').val() |
| 61 | + } |
| 62 | + }).done(function (data) { |
| 63 | + $('#notice_box_2fa').hide(); |
| 64 | + if (data === 'true') { |
| 65 | + $('#notice_box_2fa').html('<div class="alert alert-success">2-Factor Authentication has been enabled on your account. Press \'Close\' below to reload the page.</div>').slideDown(); |
| 66 | + } else { |
| 67 | + $('#notice_box_2fa').html('<div class="alert alert-danger">The token provided was invalid.</div>').slideDown(); |
| 68 | + } |
| 69 | + }).fail(function (jqXHR) { |
| 70 | + $('#notice_box_2fa').html('<div class="alert alert-danger">There was an error while attempting to enable 2-Factor Authentication on this account.</div>').slideDown(); |
| 71 | + console.error(jqXHR); |
| 72 | + }).always(function () { |
| 73 | + $('#submit_action').html('Submit').removeClass('disabled'); |
| 74 | + }); |
| 75 | + }); |
| 76 | +}); |
0 commit comments