﻿/// 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.login_manager = function(mobile, password, verifycode, callback) {
            $.getJSON("/AccountCenter/DoLoginAccountVipManager",
			                    { mobile: mobile, password: password, verifycode: verifycode },
			                    function(data) {
			                        switch (data.Result) {
			                            case "VerifyCodeError": alert("验证码错误!"); break;
			                            case "Success": alert("登录成功!"); break;
			                            case "InvalidUserName": alert("很抱歉，您的号码尚未在星石投资登记，请联系星石投资的渠道经理。如果您不知道服务您的渠道经理，请致电星石投资客户服务热线4008189800（免长途费）。谢谢！"); break;
			                            case "InvalidPassword": alert("密码错误!"); break;
			                            case "UserDisable": alert("账号被禁用!"); break;
			                        }

			                        if (data.Result == "Success") {
			                            window.location.href = "/AccountCenter/WelcomeManager/179";
			                        }
			                        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);
				});
	    };

	}
}


