Light12306/Web12306/js/account/sessionMgr.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-05-16 20:10:45 +08:00
define(function (require, exports, module) {
var session = null;
var ev = require("../platform/EventObject.js");
2014-05-29 19:41:38 +08:00
var widget = require("../ui/widget.js");
var ajax = require("../platform/webRequest.js");
2014-05-16 20:10:45 +08:00
//var LoginUser = require("./LoginUser.js");
var SessionMgr = function () {
var that = this;
ev.apply(this, arguments);
2014-05-29 19:41:38 +08:00
that.showLogin = function () {
if (that.current != null) return;
widget.showFloatDialog($("#user-login-dialog"));
};
that.loadLoginVcImage = function (target) {
};
that.loginAsync = function (callback) {
};
that.checkLoginState = function (callback) {
ajax.sendGet("modifyUser/initQueryUserInfo", "", null, "text", function () {
if (this.text.indexOf("登录名:") !== -1) {
callback({ logined: false });
} else {
var m = /姓名:.*[\r\n]+<div[^>]+>([^<]+)<\/div>/i.exec(this.text) && RegExp.$1;
var status = /核验状态:[\w\W]+?>([^<>]+?)<\/div>/.exec(this.text) && RegExp.$1;
if (!m || !status)
callback({ logined: false });
else {
callback({ logined: true, realName: m, status: status, isChecked: status === '已通过' });
}
}
}, function () {
});
};
2014-05-16 20:10:45 +08:00
Object.defineProperty(this, "current", {
get: function () {
return session;
},
2014-05-29 19:41:38 +08:00
set: function (v) {
2014-05-16 20:10:45 +08:00
if (session === v) return;
session = v;
that.fireEvent("sessionChanged");
}
});
return this;
};
SessionMgr.prototype = Object.create(ev);
SessionMgr.constructor = SessionMgr;
module.exports = new SessionMgr();
});