forked from zhufengnodejs/201601node_homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb3d88d
commit 5baa823
Showing
11 changed files
with
2,323 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>reg</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>com.aptana.ide.core.unifiedBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>com.aptana.projects.webnature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var express = require('express'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var app = express(); | ||
var bodyParser = require('body-parser'); | ||
|
||
|
||
//定义一个用户数据 | ||
var userdata= []; | ||
|
||
//读取静态文件 | ||
app.use(express.static(__dirname+'/views')); | ||
|
||
app.use(bodyParser.urlencoded({extended:true})); | ||
|
||
|
||
//配置模板引擎 | ||
app.set('view engine','ejs'); | ||
|
||
//指定模板存放的目录 | ||
app.set('views',path.resolve('views')); | ||
|
||
app.get('/',function(req,res){ | ||
res.render('index.ejs',{title:'首页',books:{ | ||
name:'node.js' | ||
}}); | ||
}); | ||
|
||
app.get('/index.html',function(req,res){ | ||
res.render('index.ejs',{title:'首页',books:{ | ||
name:'node.js' | ||
}}); | ||
}); | ||
|
||
app.post('/reg.html',function(req,res){ | ||
userdata.push(req.body) | ||
res.end('{"msg":"注册成功,请登录!"}'); | ||
|
||
}); | ||
|
||
app.post('/login.html',function(req,res){ | ||
console.log(req.body) | ||
console.log(userdata) | ||
if(userdata.length > 0){ | ||
for(var i=0;i<userdata.length;i++){ | ||
console.log(userdata[i].name); | ||
console.log(req.body.name); | ||
console.log(userdata[i].password); | ||
console.log(req.body.password); | ||
if((userdata[i].name == req.body.name) && (userdata[i].password == req.body.password)){ | ||
res.end('{"msg":"恭喜你,登录成功"}'); | ||
}else{ | ||
res.end('{"msg":"登录失败,请重新登录!"}'); | ||
} | ||
} | ||
}else{ | ||
res.end('{"msg":"登录失败,请重新登录!"}'); | ||
} | ||
|
||
}); | ||
|
||
app.listen(8080); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "mkui", | ||
"version": "1.0.1", | ||
"description": "mkui", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "#" | ||
}, | ||
"keywords": [ | ||
"mkui" | ||
], | ||
"author": "mkui", | ||
"license": "MIT", | ||
"dependencies": { | ||
"express": "^4.13.4" | ||
} | ||
} |
Oops, something went wrong.