Add anchor tag in user_profile's url. Reload authentication tab when update

This commit is contained in:
Khanh Ngo 2016-06-18 11:37:23 +07:00
parent e8f2f3d0c7
commit 92dd1586bf

View File

@ -23,19 +23,19 @@
</div> </div>
<div class="box-body"> <div class="box-body">
<!-- Custom Tabs --> <!-- Custom Tabs -->
<div class="nav-tabs-custom"> <div class="nav-tabs-custom" id="tabs">
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li class="active"><a href="#personal_tab" data-toggle="tab">Personal <li class="active"><a href="#tabs-personal" data-toggle="tab">Personal
Info</a></li> Info</a></li>
<li><a href="#avatar_tab" data-toggle="tab">Change <li><a href="#tabs-avatar" data-toggle="tab">Change
Avatar</a></li> Avatar</a></li>
<li><a href="#password_tab" data-toggle="tab">Change <li><a href="#tabs-password" data-toggle="tab">Change
Password</a></li> Password</a></li>
<li><a href="#authentication_tab" data-toggle="tab">Authentication <li><a href="#tabs-authentication" data-toggle="tab">Authentication
</a></li> </a></li>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane active" id="personal_tab"> <div class="tab-pane active" id="tabs-personal">
<form role="form" method="post" action="{{ user_profile }}"> <form role="form" method="post" action="{{ user_profile }}">
<div class="form-group"> <div class="form-group">
<label for="firstname">First Name</label> <input type="text" <label for="firstname">First Name</label> <input type="text"
@ -57,7 +57,7 @@
</div> </div>
</form> </form>
</div> </div>
<div class="tab-pane" id="avatar_tab"> <div class="tab-pane" id="tabs-avatar">
<form action="{{ user_profile }}" method="post" <form action="{{ user_profile }}" method="post"
enctype="multipart/form-data"> enctype="multipart/form-data">
<div class="form-group"> <div class="form-group">
@ -87,7 +87,7 @@
</div> </div>
</form> </form>
</div> </div>
<div class="tab-pane" id="password_tab"> <div class="tab-pane" id="tabs-password">
{% if not current_user.password %} Your account password is {% if not current_user.password %} Your account password is
managed via LDAP which isn't supported to change here. {% else managed via LDAP which isn't supported to change here. {% else
%} %}
@ -109,16 +109,18 @@
</form> </form>
{% endif %} {% endif %}
</div> </div>
<div class="tab-pane" id="authentication_tab"> <div class="tab-pane" id="tabs-authentication">
<form action="{{ user_profile }}" method="post"> <form action="{{ user_profile }}" method="post">
<div class="form-group"> <div class="form-group">
<input type="checkbox" id="{{ current_user.username }}" class="otp_toggle" {% if current_user.otp_secret %}checked{% endif %}> <input type="checkbox" id="otp_toggle" class="otp_toggle" {% if current_user.otp_secret %}checked{% endif %}>
<label for="otp_toggle">Enable Two Factor Authentication</label> <label for="otp_toggle">Enable Two Factor Authentication</label>
{% if current_user.otp_secret %} {% if current_user.otp_secret %}
<div id="token_information">
<p><img id="qrcode" src="{{ url_for('qrcode') }}"></p> <p><img id="qrcode" src="{{ url_for('qrcode') }}"></p>
Please start FreeOTP (<a target="_blank" href="https://play.google.com/store/apps/details?id=org.fedorahosted.freeotp&hl=en">Android</a> - <a target="_blank" href="https://itunes.apple.com/en/app/freeotp-authenticator/id872559395?mt=8">iOS</a>) on your smartphone and scan the above QR Code with it. Please start FreeOTP (<a target="_blank" href="https://play.google.com/store/apps/details?id=org.fedorahosted.freeotp&hl=en">Android</a> - <a target="_blank" href="https://itunes.apple.com/en/app/freeotp-authenticator/id872559395?mt=8">iOS</a>) on your smartphone and scan the above QR Code with it.
<br/> <br/>
<font color="red"><strong><i>Make sure only you can see this QR Code and nobodoy can capture it.</i></strong></font> <font color="red"><strong><i>Make sure only you can see this QR Code and nobodoy can capture it.</i></strong></font>
</div>
{% endif %} {% endif %}
</div> </div>
</form> </form>
@ -134,6 +136,19 @@
{% block extrascripts %} {% block extrascripts %}
<!-- TODO: add password and password confirmation comparisson check --> <!-- TODO: add password and password confirmation comparisson check -->
<script> <script>
$(function() {
$('#tabs').tabs({
// add url anchor tags
activate: function(event, ui) {
window.location.hash = ui.newPanel.attr('id');
}
});
// re-set active tab (ui)
var activeTabIdx = $('#tabs').tabs('option','active');
$('#tabs li:eq('+activeTabIdx+')').tab('show')
});
// initialize pretty checkboxes // initialize pretty checkboxes
$('.otp_toggle').iCheck({ $('.otp_toggle').iCheck({
checkboxClass : 'icheckbox_square-blue', checkboxClass : 'icheckbox_square-blue',
@ -147,11 +162,11 @@
postdata = { postdata = {
'action' : 'enable_otp', 'action' : 'enable_otp',
'data' : { 'data' : {
'username' : username,
'enable_otp' : enable_otp 'enable_otp' : enable_otp
} }
}; };
applyChanges(postdata, '/user/profile'); applyChanges(postdata, '/user/profile');
location.reload();
}); });
</script> </script>
{% endblock %} {% endblock %}