<%@ Control Language="C#" AutoEventWireup="true" CodeFile="register.ascx.cs" Inherits="register" %>
<link href="css/prism.css" rel="stylesheet" /> <link href="css/gh_materialize.css" type="text/css" rel="stylesheet" media="screen,projection" /> <script src="js/jquery-2.1.4.min.js" type="text/javascript"></script> </script> <script type="text/javascript"> if (!window.jQuery) { document.write('<script src="bin/jquery-2.1.1.min.js"><\/script>'); } </script> <script type="text/javascript"> function ButtonClick() { //参数,如果要向后台传入多个参数,可以用分割的方式进行传入 //例如:name,age,sex,..... 然后后台进行split分割 var 我是变量 = $( "#name" ).val(); //此处为 <%=Page.ClientScript.GetCallbackEventReference(this, "我是变量", "点按钮调用我", null)%> } function 点按钮调用我( ret ) { alert( ret ) } </script> <script src="bean/materialize.js" type="text/javascript"></script> <script src="js/code.js" type="text/javascript"></script> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div style="width: 960px; min-height: 500px; margin-left: auto; margin-right: auto;"> <div style="min-height: 500px; margin-left: auto; margin-right: auto;"> <div> <div style="float: left; width: auto"> <h4 class="header"> 加入我们: </h4> </div> <div style="float: right; width: auto"> 已有账号,<a href="login_user.aspx">马上登陆 </a> </div> <div style="clear: both;"> </div> </div> <div class="col s12 m9 l10"> <div id="input" class="section scrollspy"> <div class="row"> <form class="col s12"> <div class="row"> <%--<div class="input-field col s6"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <label for="last_name"> 账号</label> </div>--%> <div class="input-field col s6"> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> <label for="last_name"> 昵称</label> </div> </div> <div class="row"> <div class="input-field col s12"> <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox> <label for="password"> 密码</label> </div> </div> <div class="row"> <div class="input-field col s12"> <asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox> <label for="password"> 确认密码</label> </div> </div> <%-- <div class="row"> <div class="input-field col s12"> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <label for="email" data-error="wrong" data-success="right"> 邮箱</label> </div> </div>--%> <div class="row"> <div style="float: left;"> <h6 class="header"> 手机号:</h6> </div> <div style="float: left;"> <input type="text" id="name" name="numberphone" /> </div> <div style="float: left; height:50px;"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <input οnclick="time(this);ButtonClick();" type="button" value="发送验证码" /> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> <div style="clear: both"> </div> <div> <h6 class="header"> 输入验证码:</h6> <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></div> </div> <%-- <div class="section scrollspy"> <h6 class="header"> 性别</h6> <p> <input name="sex" type="radio" value="男" id="test1" checked /> <label for="test1"> 男</label> </p> <p> <input name="sex" type="radio" value="女" id="test2" /> <label for="test2"> 女</label> </p> </div>--%> <%-- <div class="row"> <div class="input-field col s12"> <textarea id="textarea1" name="OrderNote" class="materialize-textarea" length="120"></textarea> <label for="textarea1"> 个人简述</label> </div> </div>--%> <!-- Checkboxes --> <div id="checkbox" class="section scrollspy"> <h6 class="header"> 我感兴趣的</h6> <br /> <p> (可以多选) </p> <br /> <div style="float: left;"> <p> <input type="checkbox" id="test9" name="g1" checked value="手机APP设计" /> <label for="test9"> 手机APP设计</label> </p> </div> <div style="float: left; margin-left: 50px;"> <p> <input type="checkbox" id="test6" name="g2" value="影视媒体" /> <label for="test6"> 影视媒体</label> </p> </div> <div style="float: left; margin-left: 50px;"> <p> <input type="checkbox" id="test7" name="g3" value="平面设计" /> <label for="test7"> 平面设计</label> </p> </div> <div style="float: left; margin-left: 50px;"> <p> <input type="checkbox" id="test8" name="g4" value="创意设计" /> <label for="test8"> 创意设计</label> </p> </div> <div> </div> <div style="clear: both"> </div> <div style="margin-top: 50px;"> <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">立即注册</asp:LinkButton> </div> </div> <script type="text/javascript"> function ButtonClick() { //参数,如果要向后台传入多个参数,可以用分割的方式进行传入 //例如:name,age,sex,..... 然后后台进行split分割 var 我是变量 = $( "#name" ).val(); //此处为 <%=Page.ClientScript.GetCallbackEventReference(this, "我是变量", "点按钮调用我", null)%> } function 点按钮调用我( ret ) { alert( ret ) } var wait = 120; function time(o) { if (wait == 0) { o.removeAttribute("disabled"); o.value = "免费获取验证码"; wait = 5; } else { o.setAttribute("disabled", true); o.value = "重新发送(" + wait + ")"; wait--; setTimeout(function () { time(o) }, 1000) } } </script> </form> </div> </div> </div> </div> </div> 后台代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.IO; using System; using System.Security.Cryptography; using System.Text.RegularExpressions; using System.Web.Script.Serialization;public partial class register : System.Web.UI.UserControl, ICallbackEventHandler
{ protected void Page_Load(object sender, EventArgs e) { }protected void LinkButton1_Click(object sender, EventArgs e)
{ //注册用户: if (TextBox5.Text == "") { Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "myscript", "<script>Materialize.toast('昵称不能为空!', 3000, 'rounded');</script>"); } else if (TextBox7.Text == "") { Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "myscript", "<script>Materialize.toast('验证码不能为空!', 3000, 'rounded');</script>"); } else if (TextBox2.Text == "") { Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "myscript", "<script>Materialize.toast('密码不能为空!', 3000, 'rounded');</script>"); } else if (TextBox4.Text == "") { Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "myscript", "<script>Materialize.toast('密码不能为空!', 3000, 'rounded');</script>"); } //else if (TextBox3.Text == "") //{ // Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "myscript", "<script>Materialize.toast('邮箱不能为空!', 3000, 'rounded');</script>"); //}else
{
Datacon dcc = new Datacon();
SqlConnection connn = dcc.SQL_con(); if (connn.State == System.Data.ConnectionState.Closed) { connn.Open(); } string strs = "select * from [User_login] where use_num='" + TextBox5.Text + "' "; SqlCommand commm = new SqlCommand(strs, connn); SqlDataReader dr = commm.ExecuteReader(); if (dr.Read()) { Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "myscript", "<script>Materialize.toast('用户已存在!', 3000, 'rounded');</script>"); }else
{
if (TextBox7.Text.Equals(Session["codes"]))
{
if (!(TextBox2.Text.Equals(TextBox4.Text)))
{ Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "myscript", "<script>Materialize.toast('两次密码不一致!', 3000, 'rounded');</script>"); } else {String name_num = Request.Form["numberphone"];//电话
//string md5_name_num; //加密后数据 //md5_name_num = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(name_num, "MD5"); String pass1 = TextBox2.Text; string md5_pass1; //加密后数据 md5_pass1 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pass1, "MD5"); //String email = TextBox3.Text; String pass2 = TextBox4.Text; String name = TextBox5.Text; //string jianjie = Request.Form["OrderNote"];//个人简介 //String sex = Request.Form["sex"];//性别 String g1 = Request.Form["g1"];//喜好 String g2 = Request.Form["g2"];//喜好 String g3 = Request.Form["g3"];//喜好 String g4 = Request.Form["g4"];//喜好 String like = g1 + "," + g2 + "," + g3 + "," + g4 + ""; Datacon dc = new Datacon(); SqlConnection conn = dc.SQL_con(); if (conn.State == System.Data.ConnectionState.Closed) { conn.Open(); } string str = "insert into [User_login] (use_num,use_name,password,like1) values('" + name_num + "','" + name + "','" + md5_pass1 + "','" + like + "')"; SqlCommand comm = new SqlCommand(str, conn); if (Convert.ToInt32(comm.ExecuteNonQuery()) > 0) { // 在此处放置用户代码以初始化页面 //string namee = name_num; string path = Server.MapPath("") + "\\file" + "\\" + name_num; if (Directory.Exists(path)) { Response.Write("<script>alert('用户已存在了!马上登陆');history.go(-1);</script>"); } else { DirectoryInfo folder = Directory.CreateDirectory(path); string time = Convert.ToString(Directory.GetCreationTime(path)); string foldername = name.Substring(name.LastIndexOf("\\") + 1); // Response.Write("添加成功!"); //Response.Write("添加时间:" + time); //Response.Write("文件夹名:" + foldername); } WebMessageBox.Show("注册成功,欢迎您加入我们!", "index.aspx"); } else { WebMessageBox.Show("注册失败请,检查输入信息!!", "register.aspx"); Response.Redirect("register.aspx"); } if (conn.State == System.Data.ConnectionState.Open) { conn.Close(); }}
} else { Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "myscript", "<script>Materialize.toast('验证码不一致!', 3000, 'rounded');</script>"); } } } } public static string GetMD5(string myString) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString); byte[] targetData = md5.ComputeHash(fromData); string byte2String = null;for (int i = 0; i < targetData.Length; i++)
{ byte2String += targetData[i].ToString("x"); }return byte2String;
} public void but_Click(object sender, object o) { Response.Write("abc"); Session["mobile"]=""; }//protected void Button1_Click1(object sender, System.EventArgs e)
//{ // if (TextBox6.Text.Equals("")) // { // Label1.Text = "手机号不能为空!"; // } // else // { // String phnoeNumber=TextBox6.Text;//获取输入的手机号 // if (IsMobilePhone(phnoeNumber)) // {
// Random rad = new Random();//实例化随机数产生器rad;
// int value = rad.Next(1000, 10000);//用rad生成大于等于1000,小于等于9999的随机数; // Label1.Text = value.ToString(); //用label控件label1显示产生的四位随机数; // GetMessage gm = new GetMessage(); // String s=gm.mian(phnoeNumber, value.ToString());//发送 返回json // String key = getJson(s); // if (key.Equals("00000")) // { // Label1.Text = "有效时间2分钟"; // Button1.Enabled = false; // Button1.Text = "验证码已发送"; // Session["codes"] = value.ToString(); // } // else // { // Label1.Text = "手机号有误,请核实 !"; // } // } // else // { // Label1.Text = "手机号有误 !"; // } // } //} public static bool IsMobilePhone(string input) { Regex regex = new System.Text.RegularExpressions.Regex("^1\\d{10}$"); return regex.IsMatch(input); } public String getJson(String jsons) { var serializer = new JavaScriptSerializer(); var ret = serializer.Deserialize<JsonObject>(jsons); string key = ret.RespCode;return key;
} public class JsonObject { public string RespCode { get; set; } }
/*---------------------------实现下面两个函数------------------------------*/
//定义一个存储变量 string result = string.Empty; public string GetCallbackResult() { return result; }public void RaiseCallbackEvent(string eventArgument)
{ //将计算的结果赋值给result变量 //这里你也可以直接调用bll,或者直接在这里进行读取数据库.... //发送验证码的方法 String phnoeNumber = "";//获取输入的手机号 phnoeNumber = eventArgument; if (IsMobilePhone(phnoeNumber)) { Random rad = new Random();//实例化随机数产生器rad; int value = rad.Next(1000, 10000);//用rad生成大于等于1000,小于等于9999的随机数;GetMessage gm = new GetMessage();
String s = gm.mian(phnoeNumber, value.ToString());//发送 返回json String key = getJson(s); if (key.Equals("00000")) {
Session["codes"] = value.ToString();
}
else {}
} else {}
result = "验证码已发送" + eventArgument; } /*-----------------------------------------------------------------------*/ }