This commit is contained in:
Yudong
2014-04-15 00:50:42 +08:00
parent 086ab88a86
commit d0cfbe9ff2
2 changed files with 0 additions and 157 deletions

View File

@@ -1,89 +0,0 @@
_ = require 'underscore'
auth = require '../auth'
db = require '../db'
cAccount = db.collection 'accounts'
db.buildModel module.exports, cAccount
exports.register = (username, email, passwd, callback = null) ->
passwd_salt = auth.randomSalt()
exports.insert
username: username
passwd: auth.hashPasswd(passwd, passwd_salt)
passwd_salt: passwd_salt
email: email
signup: new Date()
group: []
setting: {}
attribure: {}
tokens: []
, {}, (result) ->
callback(result) if callback
# @param callback(token)
exports.createToken = (attribute, callback) ->
# @param callback(token)
generateToken = (callback) ->
token = auth.randomSalt()
exports.findOne
'tokens.token': token
, {}, (result) ->
if result
generateToken callback
else
callback token
generateToken (token) ->
exports.update
$push:
tokens:
token: token
available: true
created_at: new Date()
updated_at: new Date()
attribute: attribute
, {}, ->
callback token
exports.removeToken = (token, callback = null) ->
exports.update
$pull:
tokens:
token: token
, {}, ->
callback() if callback
exports.authenticate = (token, callback) ->
unless token
callback null
exports.findOne
'tokens.token': token
, {}, (result) ->
if result
callback result
else
callback null
exports.byUsername = db.buildByXXOO 'username', cAccount
exports.byEmail = db.buildByXXOO 'email', cAccount
exports.byUsernameOrEmail = (username, callback) ->
exports.byUsername username, (account) ->
if account
return callback account
exports.byEmail username, (account) ->
return callback account
# @return bool
exports.matchPasswd = (account, passwd) ->
return auth.hashPasswd(passwd, account.passwd_salt) == account.passwd
exports.inGroup = (account, group) ->
return group in account.group

View File

@@ -1,68 +0,0 @@
markdown = require('markdown').markdown
ObjectID = require('mongodb').ObjectID
_ = require 'underscore'
db = require '../db'
cTicket = db.collection 'tickets'
db.buildModel module.exports, cTicket
exports.createTicket = (account, title, content, type, members, attribute, callback) ->
membersID = []
for member in members
membersID.push member._id
exports.insert
account_id: account._id
created_at: new Date()
updated_at: new Date()
title: title
content: content
content_html: markdown.toHTML content
type: type
status: 'open'
members: membersID
attribute: attribute
replys: []
, {}, (ticket) ->
callback ticket
exports.createReply = (ticket, account, reply_to, content, callback) ->
if reply_to and _.isString reply_to
reply_to = new db.ObjectID reply_to
unless reply_to
reply_to = null
data =
_id: db.ObjectID()
reply_to: reply_to
account_id: account._id
created_at: new Date()
content: content
content_html: markdown.toHTML content
attribute: {}
exports.update _id: ticket._id,
$push:
replys: data
, ->
unless exports.hasMember ticket, account
exports.addMember ticket, account, ->
callback data
else
callback data
exports.addMember = (ticket, account, callback) ->
exports.update
$push:
members: account._id
, ->
callback()
exports.hasMember = (ticket, account) ->
if _.find(ticket.members, (member) -> member.equals(account._id))
return true
else
return false