• 登录注册V


    View层

    Add.cshtml


    @{
    Layout = null;
    }

    <!DOCTYPE html>

    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>Add</title>
    <script src="~/Content/jquery-3.1.1.js"></script>
    @*验证码类*@
    <script src="~/Content/yzmJS.js"></script>
    @*验证码样式*@
    <link href="~/Content/yzmStyle.css" rel="stylesheet" />
    @*布局样式*@
    <style>
    * {
    margin: 0;
    padding: 0;
    }

    a {
    text-decoration: none;
    }

    .login {
    margin-left: 450px;
    margin-top: 170px;
    }

    ul {
    list-style: none;
    }

    li {
    margin-bottom: 10px;
    }

    li .bt {
    color: red;
    }

    li .zi {
    color: #666;
    }

    .txtAdd {
    285px;
    height: 35px;
    border: 1px solid aquamarine;
    }

    .ty {
    font-size: 12px;
    margin-top: 20px;
    margin-left: 90px;
    }

    .btnAdd {
    285px;
    height: 35px;
    background-color: red;
    border: 1px solid red;
    color: white;
    margin-top: 10px;
    margin-left: 90px;
    }

    .txtAddYZ {
    150px;
    height: 35px;
    border: 1px solid aquamarine;
    }
    .tp {
    80px;
    height: 35px;
    }
    .yz {
    font-size: 12px;
    }
    #spName {
    color:red;
    font-size:12px;
    }
    #spPwd0 {
    color: red;
    font-size: 12px;
    }
    #ckTong {
    color: red;
    font-size: 12px;
    }
    #spYan {
    color: red;
    font-size: 12px;
    margin-left:8px;
    }
    </style>
    </head>
    <body>
    <form id="FormAdd">
    <div class="login">
    <ul>
    <li>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="bt">*</span>
    <samp class="zi"> 用户名</samp>:
    <input class="txtAdd" id="Text1" type="text" name="UserName" />
    <span id="spName"></span>
    </li>
    <li>
    <span class="bt">*</span>
    <samp class="zi"> 请设置密码</samp>:
    <input class="txtAdd" type="password" name="UserPassword" />
    <span id="spPwd"></span>
    </li>
    <li>
    <span class="bt">*</span>
    <samp class="zi"> 请确认密码</samp>:
    <input class="txtAdd" type="password" name="pwd0" />
    <span id="spPwd0"></span>
    </li>
    <li>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="bt">*</span>
    <samp class="zi"> 验证码</samp>:
    <input class="txtAddYZ" type="text" id="yanz" />
    <input type="button" id="code" onclick="createCode()" class="tp" />
    <a href="javascript:void(0)" onclick="createCode()" class="yz">看不清,再换一张</a><span id="spYan"></span>
    </li>
    <li class="ty">
    <input id="Checkbox1" type="checkbox" name="ck" />
    我已阅读并同意<a href="#">《金象网用户注册协议》</a>
    <span id="ckTong"></span>
    </li>
    </ul>

    <input id="Button1" class="btnAdd" type="button" value="立即注册" onclick="Add()"/>
    </div>
    </form>
    </body>
    </html>
    <script>
    $(function () {
    //获取焦点
    $("input").focus();
    //用户名文本框失去焦点
    $("[name=UserName]").blur(function () {
    $.ajax({
    url: "/Login/GetUser?Name=" + $("[name=UserName]").val(),
    type: "post",
    success: function (d) {
    console.log(d)
    if (d ==1) {
    $("#spName").html("用户名以存在")
    }
    else {
    $("#spName").html("")
    }
    }
    })
    })
    //确认密码框失去焦点
    $("[name=pwd0]").blur(function () {
    if ($("[name=pwd0]").val() != $("[name=UserPassword]").val()) {
    $("#spPwd0").html("两次密码输入不一致");
    }
    else {
    $("#spPwd0").html("")
    }
    })
    })

    //验证码,协议验证 加上添加
    function Add() {
    var oValue = $("#yanz").val().toUpperCase();
    console.log(oValue);
    if (oValue == 0) {
    $("#spYan").html("请输入验证码")
    }
    else if (oValue != code) {
    $("#spYan").html("验证码不正确")
    }
    else {
    $("#spYan").html("")
    }
    if (!$("#Checkbox1").prop("checked")) {
    $("#ckTong").html("尚未同意协议")
    return
    }
    else {
    $.ajax({
    url: "/Login/Add",
    type: "post",
    data: $("#FormAdd").serialize(),
    success: function (data) {
    if (data > 0) {
    alert("注册成功")
    location.href="/Login/Login"
    }
    }
    })
    }
    }
    </script>

    Index.cshtml


    @{
    Layout = null;
    }

    <!DOCTYPE html>

    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <style>
    * {
    padding:0;
    margin:0;
    }
    a {
    text-decoration: none;
    color: #4cff00;
    }
    .head {
    margin-left:500px;
    font-size:25px;

    }
    .geren {
    margin-top:40px;
    margin-left: 400px;
    color:#b200ff;
    }
    </style>
    </head>

    <body>
    <div>
    <span class="head"><a href="/Login/Login">登陆</a>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="/Login/Add">注册</a></span>
    <div class="geren">
    <h2>欢迎你,@ViewBag.Name</h2>

    </div>
    </div>
    </body>
    </html>

    Login.cshtml


    @{
    Layout = null;
    }

    <!DOCTYPE html>

    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>Login</title>
    <script src="~/Content/jquery-3.1.1.js"></script>
    <script src="~/Content/yzmJS.js"></script>
    <link href="~/Content/yzmStyle.css" rel="stylesheet" />
    <style>
    * {
    margin:0;
    padding:0;
    }
    a {
    text-decoration:none;
    }
    .form {
    margin-left: 500px;
    margin-top: 150px;
    }
    ul {
    list-style:none;
    }
    .tiao {
    font-size:12px;
    margin-left:30px;
    }
    .Text1 {
    285px;
    height:35px;
    margin-top:10px;
    border:1px solid #d0cece;

    }
    .Text2 {
    285px;
    height: 35px;
    margin-top: 20px;
    border: 1px solid #d0cece;
    }
    .Text3 {
    height: 35px;
    150px;
    border: 1px solid #d0cece;
    margin-top: 20px;
    }
    .Checkbox1 {
    margin-top: 20px;
    }
    .ck {
    font-size:12px;
    }
    .password {
    margin-left:170px;
    font-size:12px;
    }
    .Button1 {
    background-color: #0094ff;
    color: white;
    285px;
    height: 35px;
    border: 1px solid #0094ff;
    margin-top:20px;
    }
    .tp {
    80px;
    height: 35px;
    }
    .yz {
    font-size: 12px;
    }
    #cuo {
    color:red;
    font-size:14px;
    margin-left:80px;
    padding-top:8px;
    }
    </style>
    </head>
    <body>
    <div class="form">
    <span class="head">Hi,欢迎登陆!</span><span class="tiao">还不是金象网会员?<a href="/Login/Add">免费注册</a></span>
    <p id="cuo"></p>
    <ul>
    <li>
    <input class="Text1" type="text" placeholder="邮箱/用户名/已验证手机" name="UserName"/>
    </li>
    <li>
    <input class="Text2" type="password" placeholder="密码" name="UserPassword"/>
    </li>
    <li>
    <input class="Text3" type="text" name="Yanz"/>
    <input type="button" id="code" onclick="createCode" class="tp"/>
    <a href="javascript:void(0)" onclick="createCode" class="yz">看不清,再换一张</a><span id="Yanz"></span>
    </li>
    <li>
    <input class="Checkbox1" type="checkbox" /> <span class="ck">自动登陆</span><span class="password">忘记密码?</span>
    </li>
    </ul>
    <input class="Button1" type="button" value="立即登陆" id="btnAdd"/>
    </div>
    </body>
    </html>
    <script>
    $(function () {
    $("input").focus();
    $("[name=UserName]").blur(function () {
    $.ajax({
    url: "/Login/GetUser?Name=" + $("[name=UserName]").val(),
    type: "post",
    success: function (data) {
    if (data == 0) {
    $("#cuo").html("用户名不能存在")
    location.href = "/Login/Add"
    }
    else {
    $("#btnAdd").click(function () {
    Add();
    })
    }
    }
    })
    })
    $("[name=UserPassword]").blur(function () {
    if ($("[name=UserPassword]").val() == "") {
    $("#cuo").html("!密码不能为空")
    }
    else {
    $("#cuo").html("")
    }
    })
    })

    function Add() {
    var oValue = $("[name=Yanz]").val().toUpperCase()
    if (oValue == "") {
    $("#cuo").html("请输入验证码")
    }
    else if (oValue != code) {
    $("#cuo").html("验证码输入有误")
    }
    else {
    $("#cuo").html("")
    $.ajax({
    url: "/Login/UserLogin?Name=" + $("[name=UserName]").val() + "&Password=" + $("[name=UserPassword]").val(),
    type: "post",
    success: function (data) {
    if (data > 0) {
    location.href="/Login/Updata"
    }
    else {
    $("#cuo").html("密码有误,或用户被冻结")
    }
    }
    })
    }

    }
    </script>

    Updata.cshtml


    @{
    Layout = null;
    }

    <!DOCTYPE html>

    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>Updata</title>
    <script src="~/Content/jquery-3.1.1.js"></script>
    <style>
    * {
    padding:0;
    margin:0;
    }
    a {
    text-decoration:none;
    color:#000000;
    }
    ul li {
    list-style:none;
    }
    .dao {

    }
    .bt {
    color:red;
    }
    .Text1 {
    margin-top:20px;
    180px;
    height: 30px;
    border-radius:8px 8px;
    border:1px solid #808080;
    }
    .geren {

    }
    .update {
    margin-left:400px;
    margin-top:200px;
    }
    .Button1 {
    120px;
    height: 30px;
    background-color: #0094ff;
    color: white;
    border: 1px solid #0094ff;
    border-radius: 8px 8px;
    margin-top:20px;
    margin-left:100px;
    }
    </style>
    </head>
    <body>
    <form id="form0">
    <div class="update">
    <ul>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;登陆账号:<span class="name" name="spName" id="sp">@ViewBag.Name</span></li>
    <li>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;原密码:
    <input class="Text1" type="password" name="pwd1" />
    <span class="bt" id="spPwd1">*</span>
    </li>
    <li>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;新密码:
    <input class="Text1" type="password" name="pwd2" />
    <span class="bt" id="spPwd2">*</span>
    </li>
    <li>
    确认新密码:
    <input class="Text1" type="password" name="pwd3" />
    <span class="bt" id="spPwd3">*</span>
    </li>
    </ul>
    <input class="Button1" type="button" value="保存" onclick="Add()"/>
    </div>
    </form>
    </body>
    </html>
    <script>
    $(function () {
    $("input").focus();
    $("[name=pwd1]").blur(function () {
    $.ajax({
    url: "/Login/UserLogin?Name=" + $("[name=spName]").html() + "&Password=" + $("[name=pwd1]").val(),
    type: "post",
    success: function (data)
    {
    console.log(data)
    if (data> 0) {
    $("#spPwd1").html("")
    }
    else {
    $("#spPwd1").html("原密码错误,请重新输入")
    }
    }
    })
    })
    })

    function Add() {

    if ($("#spPwd1").html("") == "")
    return
    $.ajax({
    url: "/Login/UserUpdata?Password=" + $("[name=pwd2]").val(),
    type: "post",
    success: function (data) {
    console.log(data)
    if (data > 0) {
    location.href="/Login/Index"
    }
    }
    })
    }
    </script>

  • 相关阅读:
    H265播放器EasyPlayer.js首次加载出现Uncaught (in promise) DOMException错误信息
    合并数组并去重(ES5和ES6两种方式实现)
    ant vue transfer 使用
    python算法实现list转tree 型结构
    django choices 字段处理返回枚举值
    threadExecutor 异步应用
    自定义实现httprunner debugtalk 的函数助手功能
    【洛谷P4022】熟悉的文章
    【HDU7060】Separated Number
    【洛谷P2605】基站选址
  • 原文地址:https://www.cnblogs.com/hianb/p/10003155.html
Copyright © 2020-2023  润新知