using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using JuSNS.Home;
using JuSNS.Model;
using JuSNS.Common;

namespace JuSNS.Web
{
    public partial class RegVerify : JuSNS.UI.Page.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string r = Request.QueryString["r"];
                string email = Request.QueryString["e"];
                if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(r))
                {
                    this.LtrTitle.Text = "<div class=\"msg-error\">错误的参数。</div>";
                }
                else
                {
                    int userId;
                    string userName;
                    string userPwd;
                    User us = new User();
                    //0成功,-1验证码不正确,-2该用户已通过验证,-3数据修改失败
                    int n = us.RegisterConfirm(r, email, out userId, out userName, out userPwd);
                    switch (n)
                    {
                        case 0:
                            JuSNS.UI.Page.UserPage.SetCookie(userId, userName, userPwd, string.Empty, false);
                            //得到是不是第一次登陆
                            UserInfo mdl = new UserInfo();
                            mdl = us.GetUserInfo(userId);
                            int ln = mdl.LoginTimes;
                            if (ln < 1 && string.IsNullOrEmpty(this.GetHeadPath(userId)))
                            {
                                //获取是否是被邀请注册的，如果是邀请注册的。则为邀请者增加积分
                                us.GetInvReg(userId);
                                //插入积分
                                us.updateinte(userId, 100, 0, 0, "注册会员");

                                Response.Redirect(rooDir + "/home/space/edit.aspx?f=1");
                            }
                            else
                            {
                                us.updateinte(userId, 200, 0, 0, "验证邮件");
                                Response.Redirect(rooDir + "/home");
                            }
                            break;
                        case -1:
                            this.LtrTitle.Text = "<div class=\"msg-error\">验证码或者电子邮件不正确。</div>";
                            break;
                        case -2:
                            this.LtrTitle.Text = "<div class=\"msg-error\">该用户已通过验证。无需验证！</div>";
                            break;
                        case -3:
                            this.LtrTitle.Text = "<div class=\"msg-error\">数据修改失败。</div>";
                            break;
                    }
                }
            }
        }
    }
}

