﻿/// Require jQuery.js、Library.js

/// 名称: 用户账号类
function User()
{
	var prototype = this.constructor.prototype;
	if (!prototype.hasOwnProperty("_init_")) {
	    prototype._init_ = true;

	    // 用户登录,依据身份证号
	    prototype.login = function(identityId, password, verifycode, callback) {

	        $.getJSON("/AccountCenter/DoLogin",
				{ identityId: identityId, password: password, verifycode: verifycode },
				function(data) {
				    switch (data.Result) {
				        case "VerifyCodeError": alert("验证码错误!"); break;
				        case "Success": alert("登录成功!"); break;
				        case "InvalidUserName": alert("用户名错误!"); break;
				        case "InvalidPassword": alert("密码错误!"); break;
				        case "UserDisable": alert("账号被禁用!"); break;
				    }
				    if (data.Result == "Success") {
				        window.location.href = "/AccountCenter/Asset";
				    }
				    else {
				        if (!isUndefinedOrNull(callback)) callback();
				    }
				});
                };
        
        // 用户登录，依据会员编号
                prototype.DoLoginAccountVip = function(accountVipNum, password, verifycode, callback) {
                    $.getJSON("/AccountCenter/DoLoginAccountVip",
			            { accountVipNum: accountVipNum, password: password, verifycode: verifycode },
			            function(data) {
			                switch (data.Result) {
			                    case "VerifyCodeError": alert("验证码错误!"); break;
			                    case "Success": alert("登录成功!"); break;
			                    case "InvalidUserName": alert("用户名错误!"); break;
			                    case "InvalidPassword": alert("密码错误!"); break;
			                    case "UserDisable": alert("账号被禁用!"); break;
			                }
			                if (data.Result == "Success") {
			                    window.location.href = "/AccountCenter/Asset";
			                }
			                else {
			                    if (!isUndefinedOrNull(callback)) callback();
			                }
			            });
                };
	    

	    // 找回密码
	    prototype.findPassword = function(username, verifycode, callback) {
	        $.getJSON("/Account/DoFindPassword",
				{ username: username, verifycode: verifycode },
				function(data) {
				    switch (data.Result) {
				        case "VerifyCodeError": alert("验证码错误!"); break;
				        case "UsernameNotExists": alert("用户名错误!"); break;
				        case "Success": alert("密码已发往您的邮箱!"); break;
				    }

				    if (!isUndefinedOrNull(callback)) callback(data.Result);
				});
	    };

	    // 获取当前登录用户信息
	    prototype.getLoginUser = function(callback) {
	        $.getJSON("/Account/GetUserInfo",
				function(data) {
				    if (!isUndefinedOrNull(callback)) callback(data);
				});
	    };

	}
}

