Skip to content

Commit

Permalink
第二周作业
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkong2023 committed Mar 18, 2016
1 parent bb3d88d commit 5baa823
Show file tree
Hide file tree
Showing 11 changed files with 2,323 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 练习/闫宇韬/第二周作业/reg/.project
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>
62 changes: 62 additions & 0 deletions 练习/闫宇韬/第二周作业/reg/index.js
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);
17 changes: 17 additions & 0 deletions 练习/闫宇韬/第二周作业/reg/package.json
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"
}
}
Loading

0 comments on commit 5baa823

Please sign in to comment.