using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using xabaraCOM;

public partial class member_user_login : System.Web.UI.Page
{
    user u = new user();
    xabara x = new xabara();
    javasrcipt js = new javasrcipt();
    public string returnUrl = "/member/";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            returnUrl = Server.UrlDecode(Request.QueryString["url"]);

            string userID = u.autoLogin(returnUrl);
            if (string.IsNullOrEmpty(userID as string))
            {
                userID = "用户名/邮箱/手机号码";
            }
            uID.Text = userID;

            regExpression reg = new regExpression();
            uIDRegularExpressionValidator.ValidationExpression = reg.CHAR(2, 20);
            uIDRegularExpressionValidator.ErrorMessage = reg.charError(2, 20);
            PWRegularExpressionValidator.ValidationExpression = reg.passWord(6, 20);
            PWRegularExpressionValidator.ErrorMessage = reg.passWordError(6, 20);
            RndNumReg.ValidationExpression = reg.rndNums(6, 20);
            RndNumReg.ErrorMessage = reg.rndNumsError(6, 20);

            //快捷登录检查
            if (string.IsNullOrEmpty(xml.read("xabara.config", "qqAppID", 180) as string))
            {
                qq.Visible = false;
            }

            //aliPay快捷登录检查
            if (string.IsNullOrEmpty(xml.read("xabara.config", "aliPayID", 180) as string))
            {
                alipay.Visible = false;
            }

            /*QQ快捷登录检查
            if (!string.IsNullOrEmpty(Session["qq"] as string))
            {
                qq.Visible = false;

                errorInfo.Text = "老用户请先登录后再点击QQ登录捆绑帐号，新用户请点击右边 注册 按钮直接注册新会员！";
            }*/
        }

        Page.Title = "用户登陆　" + xml.read("xabara.config", "webName", 180) + xml.read("xabara.config", "titleMeta", 180);
    }

    protected void loginEnter_Click(object sender, ImageClickEventArgs e)
    {
        bool isLogin = false;
        if (checkLogin.Checked)
        {
            isLogin = true;
        }

        if (x.checkValidateCode(false, RndNum.Text.Trim()))
        {
            u.login("", uID.Text, uPW.Text, "", true, isLogin);
        }
        else
        {
            errorInfo.Text = "您的验证码有误，请重新填写！";
        }
    }

    protected void regImages_Click(object sender, ImageClickEventArgs e)
    {
        if (!string.IsNullOrEmpty(Session["qq"] as string))
        {
            string qq = Session["qq"].ToString().Trim();

            webPublic wp = new webPublic();
            wp.regUser("qq^" + qq, qq + "@qq.com", "", xabara.rnd("abc123", 8), "QQ用户");
        }
        else
        {
            js.alert("", "url", "/member/user/reg.aspx");
        }
    }
}