mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-29 03:55:42 +08:00
修改邮箱
This commit is contained in:
@@ -2,7 +2,7 @@ module.exports = exports = app.db.buildModel 'security_log'
|
||||
|
||||
sample =
|
||||
account_id: new ObjectID()
|
||||
type: 'update_password'
|
||||
type: 'update_password/update_setting/update_email'
|
||||
created_at: new Date()
|
||||
attribute:
|
||||
token:
|
||||
|
||||
@@ -89,6 +89,27 @@ exports.post '/update_password', requireAuthenticate, (req, res) ->
|
||||
, ->
|
||||
res.json {}
|
||||
|
||||
exports.post '/update_email', requireAuthenticate, (req, res) ->
|
||||
unless mAccount.matchPassword req.account, req.body.password
|
||||
return res.error 'wrong_password'
|
||||
|
||||
unless utils.rx.email.test req.body.email
|
||||
return res.error 'invalid_email'
|
||||
|
||||
mAccount.update _id: req.account._id,
|
||||
$set:
|
||||
email: req.body.email
|
||||
, ->
|
||||
token = _.first _.where req.account.tokens,
|
||||
token: req.token
|
||||
|
||||
mSecurityLog.create req.account, 'update_email',
|
||||
old_email: req.account.email
|
||||
email: req.body.email
|
||||
token: _.omit(token, 'updated_at')
|
||||
, ->
|
||||
res.json {}
|
||||
|
||||
exports.post '/update_setting', requireAuthenticate, (req, res) ->
|
||||
unless req.body.name in ['qq']
|
||||
return res.error 'invalid_name'
|
||||
@@ -99,4 +120,13 @@ exports.post '/update_setting', requireAuthenticate, (req, res) ->
|
||||
modifiers.$set["setting.#{req.body.name}"] = req.body.value
|
||||
|
||||
mAccount.update _id: req.account._id, modifiers, ->
|
||||
res.json {}
|
||||
token = _.first _.where req.account.tokens,
|
||||
token: req.token
|
||||
|
||||
mSecurityLog.create req.account, 'update_setting',
|
||||
name: req.body.name
|
||||
old_value: req.account.setting[req.body.name]
|
||||
value: req.body.value
|
||||
token: _.omit(token, 'updated_at')
|
||||
, ->
|
||||
res.json {}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
$ ->
|
||||
$('.action-update-password').click ->
|
||||
if $(':input[name=password]').val() != $(':input[name=password2]').val()
|
||||
if $('.form-password :input[name=password]').val() != $('.form-password :input[name=password2]').val()
|
||||
return alert 'Two password is not equal'
|
||||
|
||||
$.post '/account/update_password/', JSON.stringify
|
||||
old_password : $(':input[name=old_password]').val()
|
||||
password : $(':input[name=password]').val()
|
||||
old_password : $('.form-password :input[name=old_password]').val()
|
||||
password: $('.form-password :input[name=password]').val()
|
||||
.fail (jqXHR) ->
|
||||
alert jqXHR.responseJSON?.error ? jqXHR.statusText
|
||||
.success ->
|
||||
@@ -14,7 +14,16 @@ $ ->
|
||||
$('.action-save').click ->
|
||||
$.post '/account/update_setting/', JSON.stringify
|
||||
name: 'qq'
|
||||
value : $(':input[name=qq]').val()
|
||||
value: $(':input[name=qq]').val()
|
||||
.fail (jqXHR) ->
|
||||
alert jqXHR.responseJSON?.error ? jqXHR.statusText
|
||||
.success ->
|
||||
alert 'Success!'
|
||||
|
||||
$('.action-update-email').click ->
|
||||
$.post '/account/update_email/', JSON.stringify
|
||||
password: $('.form-email :input[name=password]').val()
|
||||
email: $(':input[name=email]').val()
|
||||
.fail (jqXHR) ->
|
||||
alert jqXHR.responseJSON?.error ? jqXHR.statusText
|
||||
.success ->
|
||||
|
||||
@@ -48,6 +48,10 @@ block main
|
||||
.row
|
||||
header 修改邮箱
|
||||
form.form-email.form-horizontal
|
||||
.form-group
|
||||
label.col-sm-2.col-md-offset-1.control-label 当前邮箱
|
||||
.col-sm-5
|
||||
input.form-control(value=account.email, disabled)
|
||||
.form-group
|
||||
label.col-sm-2.col-md-offset-1.control-label 密码
|
||||
.col-sm-5
|
||||
|
||||
Reference in New Issue
Block a user