pyc-website

main website for pyc inc.

git clone https://9o.is/git/pyc-website.git

commit 6352a92abfd819e25397c8ad1e1de21f97d42ccd
parent 21f38d389988c62449bed02faab0d8c0a33cfeba
Author: Jul <jul@9o.is>
Date:   Wed,  4 Jun 2014 04:39:31 -0400

all emails sent to users are in html format (fixes issue #17)

Diffstat:
Msrc/main/scala/inc/pyc/model/EmailResetToken.scala | 30+++++++++++-------------------
Msrc/main/scala/inc/pyc/model/User.scala | 56+++++++++++++++++++++++++++++++++++++-------------------
Msrc/main/scala/inc/pyc/snippet/UserSnip.scala | 2+-
3 files changed, 49 insertions(+), 39 deletions(-)

diff --git a/src/main/scala/inc/pyc/model/EmailResetToken.scala b/src/main/scala/inc/pyc/model/EmailResetToken.scala @@ -1,6 +1,7 @@ package inc.pyc package model +import lib._ import config._ import net.liftweb._ import common._ @@ -59,28 +60,19 @@ object EmailResetToken extends EmailResetToken with MongoMetaRecord[EmailResetTo import net.liftweb.util.Mailer._ val token = EmailResetToken.createForUserIdBox(user.id.get, email) - - token.map { token => - val msgTxt = - """ - |Someone requested to change their %s account to this email. - | - |If you did not request this, you can safely ignore it. It will expire 48 hours from the time this message was sent. - | - |Follow the link below or copy and paste it into your internet browser. - | - |%s - | - |Kindest Regards, - | - |%s - """.format(MongoAuth.siteName.vend, token.url, MongoAuth.systemUsername.vend).stripMargin - + val title = "Reset Email" + val msg = s"Hello ${user.fname.get}, you requested to change your account to this email." + + for { + token <- token + html <- HtmlEmail.createToken(title, msg, token.url) + } { sendMail( From(MongoAuth.systemFancyEmail), - Subject("%s Account: Reset Email".format(MongoAuth.siteName.vend)), + Subject("%s: %s".format(MongoAuth.siteName.vend, title)), To(token.email.get), - PlainMailBodyType(msgTxt)) + html + ) } } diff --git a/src/main/scala/inc/pyc/model/User.scala b/src/main/scala/inc/pyc/model/User.scala @@ -1,6 +1,7 @@ package inc.pyc package model +import lib._ import field._ import lib.RogueMetaRecord @@ -98,33 +99,50 @@ object User extends User with ProtoAuthUserMeta[User] with RogueMetaRecord[User] Full(resp) } - // send an email to the user with a link for logging in + /** + * Sends an email to the user with a link for logging in. + */ def sendLoginToken(user: User): Unit = { import net.liftweb.util.Mailer._ val token = LoginToken.createForUserIdBox(user.id.get) + val title = "Account Login" + val msg = s"Hello ${user.fname.get}, someone requested a link to log in to your account." - token.map { token => - val msgTxt = - """ - |Someone requested a link to log in to your %s account. - | - |If you did not request this, you can safely ignore it. It will expire 48 hours from the time this message was sent. - | - |Follow the link below or copy and paste it into your internet browser. - | - |%s - | - |Kindest Regards, - | - |%s - """.format(siteName, token.url, sysUsername).stripMargin - + for { + token <- token + html <- HtmlEmail.createToken(title, msg, token.url) + } { + sendMail( + From(MongoAuth.systemFancyEmail), + Subject("%s: %s".format(siteName, title)), + To(user.fancyEmail), + html + ) + } + } + + /** + * Sends registration token. + */ + def sendRegistrationToken(user: User): Unit = { + import net.liftweb.util.Mailer._ + + val token = LoginToken.createForUserIdBox(user.id.get) + val title = "User Registration" + val msg = + s"Hello ${user.fname.get}, thank you for registering with us"+ + " and using bitcoin. Please follow the link to complete your registration." + + for { + token <- token + html <- HtmlEmail.createToken(title, msg, token.url) + } { sendMail( From(MongoAuth.systemFancyEmail), - Subject("%s Account: Login".format(siteName)), + Subject("%s: %s".format(siteName, title)), To(user.fancyEmail), - PlainMailBodyType(msgTxt) + html ) } } diff --git a/src/main/scala/inc/pyc/snippet/UserSnip.scala b/src/main/scala/inc/pyc/snippet/UserSnip.scala @@ -183,7 +183,7 @@ class UserRegistration extends AngularSnippet with AngularImplicits { user.validate match { case Nil => user.save() - User.sendLoginToken(user) + User.sendRegistrationToken(user) NgAlert.success( <i class="fa-fw fa fa-thumbs-o-up"></i> ++