//#import Util.js
//#import pigeon.js
//#import session.js

var LoginService = (function () {
    var frontUserIdKey = "loginUserId";
    var backendUserIdKey = "_backendUserId";
    var loginTimeKey = "_frontLoginTime";
    var backendLoginTimeKey = "_backendLoginTime";

    var f = {
        getFrontendUserId: function () {
            var userId = SessionService.getSessionValue(frontUserIdKey, request);
            if (!userId) {
                return "";
            }
            return userId;
        },
        getBackendUserId: function () {
            var userId = SessionService.getSessionValue(backendUserIdKey, request);
            if (!userId) {
                return "";
            }
            return userId;
        },
        loginFrontend: function (userId) {
            var curTime = new Date().getTime();
            SessionService.addSessionValue(frontUserIdKey, userId, request, response);
            SessionService.addSessionValue(loginTimeKey, "" + curTime, request, response);
        },
        loginBackend: function (userId) {
            var curTime = new Date().getTime();
            SessionService.addSessionValue(backendUserIdKey, userId, request, response);
            SessionService.addSessionValue(backendLoginTimeKey, "" + curTime, request, response);
        },
        logoutFrontend: function () {
            SessionService.removeSessionValue(frontUserIdKey);
            SessionService.removeSessionValue(loginTimeKey);
        },
        logoutBackend: function () {
            SessionService.removeSessionValue(backendUserIdKey);
            SessionService.removeSessionValue(loginTimeKey);
        }
    };
    return f;
})();