View | Details | Raw Unified | Return to bug 30724
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/auth-two-factor.inc (-1 / +1 lines)
Lines 26-32 Link Here
26
        </fieldset>
26
        </fieldset>
27
        <fieldset class="action">
27
        <fieldset class="action">
28
            <input id="register-2FA" class="btn btn-primary" type="submit" value="Register with two-factor app" />
28
            <input id="register-2FA" class="btn btn-primary" type="submit" value="Register with two-factor app" />
29
            <a class="cancel" href="/cgi-bin/koha/members/two_factor_auth.pl">Cancel</a>
29
            <a class="cancel" href="/cgi-bin/koha/members/two_factor_auth.pl?borrowernumber=[% patron.borrowernumber | uri %]">Cancel</a>
30
        </fieldset>
30
        </fieldset>
31
    </div>
31
    </div>
32
[% END %]
32
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc (-2 / +2 lines)
Lines 93-100 Link Here
93
                        <a class="dropdown-item disabled" aria-disabled="true" id="patronflags" href="#">Set permissions</a>
93
                        <a class="dropdown-item disabled" aria-disabled="true" id="patronflags" href="#">Set permissions</a>
94
                    </li>
94
                    </li>
95
                [% END %]
95
                [% END %]
96
                [% IF ( Koha.Preference('TwoFactorAuthentication') == 'enforced' || Koha.Preference('TwoFactorAuthentication') == 'enabled' ) && logged_in_user.borrowernumber == patron.borrowernumber %]
96
                [% IF ( Koha.Preference('TwoFactorAuthentication') == 'enforced' || Koha.Preference('TwoFactorAuthentication') == 'enabled' ) && ( logged_in_user.borrowernumber == patron.borrowernumber || logged_in_user.is_superlibrarian ) %]
97
                    <li><a class="dropdown-item" id="twofa" href="/cgi-bin/koha/members/two_factor_auth.pl">Manage two-factor authentication</a></li>
97
                    <li><a class="dropdown-item" id="twofa" href="/cgi-bin/koha/members/two_factor_auth.pl?borrowernumber=[% patron.borrowernumber | uri %]">Manage two-factor authentication</a></li>
98
                [% END %]
98
                [% END %]
99
99
100
                [% IF CAN_user_borrowers_edit_borrowers && useDischarge %]
100
                [% IF CAN_user_borrowers_edit_borrowers && useDischarge %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt (-6 / +10 lines)
Lines 46-52 Link Here
46
        [% PROCESS registration_form %]
46
        [% PROCESS registration_form %]
47
47
48
        <div id="registration-status">
48
        <div id="registration-status">
49
            <div id="registration-status-enabled" [% IF patron.auth_method != "two-factor" %]style="display: none;"[% END %]>
49
            <div id="registration-status-enabled" [% IF !patron.has_2fa_enabled %]style="display: none;"[% END %]>
50
                <div class="alert alert-info two-factor-status">Status: Enabled</div>
50
                <div class="alert alert-info two-factor-status">Status: Enabled</div>
51
51
52
                <form id="two-factor-auth" action="/cgi-bin/koha/members/two_factor_auth.pl" method="post">
52
                <form id="two-factor-auth" action="/cgi-bin/koha/members/two_factor_auth.pl" method="post">
Lines 56-68 Link Here
56
                </form>
56
                </form>
57
            </div>
57
            </div>
58
58
59
            <div id="registration-status-disabled" [% IF patron.auth_method != "password" %]style="display: none;"[% END %]>
59
            <div id="registration-status-disabled" [% IF patron.has_2fa_enabled %]style="display: none;"[% END %]>
60
                <div class="alert alert-info two-factor-status">Status: Disabled</div>
60
                <div class="alert alert-info two-factor-status">Status: Disabled</div>
61
                [% IF Koha.Preference('TwoFactorAuthentication') == 'enforced' %]
61
                [% IF another_user %]
62
                    <div>Two-factor authentication is mandatory to login. If you do not enable now it will be asked at your next login.</div>
62
                    <div>You cannot enable two-factor authentication for a user. They need to do it themselves.</div>
63
                [% END %]
63
                [% ELSE %]
64
                    [% IF Koha.Preference('TwoFactorAuthentication') == 'enforced' %]
65
                        <div>Two-factor authentication is mandatory to login. If you do not enable now it will be asked at your next login.</div>
66
                    [% END %]
64
67
65
                <input id="enable-2FA" class="btn btn-primary" type="submit" value="Enable two-factor authentication" />
68
                    <input id="enable-2FA" class="btn btn-primary" type="submit" value="Enable two-factor authentication" />
69
                [% END %]
66
            </div>
70
            </div>
67
        </div>
71
        </div>
68
    [% END %]
72
    [% END %]
(-)a/members/two_factor_auth.pl (-18 / +32 lines)
Lines 42-74 if ( $TwoFactorAuthentication ne 'enabled' && $TwoFactorAuthentication ne 'enfor Link Here
42
    exit;
42
    exit;
43
}
43
}
44
44
45
my $op        = $cgi->param('op')             // '';
46
my $patron_id = $cgi->param('borrowernumber') // '';
47
48
my $another_user = $patron_id ne $loggedinuser;
49
45
my $logged_in_user = Koha::Patrons->find($loggedinuser);
50
my $logged_in_user = Koha::Patrons->find($loggedinuser);
46
my $op             = $cgi->param('op') // '';
51
52
unless ( !$another_user || $logged_in_user->is_superlibrarian() ) {
53
    print $cgi->redirect("/cgi-bin/koha/errors/403.pl");
54
    exit;
55
}
56
57
my $patron =
58
    $another_user
