using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace JuSNS.Web
{
    public partial class GetPassword : JuSNS.UI.Page.BasePage
    {
        //0未提交，1，成功，2失败
        protected int flag = 0;
        protected string errmsg = string.Empty;
        protected string email = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["HidAction"] == "Submit")
            {
                email = Request.Form["TxtEmail"];
                string verf = Request.Form["TxtVerify"];
                if (verf == null)
                {
                    flag = 2;
                    errmsg = "验证码不正确，请重新输入";
                }
                else if (Session["CheckCode"]==null)
                {
                    flag = 2;
                    errmsg = "验证码不正确，请重新输入";
                }
                else if (Session["CheckCode"].ToString().ToLower() != verf)
                {
                    flag = 2;
                    errmsg = "验证码不正确，请重新输入";
                    Session.Remove("CheckCode");
                }
                else
                {
                    if (!string.IsNullOrEmpty(email))
                    {
                        Session.Remove("CheckCode");
                        JuSNS.Home.User us = new JuSNS.Home.User();
                        int n = us.Retrieve(email);
                        if (n == -2)
                        {
                            flag = 2;
                            errmsg = "这个 Email 地址没有注册";
                        }
                        else if (n == -3)
                        {
                            flag = 2;
                            errmsg = "邮件发送失败,请稍后再试";
                        }
                        else
                        {
                            flag = 1;
                            Response.Write(n);
                            Response.End();
                        }
                    }
                    else
                    {
                        flag = 2;
                        errmsg = "请填写电子邮件";
                    }
                }
            }
            DataBind();
        }

    }
}
