/* * rhwebimport * * Copyright (C) 2014-2015 Christian Pointner * Copyright (C) 2015 Peter Grassberger * * This file is part of rhwebimport. * * rhwebimport is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * rhwebimport is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with rhwebimport. If not, see . */ var auth_username; var auth_fullname; var auth_token; function auth_loginSuccess(data) { if (data.status == 'OK') { auth_username = data.username; auth_fullname = data.fullname; auth_token = data.token; sessionStorage.setItem("auth_username", auth_username); sessionStorage.setItem("auth_fullname", auth_fullname); sessionStorage.setItem("auth_token", auth_token); apps_select(apps_current); $('#username-field').html(auth_fullname + ' (' + 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("/rh-bin/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_fullname = sessionStorage.getItem("auth_fullname"); auth_token = sessionStorage.getItem("auth_token"); if(auth_token && auth_username && auth_fullname) { $("#loginbox").hide(); $('#username-field').html(auth_fullname + ' (' + 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_fullname"); delete auth_fullname; sessionStorage.removeItem("auth_token"); delete auth_token; $("#password").val(''); }