node+mysql实现(账户密码,阿里云短信验证,QQ邮箱注册登录,短信验证密码重置,邮箱密码重置)之注册,登录密码重置总篇

node+mysql实现账户登录

    • 注意
      • 效果图
      • 项目插件
      • 代码参数说明
        • 短信验证模块
        • 邮箱验证模块
        • 注册方式
        • 登录方式
        • 密码重置
      • 前端页面部分
        • 登录页面
          • 账户登录页面(login.html)
          • 短信验证登录页面(smsLogin.html)
          • 邮箱登录页面(emailLogin.html)
        • 注册部分页面
          • 短信验证注册页面(register.html)
          • 邮箱验证注册(emailRegister.html)
        • 密码重置部分页面
          • 短信验证密码重置(restPassword.html)
          • 邮箱验证密码重置(emailRest.html)
      • js部分
        • 数据库连接db.js
        • SQL语句部分(db/account.js)
        • 路由下的js部分(router/*)
          • account.js
          • api.js
          • email.js
      • app.js
        • MySQL

注意

项目中所用到的验证码模块都不是虚拟的,手机号短信验证调用的是阿里云的短信服务模块,QQ邮箱验证码是调用邮件服务模块

效果图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

项目插件

layui ,layui消息通知插件(notify)

//Express
npm install express
//body-parser
npm install body-parser
//阿里云相关短信服务
npm install @alicloud/dysmsapi20170525
npm install @alicloud/openapi-client
npm install @alicloud/tea-util
//mysql2
npm install mysql2
//邮件
npm install nodemailer

代码参数说明

短信验证模块

在这里插入图片描述

邮箱验证模块

在这里插入图片描述

注册方式

在这里插入图片描述

登录方式

在这里插入图片描述

密码重置

在这里插入图片描述

前端页面部分

登录页面
账户登录页面(login.html)

在这里插入图片描述

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>暖意书栈登录</title><!-- 设置系统图标 --><link rel="shortcut icon" href="../icon/login.ico" type="image/x-icon" /><!-- 引用layui文件中layui.css --><link rel="stylesheet" href="../layui/css/layui.css"  media="all"></link>
</head>
<style>.login-container{width: 320px; margin: 241px auto 0;}.reg-other .layui-icon{position: relative; display: inline-block; margin: 0 15px; top: 2px; font-size: 30px;}body {background-image: url(../image/login_index.jpg);background-size: cover;background-repeat: repeat;}.register-link-container {text-align: right; /* 右对齐文本 */}</style>
<body>
<form class="layui-form" id="loginForm"><div class="login-container"><div class="layui-form-item"><div class="layui-input-wrap"><div class="layui-input-prefix"><i class="layui-icon layui-icon-username"></i></div><input type="number" name="account"  lay-verify="required|phone" placeholder="账户" lay-reqtext="请先填写账户" lay-vertype="tips" autocomplete="off" class="layui-input" lay-affix="clear"></div></div><div class="layui-form-item"><div class="layui-input-wrap"><div class="layui-input-prefix"><i class="layui-icon layui-icon-password"></i></div><input type="password" name="password"  lay-verify="required" placeholder="密   码" lay-reqtext="请填写密码" lay-vertype="tips" autocomplete="off" class="layui-input" lay-affix="eye"></div></div><div class="layui-form-item"><input type="checkbox" name="remember" lay-skin="primary" title="记住密码"><a href="/rest" style="float: right; margin-top: 7px;color: #435594;">忘记密码?</a></div><div class="layui-form-item"><button class="layui-btn layui-btn-fluid layui-bg-black" lay-submit lay-filter="loginBtn">&nbsp;&nbsp;&nbsp;&nbsp;</button></div><div class="layui-form-item "><a href="/sms" style="position: fixed;color: #435594;">短信快捷登录</a><div class="register-link-container"><a href="/register" style="color: #435594;">注册帐号</a> </div><div style="display: flex; align-items: center;"><hr class="layui-border-green" style="height: 1px;  flex: 1; margin: 0 5px;"><span style="color: gray;font-size: 12px;">其他方式登录</span><hr class="layui-border-green" style="height: 1px;  flex: 1; margin: 0 5px;"></div><div class="reg-other"><a href="/emailLogin"title="使用QQ邮箱登录" ><i class="layui-icon layui-icon-login-qq" style="color: #1680eb;"></i></a><a href="javascript:;" title="使用微信账号登录" onclick="layer.msg('功能设计开发中')"><i class="layui-icon layui-icon-login-wechat" style="color: #36761e;"></i></a><a href="javascript:;" title="使用微博账号登录" onclick="layer.msg('功能设计开发中')"><i class="layui-icon layui-icon-login-weibo" style="color: #cf1900;"></i></a><a href="javascript:;" title="使用GitHub账号登录" onclick="layer.msg('功能设计开发中')"><i class="layui-icon layui-icon-github" ></i></a><a href="javascript:;" title="使用Windows账户登录" onclick="layer.msg('功能设计开发中')"><i class="layui-icon layui-icon-windows" style="color: #91b0d4;" ></i></a></div></div></div>
</form><!-- layui.js 地址 -->
<script src="../layui/layui.js"></script> 
<script src="../notify/notify.js"></script>
<script>layui.use(['notify'],function(){var $ = layui.$;var form = layui.form;var layer = layui.layer;var util = layui.util;var notify = layui.notify;// 方法2: 引用第三方消息通知组件进行表单提交事件form.on('submit(loginBtn)', function(data){var field = data.field; // 获取表单字段值if(field.password.length < 6){notify.info({msg:'密码长度不能小于6位',position:'vcenter',shadow:true, closable:false,duration:1000});return false;}/*加载提示:用法 notify.info({msg:"提示",//提示信息closable:true,//是否显示关闭按钮 默认是trueposition:'vcenter',// 指定弹出位置:默认topCenter,可选值:bottomRight|bottomLeft|topRight|topLeft|topCenter|bottomCenter|vcenter"shadow:true,//  是否显示阴影默认是falseduration:2000,//显示时间默认3000,为 0 时不自动关闭});*/notify.loading({msg:'验证登录中,请稍后...',position:'vcenter',shadow:true, closable:false});//显示加载中setTimeout(function(){notify.destroyAll();//关闭所有通知$.ajax({url: '/user/login',type: 'post',data: {account:field.account,password:field.password,key:1 //1:账户手机号登录;2:短信验证登录;3:邮箱登录}, // 数据转换为JSON字符串success: function(res) {if(res.code == 0){//弹出成功提示notify.success({msg:res.msg,position:'vcenter',shadow:true, closable:false,duration:1000});//跳转到系统首页,延迟500毫秒setTimeout(function(){location.href = '/main';}, 500);}else{//弹出错误提示notify.error({msg:res.msg,position:'vcenter',shadow:true, closable:false,duration:1000});}}}).done(function () {setTimeout(function () {parent.location.reload();//重载页面}, 1500);});}, 2000);// 阻止表单跳转return false; //如果不加的话,表单不会跳转但不会进行登录操作});});</script></body>
</html>
短信验证登录页面(smsLogin.html)

在这里插入图片描述

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>暖意书栈快捷账户登录</title><!-- 设置系统图标 --><link rel="shortcut icon" href="../icon/smslogin.ico" type="image/x-icon" /><!-- 引用该 layui.css 地址 --><link href="../layui/css/layui.css" rel="stylesheet">
</head>
<style>.reg-container{width: 320px; margin: 240px auto 0;}.reg-other .layui-icon{position: relative; display: inline-block; margin: 0 2px; top: 2px; font-size: 26px;}body {background-image: url(../image/login_index.jpg);background-size: cover;background-repeat: repeat;}.register-link-container {text-align: right; /* 右对齐文本 */}</style>
<body>
<form class="layui-form"><div class="reg-container"><div class="layui-form-item"><div class="layui-input-wrap"><div class="layui-input-prefix"><i class="layui-icon  layui-icon-cellphone"></i></div><input type="number" name="cellphone" value="" lay-verify="required|phone"  lay-vertype="tips" placeholder="手机号" lay-reqtext="请先填写手机号" autocomplete="off" class="layui-input" id="login-cellphone"></div></div><div class="layui-form-item"><div class="layui-row"><div class="layui-col-xs7"><div class="layui-input-wrap"><div class="layui-input-prefix"><i class="layui-icon layui-icon-vercode"></i></div><input type="text" name="vercode" value="" lay-verify="required" placeholder="验证码"  lay-vertype="tips" lay-reqtext="请填写验证码" autocomplete="off" class="layui-input"></div></div><div class="layui-col-xs5"><div style="margin-left: 11px;"><button type="button" class="layui-btn layui-btn-fluid layui-bg-cyan" lay-on="get-vercode">获取验证码</button></div></div></div></div><div class="layui-form-item"><button class="layui-btn layui-btn-fluid layui-bg-cyan" lay-submit lay-filter="loginBtn">&nbsp;&nbsp;&nbsp;&nbsp;</button></div><div class="layui-form-item reg-other"><label>其他账号登录</label><span style="padding: 0 21px 0 6px;"><a href="/emailLogin"title="使用QQ邮箱登录" "><i class="layui-icon layui-icon-login-qq" style="color: #124e89;"></i></a><a href="javascript:;" title="使用微信账号登录" onclick="layer.msg('功能设计开发中')"><i class="layui-icon layui-icon-login-wechat" style="color: #36761e;"></i></a><ahref="javascript:;" title="使用微博账号登录" οnclick="layer.msg('功能设计开发中')"><i class="layui-icon layui-icon-login-weibo" style="color: #cf1900;"></i></a></span><a href="/" style="color: #435594;">返回账户登录</a></div></div>
</form><!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="../layui/layui.js"></script> 
<script src="../notify/notify.js"></script>
<script>
layui.use(function(){var $ = layui.$;var form = layui.form;var layer = layui.layer;var util = layui.util;// 提交事件form.on('submit(loginBtn)', function(data){var field = data.field; // 获取表单字段值notify.loading({msg:'验证登录中,请稍后...',position:'vcenter',shadow:true, closable:false});//显示加载中setTimeout(function(){notify.destroyAll();$.ajax({url: '/api/verifyCode',type: 'POST',data: {phoneNumber:field.cellphone,//手机号verificationCode:field.vercode,//验证码code:2//1代表注册;2:登录;3:密码重置}, // 数据转换为JSON字符串success: function(res) {if(res.success){//进行账户注册操作$.ajax({url: '/user/login',type: 'POST',data: {account:field.cellphone,key:2 //1:账户登录;2:短信登录;3:邮箱登录}, // 数据转换为JSON字符串success: function(res) {if(res.code == 0){//弹出成功提示notify.success({msg:res.msg,position:'vcenter',shadow:true, closable:false,duration:1000});//跳转到系统首页,延迟500毫秒setTimeout(function(){location.href = '/main';}, 500);}else if(res.code == 1){notify.warning({msg:res.msg,position:'vcenter',shadow:true, closable:false,duration:1000})}else{notify.error({msg:res.msg,position:'vcenter',shadow:true, closable:false,duration:1000})}}});}else{notify.error({msg:res.message,position:'vcenter',shadow:true, closable:false,duration:1000})}}}).done(function () {setTimeout(function () {parent.location.reload();//重载页面}, 1500);});},2000)return false; // 阻止默认 form 跳转});// 普通事件util.on('lay-on', {// 获取验证码'get-vercode': function(othis){var isvalid = form.validate('#login-cellphone'); // 主动触发验证,v2.7.0 新增 //获取输入框的手机号值var phoneNumber = $('#login-cellphone').val();//验证手机号是否是正确手机号if(phoneNumber!=''){if (!/^1[3456789]\d{9}$/.test(phoneNumber)) {notify.warning({msg:'请输入正确的手机号',position:'vcenter',shadow:true, closable:false,duration:1500});return false;}}// 验证通过if(isvalid){$.ajax({url: '/api/sendCode',type: 'POST',data: { phoneNumber:phoneNumber,//手机号code:2//验证码类型},success: function(response) {if (response.success) {notify.success({msg:response.message,position:'vcenter',shadow:true, closable:false,duration:1200});// 按钮显示倒计时(60秒后重新获取)var countdown = 60; // 直接用秒数进行倒计时othis.attr('disabled', true); // 在开始倒计时前禁用按钮othis.text(countdown + '秒后重新获取');var interval = setInterval(function() {if (countdown <= 0) { // 当倒计时小于等于0时clearInterval(interval); // 清除倒计时定时器othis.text('获取验证码'); // 恢复按钮文本othis.removeAttr('disabled'); // 恢复按钮的可点击状态} else {othis.text(countdown + '秒后重新获取'); // 更新倒计时文本countdown--; // 减少倒计时秒数}}, 1000); // 每1000毫秒执行一次,即每秒倒计时递减} else {notify.error({msg:response.message,position:'vcenter',shadow:true, closable:false,duration:1000});}},error: function() {notify.error({msg:response.message,position:'vcenter',shadow:true, closable:false,duration:1000});}});}}});
});
</script></body>
</html>
邮箱登录页面(emailLogin.html)

在这里插入图片描述

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>暖意书栈邮箱登录</title><!-- 设置系统图标 --><link rel="shortcut icon" href="../icon/email.ico" type="image/x-icon" /><!-- 引用layui文件中layui.css --><link rel="stylesheet" href="../layui/css/layui.css"  media="all"></link>
</head>
<style>.login-container{

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/874941.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python Word 操作全面指南

Word 是我们日常生活中经常使用的文档处理工具&#xff0c;而 Python 作为一种强大的编程语言&#xff0c;在处理 Word 文件方面也有着广泛的应用。本文将全面总结 Python Word 操作&#xff0c;包括如何使用 Python 来读取、写入、修改 Word 文件&#xff0c;以及如何使用 Pyt…

【C++高阶】深度剖析:从零开始模拟实现 unordered 的奥秘

&#x1f4dd;个人主页&#x1f339;&#xff1a;Eternity._ ⏩收录专栏⏪&#xff1a;C “ 登神长阶 ” &#x1f921;往期回顾&#x1f921;&#xff1a;哈希底层 &#x1f339;&#x1f339;期待您的关注 &#x1f339;&#x1f339; ❀哈希 &#x1f4d2;1. 改造 HashTable…

Qt多语言功能实现

本文介绍Qt多语言功能实现。 应用程序多语言支持是常用功能&#xff0c;比如产品需要出口到不同语种的国家。采用Qt的多语言支持工具可以方便实现应用程序的多语言功能。本文以中英文语言切换为例&#xff0c;简要介绍Qt的多语言功能实现。 1.界面设计 界面设计需要考虑使用…

正则表达式与文本三剑客之grep

目录 前言 一、grep命令 二、基础正则表达式常见元字符 2.1、特殊字符 2.2、定位符 2.3、非打印字符 三、元字符操作实例 3.1、查找特定字符 3.2、利用中括号“[]”来查找集合字符 3.3、查找行首“^”与行尾字符“$” 3.4、查找任意一个字符“.”与重复字符“*” 3.…

Pattern的多种匹配模式

参考&#xff1a; 好文→ Pattern的多种匹配模式 – 《JAVA编程思想》42 目录标题 单行匹配多行匹配正则匹配忽略大小写Unicode 字符集中的大小写敏感字符都将表示字面含义考虑字符的等价性会忽略正则表达式中的空格及#开始后面的部分只会将 \n 认作换行符\w 可以匹配任何语言…

BGP选路之Preferred value

原理概述 当一台BGP路由器中存在多条去往同一目标网络的BGP路由时&#xff0c;BGP协议会对这些BGP路由的属性进行比较&#xff0c;以确定去往该目标网络的最优BGP路由&#xff0c;然后将该最优BGP路由与去往同一目标网络的其他协议路由进行比较&#xff0c;从而决定是否将该最优…

fastadmin 批量上传图片

1.自定义按钮 <button type"button" id"faupload-local" class"btn btn-primary btn-danger faupload" data-input-id"c-local" data-multiple"true" data-preview-id"p-local" data-url"{:url(ajax/upl…

OAuth2.0 or Spring Session or 单点登录流程

1.社交登录 2.微博社交登录 第三方登录 1.登录微博 2.点击网站接入 3.填写完信息&#xff0c;到这里&#xff0c;写入成功回调 和 失败回调 是重定向&#xff0c;所以可以写本地的地址 3.认证 分布式Session spring-session 域名不一样 发的 jSessionId 就不同&#xff0c…

自定义element主题

说明&#xff1a;这里使用的是vue3做的demo&#xff0c;所以使用的是element-plus&#xff0c;不同版本大同小异 一、安装element-plus npm install element-plus --save二、在main.ts中引入 import ElementPlus from "element-plus"; import "element-plus/d…

如何使用Python的http.server模块(或Flask/Django的简化版本)实现一个简单的HTTP服务器,能够处理GET和POST请求

使用Python的http.server模块实现HTTP服务器 http.server模块是Python标准库中的一部分&#xff0c;它提供了一个非常基础的HTTP服务器实现。虽然这个服务器主要用于测试和开发目的&#xff0c;但它确实能够处理GET和POST请求。不过&#xff0c;请注意&#xff0c;http.server…

MySQL-视 图

视 图 创建视图 视图是从一个或者几个基本表&#xff08;或视图&#xff09;导出的表。它与基 本表不同&#xff0c;是一个虚表。 语法&#xff1a; create view 视图名 【view_xxx/v_xxx】 说明&#xff1a; • view_name 自己定义的视图名&#xff1b; • as 后面是这…

【web]-反序列化-easy ? not easy

打开后看到源码 <?php error_reporting(0); highlight_file(__FILE__);class A{public $class;public $para;public $check;public function __construct(){$this->class "B";$this->para "ctfer";echo new $this->class ($this->para…

Kubernetes学习指南:保姆级实操手册03——规划部署

Kubernetes学习指南&#xff1a;保姆级实操手册03——规划部署 一、部署节点规划 Hostnameiprolesk8s-master0110.255.210.1masterk8s-master0210.255.210.2masterk8s-master0310.255.210.3masterk8s-node0110.255.210.4worker nodek8s-node0210.255.210.5worker nodek8s-nod…

【深度学习】LDA线性判别分析

date:2024/07/23 author:sion tag:Deeping Learn LDA(线性判别分析) 文章目录 LDA(线性判别分析)1.LDA是什么LDA是一种解决二分类问题的线性方法。它描述&#xff0c;对于给定样例集&#xff0c;将样例点投影到一条直线上&#xff0c;这条直线能使异样的样例相距远&#xff0c;…

为Jetson Xavier NX安装合适版本的pytorch(解决torch not compiled with cuda enabled)

Jetson Xavier NX 上我的环境是torch2.3.1 cuda 11.4 cuDNN8.4.1 sudo jtop和 nvcc -V都正常显示 有cuda11.4 环境变量路径也配置了 但是我print(“CUDA available:”, torch.cuda.is_available())输出为False 运行torch.cuda.current_device() 报错是torch not compiled wi…

【日常介绍】—pycharm2024.1变化

目录 一、性能提升 二、代码编辑与导航 三、重构与版本控制 四、调试与测试 五、集成工具与云服务 六、用户界面与体验 七、其他新特性 一、性能提升 项目加载时间优化&#xff1a;改进了项目索引机制&#xff0c;使得初次加载时间更快。代码分析引擎优化&#xff1a;提…

Linus: vim编辑器的使用,快捷键及配置等周边知识详解

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 vim的安装创建新用户 adduser 用户名Linus是个多用户的操作系统是否有创建用户的权限查看当前用户身份:whoami** 怎么创建设置密码passwdsudo提权(sudo输入的是用户…

Golang | Leetcode Golang题解之第275题H指数II

题目&#xff1a; 题解&#xff1a; func hIndex(citations []int) int {n : len(citations)return n - sort.Search(n, func(x int) bool { return citations[x] > n-x }) }

数驭未来,景联文科技构建高质大模型数据库

国内应用层面的需求推动AI产业的加速发展。根据IDC数据预测&#xff0c;预计2026年中国人工智能软件及应用市场规模会达到211亿美元。 数据、算法、算力是AI发展的驱动力&#xff0c;其中数据是AI发展的基石&#xff0c;中国的数据规模增长速度预期将领跑全球。 2024年《政府工…

go语言day15 goroutine

Golang-100-Days/Day16-20(Go语言基础进阶)/day17_Go语言并发Goroutine.md at master rubyhan1314/Golang-100-Days GitHub 第2讲-调度器的由来和分析_哔哩哔哩_bilibili 一个进程最多可以创建多少个线程&#xff1f;-CSDN博客 引入协程 go语言中内置了协程goroutine&#…