前言:

刚接手cms3.0的工作,似乎对一切都那么的不熟悉,于是在开始新需求之前,先做一个简单的登录系统。

项目目录:

1.使用webstroms建expreess项目,非常方便简单,建好的项目目录就是这样子的:

   ;

/bin: 用于应用启动

/public: 静态资源目录

/routes:可以认为是controller(控制器)目录

/views: jade/ejs/html模板目录,可以认为是view(视图)目录

app.js 程序main文件

2.在文件夹bin下面找www,右键单击Run 'bin\www',即可看到控制台输出“server Listening on port 3000 +0ms”,然后在浏览器输入“localhost:3000”就可以看见页面上“Hello Express”的字样;

3.在建项目之初,选用的模板是ejs或者jade,在这里为了方便,我们需要把模板改成常用的,挑一种来说,这是修改app.js文件中的代码:

...
var app = express();// view engine setup
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'jade');// 设置模板引擎从jade为html
// view engine setup
app.set('views', path.join(__dirname, 'views'));
var template = require('arttemplate-gg');
template.config('base', '');
template.config('extname', '.html');
app.engine('.html', template.__express);
app.set('view engine', 'html');
...

最后还需要吧views文件夹底下的页面全部修改成.html结束的文件。这样基本的框架才搭建出来了;

4.项目中所需的静态文件,比如jQuery、图片、插件、样式文件统一放在public对应的文件夹底下;

5.在views文件夹底下总共建4个页面:

①err.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title></title>
</head>
<body><h1>{{message}}</h1>
<h2> {{error.status}}</h2>
<pre>{{error.stack}}</pre></body>
</html>

②home.html

<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>欢迎登录@@@@@@@@@@</title>
</head>
<body>
欢迎登录
</body>
</html>

③index.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><link href="/public/stylesheets/bootstrap.min.css" rel="stylesheet" media="screen"><title></title>
</head>
<body>
<p>我是index页面~~~</p>
<script src="/public/javascripts/jquery.min.js"></script>
<script src="/public/javascripts/bootstrap.min.js"></script>
</body>
</html>

