邮箱登录

<div class="tab-2 resp-tab-content" aria-labelledby="tab_item-2">
                            <input id="GetAuto" onclick="GetAuto()" type="button" value="获取验证码" />
                            <div class="register">
                                <form action="#" method="post">
                                    <input type="text" Name="Email" id="Email" placeholder="请输入邮箱" required="">
                                    <input type="text" Name="passWord" id="AuthCode" placeholder="请输入验证码" required="">
                                    <ul>
                                        <li>
                                            <input type="checkbox" id="brand2" value="">
                                            <label for="brand2"><span style="color:white">同意《平安一账通会员服务协议》</span></label>
                                        </li>
                                    </ul>

                                    <div class="send-button">
                                        <input type="submit" onclick="AutoLogin()" value="登陆">
                                    </div>
 //验证码登陆
        function AutoLogin() {
            if (!document.getElementById("brand2").checked) {
                alert("请勾选");
                location.reload(true);
            }
        }
   //邮箱验证码登陆
        function GetAuto() {
            var regemali = new RegExp(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/);
            var emali = $("#Email").val();
            alert(emali);
            if (emali == "") {
                alert("输入不可以为空");
                return;
            }
            else if (!regemali.test(emali)) {
                alert("邮箱格式不正确");
                return;
            }
            else {
                alert("通过");
            }
        }

注册邮箱

 <div style="text-align:center">
            <input id="u6_input" type="text" placeholder="请输入邮箱" /><input id="SetAuto" onclick="SetAuto()"  type="button" value="发送验证码"  /><label id="xianshi" style="color:red"></label>
            <br />
            <br />
            <input id="yanzhengma" placeholder="请输入验证码" type="text" />
            <br />
            <br />
            <input id="Checkbox1" type="checkbox" /><label>我已同意并阅读:<a style="color:red">《平安一账通会员服务协议》</a></label>
            <br />
            <br />
            <input id="Button1" type="button" onclick="verification()" style="width:85px;height:45px" value="点击按钮进行验证" />
        </div>


function SetAuto() {
        var reg = new RegExp(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/);
        var emali = $("#u6_input").val();
        if (emali == "") {
            alert("输入不可以为空");
            return;
        }
        else if (!reg.test(emali)) {
            alert("邮箱格式不正确");
            return;
        }
        else {
            var zhanghao = $('#u6_input').val();//获取邮箱账号

            $.post("/EmailSent/index", {
                "Email": zhanghao
            },
                function (data) {
                    if (data != "发送成功") {
                        alert("发送失败,有可能是你的邮箱账号不正确")
                    } else {
                        i = 56;
                        $("#SetAuto").hide();
                        $("#xianshi").show();
                        setInterval("dingshiqi()", 1000);
                        alert("发送成功")
                    }
                });
             }
    }
    //定时器 等多长时间再获取验证码
    function dingshiqi() {
        i = i - 1;
        if (i > 0) {
            $("#xianshi").html(i + "秒后再次获取验证码");
        } else {
            $("#xianshi").hide();
            $("#SetAuto").show();
        }
    }
    //判断是否注册成功
    function verification() {
        if (!document.getElementById("Checkbox1").checked) {
            alert("请勾选");
            return;
        }
        var yanzhengma = $('#yanzhengma').val();
        $.post("/EmailSent/zhuce", {
            "yanzhengma": yanzhengma
        },
            function (data) {
                if (data == "注册成功") {
                    alert("注册成功")
                } else {
                    alert("注册失败")
                    return;
                }
            });
    }

忘记密码

<div>
        <h3>填写邮箱</h3>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <input id="Email" type="text" /><input id="Button1" onclick="GetAuto()" type="button" value="获取验证码" />
        <br />
        <h3>请输入验证码</h3>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <input id="authcode" type="text" />
        <br />
        <h3>请输入新密码</h3>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <input id="newpass" type="text" />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;
        <input id="Button1" type="button" value="修改" />

    </div>


 function GetAuto() {
            var regemali = new RegExp(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/);
            var emali = $("#Email").val();
            alert(emali);
            if (emali == "") {
                alert("输入不可以为空");
                return;
            }
            else if (!regemali.test(emali)) {
                alert("邮箱格式不正确");
                return;
            }
            else {
                alert("通过");
            }

        }

邮箱登录控制器

//发送邮箱
[HttpPost]
public ActionResult Index(string Email)
{
try
{
Session["y"] = randomnumber(4);
//生成四位数的随机数
//发送邮件前首先你要有一个邮箱地址,
//[email protected]
//smtp smtp.126.com
//密码:
//发送邮件的类
SmtpClient client = new SmtpClient();
//指定发送的方式
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//指定服务器
client.Host = "smtp.qq.com";
//指定发件人的邮箱和密码
client.Credentials = new System.Net.NetworkCredential("[email protected]", "okunfqrtzszleafd");//用户名和密码
//发送邮件的设置
MailMessage message = new MailMessage("[email protected]", Email);
//设置邮件的标题
message.Subject = "我是一份测试邮件";
message.Body = "你的验证码是" + Session["y"];
//是否html格式,
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.UTF8;
//是否开启SSL方式
client.EnableSsl = true;
//发送邮件
client.Send(message);
return Content("发送成功");
}
catch(Exception ex)
{
throw;
}
}
/// <summary>
/// 生成随机验证码
/// </summary>
/// <param name="length"></param>
/// <returns></returns>
public static string randomnumber(int length)
{
var result = new StringBuilder();
for (var i = 0; i < length; i++)
{
var r = new Random(Guid.NewGuid().GetHashCode());
result.Append(r.Next(0, 10));
}
return result.ToString();
}
//判断是否注册成功
[HttpPost]
public ActionResult zhuce(string yanzhengma)
{
if (yanzhengma == Session["y"].ToString())//判断用户输入的验证码是否和发送到邮箱的验证码一致
{
return Content("注册成功");
}
else
{
return Content("注册失败");
}

}

猜你喜欢

转载自www.cnblogs.com/ntg2/p/13197248.html