1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-10-21 10:51:17 +00:00

[share link audit] fix & improvement

This commit is contained in:
llj
2016-04-25 21:00:25 +08:00
parent ae00156cdb
commit b38d4b671d
3 changed files with 42 additions and 24 deletions

View File

@@ -3525,3 +3525,10 @@ img.thumbnail {
.device-libs-dropdown-menu {
min-width:200px;
}
/* link audit */
#link-audit-form .email-input {
margin-bottom:5px;
}
#link-audit-form .get-code-btn {
margin-bottom:20px;
}

View File

@@ -3,20 +3,20 @@
{% block main_panel %}
<div class="new-narrow-panel" role="main">
<h2 class="hd">{% trans "Email verification" %}</h2>
<p class="notice">{% trans "Please provide your email address to continue." %}</p>
<form action="#" method="post" id="link-audit-form" class="con link-visit-verify">{% csrf_token %}
<h2 class="hd">{% trans "Email Verification" %}</h2>
<form action="" method="post" id="link-audit-form" class="con">{% csrf_token %}
<p class="tip">{% trans "Please provide your email address to continue." %}</p>
<label for="email">{% trans "Email" %}</label>
<input id="email" type="text" class="input" name="email" value="{{email}}" />
<button id="code-btn">{% trans "Get code" %}</button><br/>
<p class="field-feedback"></p>
<input id="email" type="text" class="input email-input" name="email" value="{{email}}" />
<button type="button" id="get-code" class="get-code-btn">{% trans "Get code" %}</button><br />
<lable for="code">{% trans "Verification code" %}</lable>
<input id="code" type="text" class="input" name="code" value="{{code}}" /><br/>
<label for="code">{% trans "Verification code" %}</label><br />
<input id="code" type="text" class="input" name="code" value="{{code}}" />
{% if err_msg %}
<p class="error">{{ err_msg }}</p>
{% else %}
<p class="error hide"></p>
{% endif %}
<input type="submit" value="{% trans "Submit" %}" />
@@ -25,14 +25,14 @@
{% endblock %}
{% block extra_script %}
<script type="text/javascript">
$('#code-btn').click(function() {
var email = $('input[name="email"]').val();
$('#get-code').click(function() {
var email = $.trim($('input[name="email"]').val());
if (!email) {
return false;
}
var $this = $(this);
var originalText = this.innerHTML; // Remember the original text content
var originalText = $this.text(); // Remember the original text content
var seconds = 60;
$this.prop('disabled', true).addClass('btn-disabled');
@@ -42,33 +42,44 @@ $('#code-btn').click(function() {
var interval = setInterval(function() {
// decrement the seconds and update the text
seconds = seconds - 1;
$this.text( originalText + ' (' + seconds + 's)');
if (seconds === 0) { // once seconds is 0...
$this.text(originalText + ' (' + seconds + 's)');
if (seconds === 0) { // once seconds is 0...
$this.prop('disabled', false).removeClass('btn-disabled')
.text(originalText); //reset to original text
clearInterval(interval); // clear interval
.text(originalText); // reset to original text
clearInterval(interval); // clear interval
}
}, 1000);
$.ajax({
url: "{% url "ajax_get_link_audit_code" %}",
type: 'POST',
cache: 'false',
cache: false,
beforeSend: prepareCSRFToken,
data: {
token: "{{token}}",
email: email
},
success: function() {
$(".field-feedback").html('{% trans "Successfully sent verification code to this email." %}');
feedback('{% trans "A verification code has been sent to the email." %}', 'success');
},
error: function(jqXHR, textStatus, errorThrown) {
$(".field-feedback").html($.parseJSON(jqXHR.responseText).error);
error: function(xhr) {
var err_msg = '';
if (xhr.responseText) {
err_msg = $.parseJSON(xhr.responseText).error;
} else {
err_msg = "{% trans "Failed. Please check the network." %}";
}
$('.error', $this.closest('form')).html(err_msg).removeClass('hide');
}
});
return false;
});
$('#link-audit-form').submit(function() {
var email = $.trim($('[name="email"]').val());
var code = $.trim($('[name="code"]').val());
if (!email || !code) {
return false;
}
});
</script>
{% endblock %}

View File

@@ -1222,7 +1222,7 @@ def ajax_get_link_audit_code(request):
cache.set(cache_key, code, timeout)
# send code to user via email
subject = _("Audit code for link: %s") % fs.get_full_url()
subject = _("Verification code for visiting share links")
c = {
'code': code,
}
@@ -1237,5 +1237,5 @@ def ajax_get_link_audit_code(request):
logger.error('Failed to send audit code via email to %s')
logger.error(e)
return HttpResponse(json.dumps({
"error": _("Failed to send audit code, please try again later.")
"error": _("Failed to send a verification code, please try again later.")
}), status=500, content_type=content_type)