This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
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
Showing
84 changed files
with
157,928 additions
and
6 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
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,10 @@ | ||
language: node_js | ||
node_js: | ||
- 0.12 | ||
- 0.11 | ||
- 0.10 | ||
install: | ||
- "npm install -g mocha should" | ||
- "npm install" | ||
script: | ||
- "mocha" |
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 |
---|---|---|
@@ -1,14 +1,36 @@ | ||
WiAuth-Backend | ||
Rap-ID.server.js | ||
===== | ||
|
||
概述 | ||
An server implyment for Rap-ID in Node.js. | ||
|
||
Usage | ||
----- | ||
|
||
主项目:[WiAuth](https://github.com/WiAuth/WiAuth) | ||
Just use the npm to start the program. | ||
|
||
``` | ||
npm install&& npm start | ||
``` | ||
|
||
And if you want to do unit tests, you may use this: | ||
|
||
``` | ||
npm test | ||
``` | ||
|
||
在日常生活中,互联网用户需要面对大量授权登录场景,已有的方式大多需要用户交互验证或者额外的硬件。眼下,国家网络实名制进程正在逐步推进,找到一种廉价而有效的方式迫在眉睫。因此,我们提出了一种既快速又安全,同时可以解决实名制的身份认证算法。本算法依靠局域网通信,以手机作为硬件令牌,使用token传递机制,使用户只需点击按钮即可完成授权操作。此外,其利用滚动密钥机制和DES加密算法,及配对口令体系,保障了较高的安全性。同时利用手机号开户时录入的实名信息,通过SIM卡ICCID查询,实现实名验证和登录保护。本算法实现了较好的用户体验、安全保障以及实名制解决方案。当下,智能手机与家庭局域网络已经十分普及,此算法的推广容易被用户接受。同时,算法提供了API接口以及SDK,为第三方软件使用此算法提供了可行的方案,具有较好的普适性和可移植性。本算法可应用在网络登陆、实名安全支付和网吧实名登记等场景中。 | ||
However, we use `mocha` for unit testing, so you may install it via npm: | ||
|
||
作者 | ||
``` | ||
npm install mocha -g | ||
``` | ||
|
||
License | ||
----- | ||
|
||
- [@coderfox](https://github.com/coderfox) (Yuze Fu,傅禹泽)<[email protected]> | ||
MIT License. | ||
|
||
(c)2015 coderfox(Yuze Fu,傅禹泽)<[email protected]> | ||
|
||
``` | ||
My name is Yuze Fu. I assign my copyrights of all the things contributed to this repo to the project Rap-ID. | ||
``` |
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,154 @@ | ||
// global object | ||
global.r = {}; | ||
// get config | ||
r.c = function(name) { | ||
var config = require('config'); | ||
return config.get(name); | ||
}; | ||
var _log = require('log'); | ||
// log | ||
r.l = new _log(r.c('log.level')); | ||
r.l.info('Logging level ' + r.c('log.level')); | ||
// mysql | ||
var mysql = require('aa-mysql'); | ||
mysql.config({ | ||
host: r.c('database.host'), | ||
port: r.c('database.port'), | ||
user: r.c('database.user'), | ||
pass: r.c('database.pass'), | ||
db: r.c('database.db') | ||
}); | ||
// dump mysql | ||
r.l.info('Connecting database on ' + | ||
r.c('database.host') + ':' + | ||
r.c('database.port')); | ||
r.d = mysql.createPool(); | ||
// ok result for api | ||
r.aok = function(data) { | ||
return { | ||
data: data, | ||
error: { | ||
id: 0, | ||
msg: "ok" | ||
} | ||
}; | ||
} | ||
// error object | ||
r.e = function(msg, id, status, stack) { | ||
this.message = msg; | ||
this.id = id; | ||
this.status = status; | ||
this.stack = stack; | ||
} | ||
// dump env | ||
r.l.info('Server env: ' + r.c('server.env')); | ||
|
||
var express = require('express'); | ||
var path = require('path'); | ||
var favicon = require('serve-favicon'); | ||
var logger = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
|
||
// express app | ||
var app = express(); | ||
|
||
// view engine setup | ||
var hbs = require('hbs'); | ||
// register partials | ||
hbs.registerPartials(__dirname + '/views/partials'); | ||
app.set('views', path.join(__dirname, 'views')); | ||
// use handlebars | ||
app.set('view engine', 'hbs'); | ||
|
||
app.use(logger('dev')); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ | ||
extended: false | ||
})); | ||
app.use(cookieParser()); | ||
// use middleware for /public | ||
app.use(express.static(path.join(__dirname, '/public'))); | ||
|
||
// routes | ||
var mainRoutes = require('./routes/main'); | ||
var apiRoutes = require('./routes/api'); | ||
var demoRoutes = require('./routes/demo'); | ||
// use routes | ||
app.use('/', mainRoutes); | ||
app.use('/api', apiRoutes); | ||
app.use('/demo',demoRoutes); | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
|
||
// error handlers | ||
if (r.c('server.env') === 'debug') { | ||
app.use('/api', function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.json({ | ||
error: { | ||
id: err.id || err.status, | ||
msg: err.message, | ||
stack: err.stack | ||
} | ||
}); | ||
}); | ||
app.use('/demo', function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
code: err.status, | ||
stack: err.stack, | ||
title: err.status + ' - ' + err.message, | ||
banner: r.c('content.demo.banner'), | ||
home_title: r.c('site.demo') | ||
}); | ||
}); | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
code: err.status, | ||
stack: err.stack, | ||
title: err.status + ' - ' + err.message, | ||
banner: r.c('content.front.banner'), | ||
home_title: r.c('site.front') | ||
}); | ||
}); | ||
} | ||
app.use('/api', function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.json({ | ||
error: { | ||
id: err.id || err.status, | ||
msg: err.message | ||
} | ||
}); | ||
}); | ||
app.use('/demo', function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
code: err.status, | ||
title: err.status + ' - ' + err.message, | ||
banner: r.c('content.demo.banner'), | ||
home_title: r.c('site.demo') | ||
}); | ||
}); | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
code: err.status, | ||
title: err.status + ' - ' + err.message, | ||
banner: r.c('content.front.banner'), | ||
home_title: r.c('site.front') | ||
}); | ||
}); | ||
|
||
module.exports = app; |
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,107 @@ | ||
-- phpMyAdmin SQL Dump | ||
-- version 4.4.2 | ||
-- http://www.phpmyadmin.net | ||
-- | ||
-- Host: localhost | ||
-- Generation Time: 2015-05-02 10:26:36 | ||
-- 服务器版本: 5.6.24 | ||
-- PHP Version: 5.6.5 | ||
|
||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | ||
SET time_zone = "+00:00"; | ||
|
||
-- | ||
-- Database: `rapid` | ||
-- | ||
|
||
-- -------------------------------------------------------- | ||
|
||
-- | ||
-- 表的结构 `identity` | ||
-- | ||
|
||
CREATE TABLE IF NOT EXISTS `identity` ( | ||
`id` int(11) NOT NULL, | ||
`data` text NOT NULL, | ||
`iccid` varchar(50) NOT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
-- -------------------------------------------------------- | ||
|
||
-- | ||
-- 表的结构 `releases` | ||
-- | ||
|
||
CREATE TABLE IF NOT EXISTS `releases` ( | ||
`id` int(11) NOT NULL, | ||
`name` varchar(200) NOT NULL, | ||
`data` text NOT NULL, | ||
`version` int(11) NOT NULL, | ||
`time` int(11) NOT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
-- | ||
-- 转存表中的数据 `releases` | ||
-- | ||
|
||
INSERT INTO `releases` (`id`, `name`, `data`, `version`, `time`) VALUES | ||
(1, 'v1.0', '{"color":"warning","note":"debug","packs":[{"name":"win","link":"http://baidu.com","color":"material-orange"}]}', 1, 1430560595), | ||
(2, 'v1.0', '{"color":"success","note":"debug","packs":[{"name":"win","link":"http://baidu.com","color":"material-orange"},{"name":"android","link":"http://google.com","color":"material-blue"}]}', 2, 1430560600); | ||
|
||
-- -------------------------------------------------------- | ||
|
||
-- | ||
-- 表的结构 `token` | ||
-- | ||
|
||
CREATE TABLE IF NOT EXISTS `token` ( | ||
`id` int(11) NOT NULL, | ||
`token` varchar(32) NOT NULL, | ||
`uid` int(11) NOT NULL, | ||
`iccid` varchar(50) NOT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
-- -------------------------------------------------------- | ||
|
||
-- | ||
-- 表的结构 `user` | ||
-- | ||
|
||
CREATE TABLE IF NOT EXISTS `user` ( | ||
`id` int(11) NOT NULL, | ||
`name` varchar(50) NOT NULL, | ||
`pass` varchar(32) NOT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
-- | ||
-- Indexes for dumped tables | ||
-- | ||
|
||
-- | ||
-- Indexes for table `identity` | ||
-- | ||
ALTER TABLE `identity` | ||
ADD PRIMARY KEY (`id`), | ||
ADD UNIQUE KEY `iccid` (`iccid`); | ||
|
||
-- | ||
-- Indexes for table `releases` | ||
-- | ||
ALTER TABLE `releases` | ||
ADD PRIMARY KEY (`id`), | ||
ADD UNIQUE KEY `id` (`id`), | ||
ADD UNIQUE KEY `version` (`version`); | ||
|
||
-- | ||
-- Indexes for table `token` | ||
-- | ||
ALTER TABLE `token` | ||
ADD PRIMARY KEY (`id`), | ||
ADD UNIQUE KEY `token` (`token`); | ||
|
||
-- | ||
-- Indexes for table `user` | ||
-- | ||
ALTER TABLE `user` | ||
ADD PRIMARY KEY (`id`), | ||
ADD UNIQUE KEY `name` (`name`); |
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,63 @@ | ||
#!/usr/bin/env node | ||
|
||
module.exports = function() { | ||
var app = require('../app'); | ||
var debug = require('debug')('Rap-ID.server.js:server'); | ||
var http = require('http'); | ||
var config = require('config'); | ||
var _log = require('log'), | ||
log = new _log(config.get('log.level')); | ||
|
||
var port = normalizePort(config.get('server.port')); | ||
app.set('port', port); | ||
|
||
var server = http.createServer(app); | ||
|
||
server.listen(port); | ||
server.on('error', onError); | ||
server.on('listening', onListening); | ||
|
||
function normalizePort(val) { | ||
var port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
console.error(bind + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error(bind + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
function onListening() { | ||
var addr = server.address(); | ||
var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; | ||
log.info('Listening on ' + bind); | ||
} | ||
} | ||
|
||
module.exports(); |
Oops, something went wrong.