mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
add changeEmail function to newsletter manager
not actually called
This commit is contained in:
parent
88f2b3670b
commit
6208e9f2d0
2 changed files with 23 additions and 8 deletions
|
@ -4,14 +4,19 @@ Settings = require 'settings-sharelatex'
|
|||
crypto = require('crypto')
|
||||
Mailchimp = require('mailchimp-api-v3')
|
||||
|
||||
|
||||
if !Settings.mailchimp?.api_key?
|
||||
logger.warn "No newsletter provider configured so not chaning email on user"
|
||||
mailchimp =
|
||||
request: (opts, cb)-> cb()
|
||||
else
|
||||
mailchimp = new Mailchimp(Settings.mailchimp?.api_key)
|
||||
|
||||
module.exports =
|
||||
|
||||
subscribe: (user, callback = () ->)->
|
||||
if !Settings.mailchimp?
|
||||
logger.warn "No newsletter provider configured so not subscribing user"
|
||||
return callback()
|
||||
options = buildOptions(user, true)
|
||||
logger.log options:options, user:user, email:user.email, "trying to subscribe user to the mailing list"
|
||||
mailchimp = new Mailchimp(Settings.mailchimp?.api_key)
|
||||
mailchimp.request options, (err)->
|
||||
if err?
|
||||
logger.err err:err, "error subscribing person to newsletter"
|
||||
|
@ -20,12 +25,8 @@ module.exports =
|
|||
callback(err)
|
||||
|
||||
unsubscribe: (user, callback = () ->)->
|
||||
if !Settings.mailchimp?
|
||||
logger.warn "No newsletter provider configured so not unsubscribing user"
|
||||
return callback()
|
||||
logger.log user:user, email:user.email, "trying to unsubscribe user to the mailing list"
|
||||
options = buildOptions(user, false)
|
||||
mailchimp = new Mailchimp(Settings.mailchimp?.api_key)
|
||||
mailchimp.request options, (err)->
|
||||
if err?
|
||||
logger.err err:err, "error unsubscribing person to newsletter"
|
||||
|
@ -33,6 +34,19 @@ module.exports =
|
|||
logger.log user:user, "finished unsubscribing user to the newsletter"
|
||||
callback(err)
|
||||
|
||||
changeEmail: (oldEmail, newEmail, callback = ()->)->
|
||||
options = buildOptions({email:oldEmail})
|
||||
delete options.body.status
|
||||
options.body.email_address = newEmail
|
||||
mailchimp.request options, (err)->
|
||||
# if the user has unsubscribed mailchimp will error on email address change
|
||||
if err? and err?.message.indexOf("could not be validated") == -1
|
||||
logger.err err:err, "error changing email in newsletter"
|
||||
return callback(err)
|
||||
else
|
||||
logger.log "finished changing email in the newsletter"
|
||||
return callback()
|
||||
|
||||
hashEmail = (email)->
|
||||
crypto.createHash('md5').update(email.toLowerCase()).digest("hex")
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ EmailHelper = require "../Helpers/EmailHelper"
|
|||
Errors = require "../Errors/Errors"
|
||||
Settings = require "settings-sharelatex"
|
||||
request = require 'request'
|
||||
NewsletterManager = require "../Newsletter/NewsletterManager"
|
||||
|
||||
module.exports = UserUpdater =
|
||||
updateUser: (query, update, callback = (error) ->) ->
|
||||
|
|
Loading…
Reference in a new issue