summaryrefslogtreecommitdiff
path: root/www/js/auth.js
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-03-19 22:11:15 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-03-19 22:16:10 (GMT)
commit259e1c7a81ea9a096c227a6bc44114a7a9cf3a50 (patch)
tree051c708e449b5e5afb6ba25bce169b280045f254 /www/js/auth.js
parentd7795f99ed3fb52564fa6d2340d928ae9b191e5b (diff)
implemented a more secure directory structure
Diffstat (limited to 'www/js/auth.js')
-rw-r--r--www/js/auth.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/www/js/auth.js b/www/js/auth.js
new file mode 100644
index 0000000..29dde31
--- /dev/null
+++ b/www/js/auth.js
@@ -0,0 +1,78 @@
+var auth_username;
+var auth_token;
+
+function auth_loginSuccess(data) {
+ if (data.status == 'OK') {
+ auth_username = data.username;
+ sessionStorage.setItem("auth_username", auth_username);
+
+ auth_token = data.token;
+ sessionStorage.setItem("auth_token", auth_token);
+
+ apps_select('shows');
+
+ $('#username-field').html(auth_username);
+ $('#loginbox').slideUp();
+ $('#mainwindow').fadeIn();
+ } else {
+ alertbox.error('loginbox', "Fehler beim Login", data.errorstring);
+ auth_cleanup();
+ }
+}
+
+function auth_loginError(req, status, error) {
+ message = req.status + ': ' + error;
+ if(req.status == 401) {
+ message = "Benutzer und/oder Passwort sind falsch!";
+ }
+ alertbox.error('loginbox', "Fehler beim Login", message);
+ $("#password").val('');
+}
+
+function auth_login()
+{
+ $.ajax("/authtoken.json",
+ { cache: false,
+ username: $("#username").val(),
+ password: $("#password").val(),
+ dataType: "json",
+ error: auth_loginError,
+ success: auth_loginSuccess
+ });
+}
+
+function auth_logout()
+{
+ auth_cleanup();
+ apps_cleanup();
+
+ $(".alert").alert('close');
+ $("#username").val('');
+ $("#password").val('');
+ $("#mainwindow").fadeOut();
+ $('#username-field').html('');
+ $('#loginbox').slideDown();
+}
+
+function auth_init() {
+ auth_username = sessionStorage.getItem("auth_username");
+ auth_token = sessionStorage.getItem("auth_token");
+
+ if(auth_token && auth_username) {
+ $("#loginbox").hide();
+ $('#username-field').html(auth_username);
+ } else {
+ $("#mainwindow").hide();
+ }
+ $("#loginform").submit(function(event) { auth_login(); event.preventDefault(); });
+}
+
+function auth_cleanup() {
+ sessionStorage.removeItem("auth_username");
+ delete auth_username;
+ $("#username").val('').focus();
+
+ sessionStorage.removeItem("auth_token");
+ delete auth_token;
+ $("#password").val('');
+}