Statistics
| Branch: | Tag: | Revision:

root / templates / mail_change.html @ 064ecc91

History | View | Annotate | Download (2.7 kB)

1
<div id="usermailchange_placeholder">
2
<script>
3
        $(document).ajaxSend(function(event, xhr, settings) {
4
    function getCookie(name) {
5
        var cookieValue = null;
6
        if (document.cookie && document.cookie != '') {
7
            var cookies = document.cookie.split(';');
8
            for (var i = 0; i < cookies.length; i++) {
9
                var cookie = jQuery.trim(cookies[i]);
10
                // Does this cookie string begin with the name we want?
11
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
12
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
13
                    break;
14
                }
15
            }
16
        }
17
        return cookieValue;
18
    }
19
    function sameOrigin(url) {
20
        // url could be relative or scheme relative or absolute
21
        var host = document.location.host; // host + port
22
        var protocol = document.location.protocol;
23
        var sr_origin = '//' + host;
24
        var origin = protocol + sr_origin;
25
        // Allow absolute or scheme relative URLs to same origin
26
        return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
27
            (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
28
            // or any other URL that isn't scheme relative or absolute i.e relative.
29
            !(/^(\/\/|http:|https:).*/.test(url));
30
    }
31
    function safeMethod(method) {
32
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
33
    }
34

35
    if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
36
        xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
37
    }
38
});
39

40
        $(function() {
41
        $('#change_email_btn').button();
42
        $('#change_email_btn').click(function() {
43
                        str = $('#change_email_form').serialize();
44
            $.ajax({
45
                type: "POST",
46
                url: "{% url mail-change %}",
47
                data: str,
48
                success: function(response){
49
//                                        console.log(response);
50
//                                        var $response=$(response);
51
//                                        var resdata =  $response.filter("#sshkeys_placeholder").html();
52
                        $("#usermailchange_placeholder").html(response);
53
                        }
54
        });
55
    return false;
56
        });
57
        });
58
        </script>
59
        {% load i18n %}
60
<div>{{user}} {% trans "enter your new mail address twice so we can verify you typed it in correctly." %}</div> 
61
<div>{% trans "Your e-mail" %} {% if changed %} {% trans "has successfully changed to" %} {% endif %}: <strong>{% ifequal mail|length 0 %} {% trans "you have not registered an address yet" %} {% else %}{{mail}}{% endifequal %}</strong></div>
62
<form method="POST" id="change_email_form">
63
{% csrf_token %}
64
        <table>
65
            {{ form.as_table }}
66
        </table>
67
<button id="change_email_btn">{% trans "Change email" %}</button>
68
</form>
69

    
70
</div>