59
    ? Koha::Patrons->find($patron_id)
60
    : $logged_in_user;
61
62
if ( !$patron ) {
63
    print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
64
    exit;
65
}
47
66
48
if ( !C4::Context->config('encryption_key') ) {
67
if ( !C4::Context->config('encryption_key') ) {
49
    $template->param( missing_key => 1 );
68
    $template->param( missing_key => 1 );
50
} else {
69
} else {
51
70
52
    my $csrf_pars = {
53
        session_id => scalar $cgi->cookie('CGISESSID'),
54
        token      => scalar $cgi->param('csrf_token'),
55
    };
56
57
    if ( $op eq 'cud-disable-2FA' ) {
71
    if ( $op eq 'cud-disable-2FA' ) {
58
        my $auth = Koha::Auth::TwoFactorAuth->new( { patron => $logged_in_user } );
72
59
        $logged_in_user->secret(undef);
73
        $patron->reset_2fa();
60
        $logged_in_user->auth_method('password')->store;
74
61
        if ( $logged_in_user->notice_email_address ) {
75
        if ( $patron->notice_email_address ) {
62
            $logged_in_user->queue_notice(
76
            $patron->queue_notice(
63
                {
77
                {
64
                    letter_params => {
78
                    letter_params => {
65
                        module      => 'members',
79
                        module      => 'members',
66
                        letter_code => '2FA_DISABLE',
80
                        letter_code => '2FA_DISABLE',
67
                        branchcode  => $logged_in_user->branchcode,
81
                        branchcode  => $patron->branchcode,
68
                        lang        => $logged_in_user->lang,
82
                        lang        => $patron->lang,
69
                        tables      => {
83
                        tables      => {
70
                            branches  => $logged_in_user->branchcode,
84
                            branches  => $patron->branchcode,
71
                            borrowers => $logged_in_user->id
85
                            borrowers => $patron->id
72
                        },
86
                        },
73
                    },
87
                    },
74
                    message_transports => ['email'],
88
                    message_transports => ['email'],
Lines 79-86 if ( !C4::Context->config('encryption_key') ) { Link Here
79
}
93
}
80
94
81
$template->param(
95
$template->param(
82
    patron => $logged_in_user,
96
    another_user => $another_user,
83
    op     => $op,
97
    op           => $op,
98
    patron       => $patron,
84
);
99
);
85
100
86
output_html_with_http_headers $cgi, $cookie, $template->output;
101
output_html_with_http_headers $cgi, $cookie, $template->output;
87
- 

Return to bug 30724