mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-03-29 22:20:30 +08:00
Merge branches 'master' and 'master' of https://github.com/jysperm/RootPanel
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
12
gulpfile.js
12
gulpfile.js
@@ -4,22 +4,20 @@ var coffee = require('gulp-coffee');
|
||||
var uglify = require('gulp-uglify');
|
||||
var path = require('path');
|
||||
|
||||
lessPath = './core/static/style';
|
||||
corePath = './core'
|
||||
|
||||
gulp.task('less', function() {
|
||||
return gulp.src(lessPath + "/**/*.less").pipe(less()).pipe(gulp.dest(lessPath));
|
||||
return gulp.src(['./**/*.less','!node_modules/**/*.less']).pipe(less()).pipe(gulp.dest('./'));
|
||||
});
|
||||
|
||||
gulp.task('coffee', function() {
|
||||
return gulp.src(corePath + "/**/**/**/*.coffee").pipe(coffee({bare:true})).on('error', function(error) {
|
||||
return gulp.src(['./**/*.coffee','!node_modules/**/*.coffee']).pipe(coffee({bare:true})).on('error', function(error) {
|
||||
throw error;
|
||||
}).pipe(uglify()).pipe(gulp.dest(corePath));
|
||||
}).pipe(uglify()).pipe(gulp.dest('./'));
|
||||
});
|
||||
|
||||
gulp.task('watch', function(){
|
||||
gulp.watch(corePath + "/**/**/**/*.coffee",['coffee']);
|
||||
gulp.watch(lessPath + "/**/*.less",['less']);
|
||||
gulp.watch([ './**/*.coffee','!node_modules/**/*.coffee'],['coffee']);
|
||||
gulp.watch(['./**/*.less','!node_modules/**/*.less'],['less']);
|
||||
});
|
||||
|
||||
gulp.task('default', ['less', 'coffee', 'watch']);
|
||||
|
||||
Reference in New Issue
Block a user