-
Notifications
You must be signed in to change notification settings - Fork 3
/
loginmenuitem.html
73 lines (68 loc) · 3.38 KB
/
loginmenuitem.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{% load item_tags %}
{% if cur_agent.is_anonymous %}
<li>
<script type="text/javascript" src="{% media_url "javascripts/sha1.js" %}"></script>
<script type="text/javascript" src="{% media_url "javascripts/mysql_pre41_password.js" %}"></script>
<script type="text/javascript">
function get_encrypted_password(raw_password, algo, salt, nonce) {
var original_hashed_password;
if (algo == 'sha1') {
original_hashed_password = SHA1(salt + raw_password);
} else if (algo == 'mysql_pre41_password') {
original_hashed_password = mysql_pre41_password(raw_password);
} else {
return 'unknown algo: ' + algo;
}
return SHA1(nonce + original_hashed_password);
}
function encrypt_password() {
var raw_password = document.forms['password_form']['password'].value;
var url = '{% url item_type_url viewer="demeaccount",action="getencryptionmethod" %}';
jQuery.post(url, {username:document.forms['password_form']['username'].value}, function(json) {
var algo = json.algo;
var salt = json.salt;
var nonce = json.nonce;
var encrypted_password = get_encrypted_password(raw_password, algo, salt, nonce);
document.forms['real_password_form']['hashed_password'].value = encrypted_password;
document.forms['real_password_form']['username'].value = document.forms['password_form']['username'].value;
document.forms['real_password_form'].submit();
}, "json");
}
</script>
<div style="display: none;" id="login_dialog_password" title="Login">
<form name="password_form" onsubmit="$('#login_dialog_password').dialog('hide'); encrypt_password(); return false;">
<div>Username:</div>
<div><input type="text" name="username" /></div>
<div>Password:</div>
<div><input type="password" name="password" /></div>
</form>
<form name="real_password_form" action="{% url item_type_url viewer="demeaccount",action="login" %}?redirect={{ redirect|urlencode }}" method="post">
<input type="hidden" name="username" />
<input type="hidden" name="hashed_password" onchange="document.forms['password_form']['hashed_password'].value = '';" />
</form>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#login_dialog_password').dialog({
autoOpen: false,
buttons: {"Login": function(){$(this).dialog('close'); document.forms['password_form'].onsubmit()}, "Cancel": function(){$(this).dialog("close")} },
modal: true,
bgiframe: true,
});
});
</script>
</li>
<li class="loginmenuitem"><a href="#" onclick="$('#login_dialog_password').dialog('open'); return false;">Deme account</a></li>
{% else %}
{% if one_or_more %}
{% if two_or_more %}
{% for account in auth_methods %}
<li class="loginmenuitem"><a href="{% url item_url viewer="demeaccount",action="edit",noun=account.pk %}"><i class="glyphicon glyphicon-user"></i> Change password for {% viewable_name account %}</a></li>
{% endfor %}
{% else %}
{% for account in auth_methods %}
<li class="loginmenuitem"><a href="{% url item_url viewer="demeaccount",action="edit",noun=account.pk %}"><i class="glyphicon glyphicon-user"></i> Change password</a></li>
{% endfor %}
{% endif %}
{% endif %}
{% endif %}