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

namespace CitySunlight
{
    public partial class register : System.Web.UI.Page
    {
        public String msg;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void submit_Click(object sender, EventArgs e)
        {
            String username = HttpUtils.getElementsbyName("usernameTx");
            String password = HttpUtils.getElementsbyName("passwordTx");
            String confirm = HttpUtils.getElementsbyName("confirmTx");

            if (username == "" || password == "" || confirm == "")
            {
                msg = "请填写完整的账号密码!";
                return;
            }

            if (password != confirm)
            {
                msg = "两次输入的密密码不一致!";
                return;
            }

            if (UserManager.isExist(username))
            {
                msg = "当前用户名已存在,请换一个用户名!";
                return;
            }

            if (UserManager.RegisterUser(username, password))
            {
                Response.Redirect("<scrip>alert('1')</scrip>");
                Session["username"] = username;
                Response.Redirect("../Main.aspx");
            }
            else
            {
                msg = "注册失败,请联系管理员!";
            }
        }

    }
}