refactor config about billing

This commit is contained in:
jysperm
2014-09-07 23:08:58 +08:00
parent 9735bb31da
commit f9ec76d763
9 changed files with 26 additions and 23 deletions

View File

@@ -41,7 +41,7 @@ exports.run = ->
app.package = require './package.json'
app.pluggable = require './core/pluggable'
app.middleware = require './core/middleware'
app.token_manager = require './core/token_manager'
app.authenticator = require './core/authenticator'
app.models =
mAccount: require './model/account'

View File

@@ -38,7 +38,7 @@ service supervisor restart
bitcoin_secret = crypto.createHash('sha256').update(crypto.randomBytes(256)).digest('hex')
bitcoin.genAddress bitcoin_secret, (address) ->
mAccount.update _id: account._id,
mAccount.update {_id: account._id},
$set:
'attribute.bitcoin_deposit_address': address
'bitcoin_secret': bitcoin_secret

View File

@@ -15,7 +15,7 @@ exports.generateAvailableToken = (callback) ->
# @param callback(token)
exports.createToken = (account, type, payload, callback) ->
exports.generateAvailableToken (token) ->
exports.update _id: account._id,
exports.update {_id: account._id},
$push:
tokens:
type: type

View File

@@ -25,9 +25,11 @@ sample =
services: ['shadowsocks']
plans: ['all']
last_billing_at:
all: new Date()
balance: 100
last_billing_at: Date()
arrears_at: Date()
arrears_at: new Date()
pluggable:
bitcoin:
@@ -83,7 +85,7 @@ exports.register = (account, callback) ->
plans: []
balance: 0
last_billing_at: Date()
last_billing_at: {}
arrears_at: null
pluggable: {}
@@ -101,7 +103,7 @@ exports.register = (account, callback) ->
exports.updatePassword = (account, password, callback) ->
password_salt = utils.randomSalt()
exports.update _id: account._id,
exports.update {_id: account._id},
$set:
password: utils.hashPassword password, password_salt
password_salt: password_salt
@@ -127,7 +129,7 @@ exports.inGroup = (account, group) ->
exports.joinPlan = (account, plan, callback) ->
account.attribute.plans.push plan
exports.update _id: account._id,
exports.update {_id: account._id},
$addToSet:
'attribute.plans': plan
$set:
@@ -136,7 +138,7 @@ exports.joinPlan = (account, plan, callback) ->
exports.leavePlan = (account, plan, callback) ->
account.attribute.plans = _.reject account.attribute.plans, (i) -> i == plan
exports.update _id: account._id,
exports.update {_id: account._id},
$pull:
'attribute.plans': plan
$set:
@@ -144,7 +146,7 @@ exports.leavePlan = (account, plan, callback) ->
, callback
exports.incBalance = (account, type, amount, attribute, callback) ->
exports.update _id: account._id,
exports.update {_id: account._id},
$inc:
'attribute.balance': amount
, ->

View File

@@ -30,7 +30,7 @@ exports.codeMessage = (coupon_code) ->
return exports.type_meta[coupon_code.type].message coupon_code
exports.applyCode = (account, coupon_code, callback) ->
exports.update _id: coupon_code._id,
exports.update {_id: coupon_code._id},
$inc:
available_times: -1
$push:

View File

@@ -56,7 +56,7 @@ exports.createReply = (ticket, account, content, status, callback) ->
content_html: markdown.toHTML content
payload: {}
exports.update _id: ticket._id,
exports.update {_id: ticket._id},
$push:
replies: data
$set:
@@ -70,7 +70,7 @@ exports.createReply = (ticket, account, content, status, callback) ->
callback null, data
exports.addMember = (ticket, account, callback) ->
exports.update _id: ticket._id,
exports.update {_id: ticket._id},
$push:
members: account._id
$set:

View File

@@ -1,6 +1,6 @@
{renderAccount, errorHandling, requireAuthenticate} = app.middleware
{mAccount, mSecurityLog, mCouponCode} = app.models
{pluggable, config, utils, token_manager} = app
{pluggable, config, utils, authenticator} = app
module.exports = exports = express.Router()
@@ -57,7 +57,7 @@ exports.post '/register', errorHandling, (req, res) ->
return if err
mAccount.register _.pick(req.body, 'username', 'email', 'password'), (err, account) ->
token_manager.createToken account,
authenticator.createToken account,
ip: req.headers['x-real-ip']
ua: req.headers['user-agent']
, (token)->
@@ -75,7 +75,7 @@ exports.post '/login', errorHandling, (req, res) ->
unless mAccount.matchPassword account, req.body.password
return res.error 'wrong_password'
token_manager.createToken account,
authenticator.createToken account,
ip: req.headers['x-real-ip']
ua: req.headers['user-agent']
, (err, token) ->
@@ -87,7 +87,7 @@ exports.post '/login', errorHandling, (req, res) ->
token: token
exports.post '/logout', requireAuthenticate, (req, res) ->
token_manager.remokeToken req.token,
authenticator.remokeToken req.token,
revoke_at: new Date()
revoke_ip: req.headers['x-real-ip']
revoke_ua: req.headers['user-agent']
@@ -118,7 +118,7 @@ exports.post '/update_email', requireAuthenticate, (req, res) ->
unless utils.rx.email.test req.body.email
return res.error 'invalid_email'
mAccount.update _id: req.account._id,
mAccount.update {_id: req.account._id},
$set:
email: req.body.email
, ->

View File

@@ -175,7 +175,7 @@ exports.post '/update', requireAuthenticate, (req, res) ->
async.parallel [
(callback) ->
unless _.isEmpty modifier
mTicket.update _id: ticket._id,
mTicket.update {_id: ticket._id},
$set: modifier
, callback
else
@@ -183,7 +183,7 @@ exports.post '/update', requireAuthenticate, (req, res) ->
(callback) ->
unless _.isEmpty addToSetModifier
mTicket.update _id: ticket._id,
mTicket.update {_id: ticket._id},
$addToSet:
members:
$each: addToSetModifier
@@ -193,7 +193,7 @@ exports.post '/update', requireAuthenticate, (req, res) ->
(callback) ->
unless _.isEmpty pullModifier
mTicket.update _id: ticket._id,
mTicket.update {_id: ticket._id},
$pullAll:
members: pullModifier
, callback

View File

@@ -24,8 +24,7 @@ module.exports =
when_balance_below: 0
when_arrears_above: 0
cyclical_billing: 3600 * 1000
daily_billing_cycle: 24 * 3600 * 1000
billing_cycle: 10 * 60 * 1000
plans:
sample:
@@ -34,6 +33,8 @@ module.exports =
billing_by_time:
unit: 3600 * 1000
min_billing_unit: 24
price: 10 / (30 * 24)
services: []