diff --git a/app.coffee b/app.coffee
index 8489085..9655db6 100644
--- a/app.coffee
+++ b/app.coffee
@@ -1,4 +1,5 @@
connect = require 'connect'
+nodemailer = require 'nodemailer'
path = require 'path'
harp = require 'harp'
fs = require 'fs'
@@ -35,6 +36,8 @@ exports.run = ->
app.redis = redis.createClient 6379, '127.0.0.1',
auth_pass: config.redis_password
+ app.mailer = nodemailer.createTransport config.email.account
+
app.i18n = require './core/i18n'
app.utils = require './core/utils'
app.config = require '../config'
@@ -47,6 +50,7 @@ exports.run = ->
mAccount: require './model/account'
mBalanceLog: require './model/balance_log'
mCouponCode: require './model/coupon_code'
+ mNotification: require './model/notification'
mSecurityLog: require './model/security_log'
mTicket: require './model/tickets'
diff --git a/core/locale/zh_CN.json b/core/locale/zh_CN.json
index 3f4a24d..96f7690 100644
--- a/core/locale/zh_CN.json
+++ b/core/locale/zh_CN.json
@@ -61,6 +61,11 @@
"time": {
"day": "天"
},
+ "notification": {
+ "ticket_create": {
+ "title": "工单 | <%= title %>"
+ }
+ },
"view": {
"layout": {
"navigation": "展开导航"
diff --git a/core/model/account.coffee b/core/model/account.coffee
index a11f2ea..e79206a 100644
--- a/core/model/account.coffee
+++ b/core/model/account.coffee
@@ -162,15 +162,3 @@ exports.calcResourcesLimit = (plans) ->
limit[k] += v
return limit
-
-exports.sendEmail = (account, title, content) ->
- mailer = nodemailer.createTransport 'SMTP', config.email.account
-
- mail =
- from: config.email.send_from
- to: account.email
- subject: title
- html: content
-
- mailer.sendMail mail, (err) ->
- throw err if err
diff --git a/core/model/notification.coffee b/core/model/notification.coffee
index f8bbfc7..a50dbe9 100644
--- a/core/model/notification.coffee
+++ b/core/model/notification.coffee
@@ -2,9 +2,19 @@ module.exports = exports = app.db.collection 'notifications'
sample =
account_id: ObjectID()
+ group_name: 'root'
created_at: Date()
level: 'notice/event/log'
type: 'payment_success'
meta:
amount: 10
+exports.createNotice = (account, group_name, type, level, meta, callback) ->
+ exports.insert
+ account_id: account?._id ? null
+ group_name: group_name ? null
+ level: level
+ type: type
+ meta: meta
+ , (err, result) ->
+ callback _.first result
diff --git a/core/model/security_log.coffee b/core/model/security_log.coffee
index dc33fa2..a66eee6 100644
--- a/core/model/security_log.coffee
+++ b/core/model/security_log.coffee
@@ -4,13 +4,13 @@ sample =
account_id: new ObjectID()
type: 'update_password/update_setting/update_email'
created_at: new Date()
- payload:
- token:
- token: 'b535a6cec7b73a60c53673f434686e04972ccafddb2a5477f066f30eded55a9b'
- created_at: new Date()
- attribute:
- ip: '123.184.237.163'
- ua: 'Mozilla/5.0 (Intel Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102'
+ payload: {}
+ token:
+ token: 'b535a6cec7b73a60c53673f434686e04972ccafddb2a5477f066f30eded55a9b'
+ created_at: new Date()
+ attribute:
+ ip: '123.184.237.163'
+ ua: 'Mozilla/5.0 (Intel Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102'
exports.create = (account, type, token, payload, callback) ->
matched_token = _.first _.where account.tokens,
diff --git a/core/model/ticket.coffee b/core/model/ticket.coffee
index 8ed1ec0..0fe3791 100644
--- a/core/model/ticket.coffee
+++ b/core/model/ticket.coffee
@@ -81,10 +81,3 @@ exports.addMember = (ticket, account, callback) ->
exports.getMember = (ticket, account) ->
return _.find(ticket.members, (member) -> member.equals(account._id))
-
-exports.sendMailToAdmins = (title, content) ->
- mAccount.find
- group: 'root'
- .toArray (err, accounts) ->
- for account in accounts
- mAccount.sendEmail account, title, content
diff --git a/core/notification.coffee b/core/notification.coffee
index e60f118..5070006 100644
--- a/core/notification.coffee
+++ b/core/notification.coffee
@@ -1 +1,45 @@
-exports.createNotice = (account, level, notice, callback) ->
+{mAccount, mNotification} = app.models
+{i18n, config} = app
+
+{NOTICE, EVENT, LOG} = exports =
+ NOTICE: 'notice'
+ EVENT: 'event'
+ LOG: 'log'
+
+exports.notice_level =
+ ticket_create: NOTICE
+ ticket_reply: NOTICE
+ ticket_update: EVENT
+
+exports.createNotice = (account, type, notice, callback) ->
+ level = exports.notice_level[type]
+
+ mNotification.createNotice account, null, type, level, notice, (notification) ->
+ app.mailer.sendMail
+ from: config.email.send_from
+ to: account.email
+ subject: notice.title
+ html: notice.body
+ , ->
+ callback notification
+
+exports.createGroupNotice = (group, type, notice, callback) ->
+ level = exports.notice_level[type]
+
+ mNotification.createNotice null, group, type, level, notice, (notification) ->
+ unless level == NOTICE
+ callback notification
+
+ mAccount.find
+ group: 'root'
+ .toArray (err, accounts) ->
+ async.each accounts, (account, callback) ->
+ app.mailer.sendMail
+ from: config.email.send_from
+ to: account.email
+ subject: notice.title
+ html: notice.body
+ , ->
+ callback()
+ , ->
+ callback notification
diff --git a/core/template/ticket_create_email.html b/core/template/ticket_create_email.html
new file mode 100644
index 0000000..80fb543
--- /dev/null
+++ b/core/template/ticket_create_email.html
@@ -0,0 +1,6 @@
+<%= content_html %>
+
+
+
+<%= account.username %>
+<%= ticket._id %>
diff --git a/package.json b/package.json
index dada428..106e0ec 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,9 @@
{
"name": "rootpanel",
- "version": "0.7.2",
+ "version": "0.8.0",
"description": "A linux virtual host management system with extensibility",
"homepage": "http://rpvhost.net",
- "license": "GPL-3.0",
+ "license": "AGPL-3.0",
"repository": {
"type": "git",
"url": "https://github.com/jysperm/RootPanel.git"
@@ -25,21 +25,21 @@
"rp-clean": "./bin/rp-clean.coffee"
},
"dependencies": {
- "jade": "~1.3",
- "express": "~4.8.4",
- "coffee-script": "~1.7.1",
- "mongodb": "~1.4.8",
- "underscore": "~1.6.0",
- "markdown": "~0.5.0",
- "async": "~0.9.0",
- "connect": "~2.17.3",
+ "jade": "^1.3",
+ "express": "^4.8.4",
+ "coffee-script": "^1.7.1",
+ "mongodb": "^1.4.8",
+ "underscore": "^1.6.0",
+ "markdown": "^0.5.0",
+ "async": "^0.9.0",
+ "connect": "^2.17.3",
"harp": "~0.13.0",
- "middleware-injector": "~0.1.1",
- "tmp": "~0.0.24",
- "mysql": "~2.4.2",
- "moment-timezone": "~0.2.2",
- "request": "~2.40.0",
- "redis": "~0.12.1",
- "nodemailer": "~0.7.1"
+ "middleware-injector": "^0.1.1",
+ "tmp": "^0.0.24",
+ "mysql": "^2.4.2",
+ "moment-timezone": "^0.2.2",
+ "request": "^2.40.0",
+ "redis": "^0.12.1",
+ "nodemailer": "^1.2.1"
}
}