mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-01-13 07:01:20 +08:00
notification
This commit is contained in:
@@ -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'
|
||||
|
||||
|
||||
@@ -61,6 +61,11 @@
|
||||
"time": {
|
||||
"day": "天"
|
||||
},
|
||||
"notification": {
|
||||
"ticket_create": {
|
||||
"title": "工单 | <%= title %>"
|
||||
}
|
||||
},
|
||||
"view": {
|
||||
"layout": {
|
||||
"navigation": "展开导航"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
6
core/template/ticket_create_email.html
Normal file
6
core/template/ticket_create_email.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<%= content_html %>
|
||||
|
||||
<br /><br />
|
||||
|
||||
<%= account.username %>
|
||||
<a href='<%= config.web.url %>/ticket/view/?id=<%= ticket._id %>'><%= ticket._id %></a>
|
||||
34
package.json
34
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"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user