④login.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>用户登录</title><style>*{ margin:0px; padding:0px; list-style:none;}body,html{ height:100%;font:12px/1.5 \5FAE\8F6F\96C5\9ED1,tahoma,arial,sans-serif;}html{ background:url(/images/bg.png) repeat-x;}body{ background:url(/images/ftbg.png) 0 bottom repeat-x;}.main{ background:url(/images/mbg.png) no-repeat center bottom;position: absolute;width:100%;height:500px;top:50%;margin-left:0;margin-top:-290px; z-index:99}.loginbox{ width:410px;  height:375px;background:url(/images/borderbg.png); position: absolute; left:50%; top:50%; margin-left:-200px; margin-top:-200px; border-radius:8px;-moz-border-radius: 8px; -webkit-border-radius:8px; z-index:999;}.loginbg{ width:310px;padding:40px; margin:0 auto; margin-top:10px; background-color:#fff; border-radius:8px;-moz-border-radius: 8px; -webkit-border-radius:8px;}.loginbox h3{ font-size:18px; font-weight:normal; color:#333; padding-bottom:15px; text-align:center;}.loginbox input{ width:260px; height:46px; border:1px solid #dbdbdb; padding:0 5px; font-size:14px; color:#666;border-radius:5px rgba(0,0,0,0.5);-moz-border-radius: 5px; -webkit-border-radius:5px; padding-left:45px; line-height:46px;}.loginbox ul li{ padding:15px 0; position:relative;}.loginbox .user{ background:url(/images/lgicon.png) 0 0 no-repeat; display:inline-block; position:absolute; width:19px; height:20px; left:15px; top:27px;}.loginbox .pwd{ background:url(/images/lgicon.png) 0 bottom no-repeat; display:inline-block; position:absolute; width:19px; height:22px; left:15px; top:27px;}.loginbox input.lgbtn{ width:312px; background-color:#f86c6b; border:0px; color:#fff; font-size:18px; font-family:\5FAE\8F6F\96C5\9ED1;line-height:46px; text-align:center; cursor:pointer; text-indent:0px; padding:0px;}.main h2{ margin-top:-40px; font-size:30px; text-align:center; color:#fff; font-weight:normal;}.footer{ position:fixed; z-index:9; bottom:0px; text-align:center; color:#666; width:100%; padding-bottom:20px; font-size:14px;}</style>
</head>
<body>
<div class="main"><h2>小小登录窗口</h2><div class="loginbox"><div class="loginbg"><h3>测试登录</h3><form id="fm" action="/" method="post"><ul><li><span class="user" ></span><input type="text" id="username" name="username"  value=""></li><li><span class="pwd" ></span><input type="password" id="password" name="password" required="true" value=""><span style="color: red;position: absolute;top: 70px;left: 10px" id="msg">{{msg}}</span></li><li><input type="submit" value="登录" class="lgbtn"/></li></ul></form></div></div>
</div>
<div class="footer">Come on 测试一下~~~</div>
<script type="text/javascript" src="/plugin/jquery-easyui-1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="/plugin/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/plugin/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
</body>
</html>

6.所对应的js文件——routes底下的index.js

/*** created 2016-11-01* */var express = require('express');
var router = express.Router();/* GET home page. */
router.get('/', function (req, res, next) {res.render('login', {title: 'Express'});
});
// 自定义方法
router.post('/', function (req, res, next) {var username = req.body.username;var password = req.body.password;var user={username:'admin',password:'admin'};if(username == user.username && password == user.password){console.log("验证正确");res.render('home', {title: 'Express'});} else {console.log("验证失败");res.render('login', {msg: '用户名或密码错误!'});}
});module.exports = router;

最终的效果就是:

7.由于js中定义了账号和密码都为admin,因此只有输入值为admin时,才可以跳转到

如左图的页面,否则就是

提示的错误信息~

CMS3.0——初次邂逅express相关推荐

  1. vue 多选自动触发_Vue,初次邂逅(二)

    一.前言 二.Vue常用指令 2.1 什么是指令? 指令 (Directives) 是带有 v- 前缀的特殊特性.指令特性的预期值是:单个 JavaScript 表达式.指令的职责是,当表达式的值改变 ...

  2. ASP.NET 2.0与SQL Express 2005在迁移到Windows 2003时发生数据库为只读的错误

    ASP.NET 2.0和SQL Server Express 2005结合进行网站开发时,在VS 2005中运行时没有任何问题.当网站发布在Win Server 2003时,就会出现数据库无法访问的错 ...

  3. PCIe 6.0 – 关于 PCI Express Gen6 您需要知道的一切

    PCI Express ®  6.0 (PCIe ® 6.0) 规范由 PCI-SIG ®于 2022 年 1 月发布.最新一代的无处不在的 PCIe 标准带来了许多令人兴奋的新功能,旨在提高计算性能 ...

  4. 显卡接口标准:支持PCI Express 2.0和 PCI Express 16X 有何差别

    [D300科普]PCI-E 16x,PCI-E2.0,还是PCI-E 2.0 16x? 为了普及一下显卡接口的知识,不求虚假的精华虚名,只为帮助需要帮助之人~ 说明一下吧 PCIE 1x  是最基本的 ...

  5. 深度学习炼丹术 —— 与神经网络的初次邂逅:熟悉基本结构、设计和实现

    在正式介绍神经网络之前,我们先对上篇文章中的感知器内容做个简短的回顾: 我们首先介绍了什么是感知器,直观上看到了感知器的基本结构以及能做些什么.其次,通过感知器详细讲解了与门的实现原理,并通过数学公式 ...

  6. android opengl es 2.0 编程指南,Android OpenGL ES 2.0 初次体验

    本文目录 一. OpenGL ES是什么? 二. OpenGL ES的版本 三. EGL是什么? 四. 需要知道的两个方法 五. 在Android中使用OpenGL ES的步骤 六. 例子1:简单的程 ...

  7. 与JSP的初次邂逅……

    JSP是可以内嵌在网页中,由服务器端来执行与解释的程序,是一种动态网页技术标准. 在传统的HTML文件(*.htm或*.html)中加入Java程序片段和JSP标记,就构成了JSP网页(*.jsp). ...

  8. SpiderFlow平台v0.3.0初次使用并爬取薄荷网的热量和减法功效

    spider-flow 作为web爬虫他可以简单的说是新一代的爬虫平台,以图形化方式定义爬虫流程,不写代码即可完成爬虫. 也就是说我们不用在刻意的为了一些数据就去学一下语言如python,我们只要画个 ...

  9. python卡路里程序_SpiderFlow平台v0.3.0初次使用并爬取薄荷网的热量和减法功效

    spider-flow 作为web爬虫他可以简单的说是新一代的爬虫平台,以图形化方式定义爬虫流程,不写代码即可完成爬虫. 也就是说我们不用在刻意的为了一些数据就去学一下语言如python,我们只要画个 ...

  10. 给定一个只由 0、1、、|和^五种字符组成的字符串express,再给定一个布尔值 desired。返回express能有多少种组合方式,可以达到desired的结果。

    问题描述: 给定一个只由 0(假).1(真).&(逻辑与).|(逻辑或)和^(异或)五种字符组成的字符串express,再给定一个布尔值 desired.返回express能有多少种组合方式, ...

最新文章

  1. 抠图+修图+调色+合成+特效Photoshop核心应用5项修炼pdf
  2. axios请求GBK页面中文乱码解决方法
  3. agv机器人托举结构_AGV机器人常见减震浮动结构对比分析
  4. boost::mp11::mp_set_push_back相关用法的测试程序
  5. “人肉”背后隐藏的网络风险
  6. C# Socket编程笔记(转)
  7. ASP.NET Core Cookie SameSite
  8. CSRF的绕过与利用
  9. 脑子越来越不好使,文字越来越像驮shi
  10. QT中的MessageBox设置自动关闭退出
  11. QT5 QSqlQuery的SELECT INSERT UPDATE DELETE命令用法
  12. 如何使用JavaScript控制台:超越console.log()
  13. 【报告分享】罗兰贝格2019年关于人工智能的十个议题.pdf(附下载链接)
  14. C什么k什么_K线基础——什么是MACD?
  15. pe下查看ip和计算机名称,利用U盘pe系统查找原来电脑ip
  16. js中Error对象
  17. 刚刚创下新高的苹果再度自傲,iPhone14提价必将遭受挫败
  18. 基于网页版微信实现的微信SDK(Kotlin版,兼容Java)
  19. LVS负载均衡群集——NAT地址转换
  20. w10系统服务器如何创建新用户,win10添加新用户的方法分享

热门文章

  1. Android TV开发总结(二)构建一个TV Metro界面(仿泰捷视频TV版)
  2. arsc编辑器手机版_APK编辑器中文版,任意修改你手机中的APP名称、logo!
  3. 怎么调节手机的刷新率_【W21 5G性能篇】120Hz自适应刷新率,用了再也回不去
  4. python 贴吧调度器_简单的Python调度器Schedule详解
  5. php invoke 反射,PHP ReflectionMethod invoke()用法及代码示例
  6. 如何调整帆软件按钮的样式
  7. python安装mysql模块_Python:使用pip安装MySQL-python模块
  8. 信息熵、互信息、KL散度
  9. 如何理解JavaScript用三角函数计算鼠标与多个目标点的距离
  10. 修改他人代码:怎么才能减少发布Bug概率?