2
* Laudio - A webbased musicplayer
4
* Copyright (C) 2010 Bernhard Posselt, bernhard.posselt@gmx.at
6
* Laudio is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
11
* Laudio is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
* Enable jquery for csrf protection
26
$(document).ajaxSend(function(event, xhr, settings) {
27
function getCookie(name) {
28
var cookieValue = null;
29
if (document.cookie && document.cookie != '') {
30
var cookies = document.cookie.split(';');
31
for (var i = 0; i < cookies.length; i++) {
32
var cookie = jQuery.trim(cookies[i]);
33
// Does this cookie string begin with the name we want?
34
if (cookie.substring(0, name.length + 1) == (name + '=')) {
35
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
42
function sameOrigin(url) {
43
// url could be relative or scheme relative or absolute
44
var host = document.location.host; // host + port
45
var protocol = document.location.protocol;
46
var sr_origin = '//' + host;
47
var origin = protocol + sr_origin;
48
// Allow absolute or scheme relative URLs to same origin
49
return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
50
(url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
51
// or any other URL that isn't scheme relative or absolute i.e relative.
52
!(/^(\/\/|http:|https:).*/.test(url));
54
function safeMethod(method) {
55
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
58
if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
59
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
63
// js actions which are available in the whole applicatin
64
$(document).ready(function () {
67
$('#id_password1').keyup(function(){
68
validate_password($(this), $('#id_password2'))
70
$('#id_password2').keyup(function(){
71
validate_password($(this), $('#id_password1'))
78
* Function which adds or removes the correct classes on 2 fields
80
* @param $input1: The first jquery input element
81
* @param $input2: The second jquery input element
83
function validate_password($input1, $input2){
84
if($input1.val() === $input2.val()){
85
$input1.removeClass('incorrect');
86
$input2.removeClass('incorrect');
87
$input1.addClass('correct');
88
$input2.addClass('correct');
90
$input1.removeClass('correct');
91
$input2.removeClass('correct');
92
$input1.addClass('incorrect');
93
$input2.addClass('incorrect');