pyc-website

main website for pyc inc.

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

commit 9b38e63f16e02fb0a84c8965ad0df03959ccf8b2
parent b96bfe0fe13fbebe586b002c612092b731582b31
Author: Jul <jul@9o.is>
Date:   Thu, 24 Jul 2014 14:41:41 -0400

ugly fix for wierd bug that doesn't allow S object to be used in snippets

Diffstat:
Msrc/main/scala/inc/pyc/config/Site.scala | 2++
Msrc/main/scala/inc/pyc/model/EmailResetToken.scala | 19+++++++++----------
Msrc/main/scala/inc/pyc/model/User.scala | 68+++++++++++++++++++++++++++++++++-----------------------------------
Msrc/main/scala/inc/pyc/snippet/AdminSnip.scala | 58+++++++++++++++++++++++++++++++---------------------------
4 files changed, 75 insertions(+), 72 deletions(-)

diff --git a/src/main/scala/inc/pyc/config/Site.scala b/src/main/scala/inc/pyc/config/Site.scala @@ -6,6 +6,7 @@ import model.EmailResetToken._ import net.liftweb._ import common._ +import util._ import http.{S, OkResponse, RedirectResponse, RequestVar, Templates} import sitemap._ import sitemap.Loc._ @@ -38,6 +39,7 @@ object Site extends Locs { import MenuGroups._ val domain = "pycbitcoin.com" + def host = if(Props.devMode || Props.testMode) "127.0.0.1" else domain // Regular links val home = MenuLoc(Menu.i("Bitcoin ATM Services") / "index" >> TopBarGroup) diff --git a/src/main/scala/inc/pyc/model/EmailResetToken.scala b/src/main/scala/inc/pyc/model/EmailResetToken.scala @@ -18,6 +18,8 @@ import mongoauth.field._ import mongoauth.Locs._ import org.joda.time.Hours import org.bson.types.ObjectId +import scala.concurrent._ +import ExecutionContext.Implicits.global /** * This is a token for verifying new email. @@ -42,10 +44,10 @@ object EmailResetToken extends EmailResetToken with MongoMetaRecord[EmailResetTo private lazy val resetEmailTokenUrl = "/reset-email-token" private lazy val resetEmailTokenExpires = Hours.hours(48) - def url(inst: EmailResetToken): String = "%s%s?token=%s".format(S.hostAndPath, resetEmailTokenUrl, inst.id.toString) + def url(inst: EmailResetToken): String = "%s%s?token=%s".format(Site.domain, resetEmailTokenUrl, inst.id.toString) - def createForUserIdBox(uid: ObjectId, email: String): Box[EmailResetToken] = { - createRecord.userId(uid).email(email).saveBox + def createForUserId(uid: ObjectId, email: String): EmailResetToken = { + createRecord.userId(uid).email(email).save() } def deleteAllByUserIdBox(uid: ObjectId): Box[Unit] = tryo { @@ -56,22 +58,19 @@ object EmailResetToken extends EmailResetToken with MongoMetaRecord[EmailResetTo if (ObjectId.isValid(in)) find(new ObjectId(in)) else Failure("Invalid ObjectId: "+in) - def sendToken(user: User, email: String): Unit = { + def sendToken(user: User, email: String): Future[Unit] = Future { import net.liftweb.util.Mailer._ - val token = EmailResetToken.createForUserIdBox(user.id.get, email) + val token = EmailResetToken.createForUserId(user.id.get, email) 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) - } { + HtmlEmail.createToken(title, msg, token.url) map { sendMail( From(MongoAuth.systemFancyEmail), Subject("%s: %s".format(MongoAuth.siteName.vend, title)), To(token.email.get), - html + _ ) } } diff --git a/src/main/scala/inc/pyc/model/User.scala b/src/main/scala/inc/pyc/model/User.scala @@ -2,6 +2,7 @@ package inc.pyc package model import lib._ +import config._ import field._ import lib.RogueMetaRecord import org.bson.types.ObjectId @@ -15,6 +16,8 @@ import net.liftmodules.mongoauth._ import net.liftmodules.mongoauth.field._ import net.liftmodules.mongoauth.model._ import java.util.regex.Pattern +import scala.concurrent._ +import ExecutionContext.Implicits.global class User private () extends ProtoAuthUser[User] with ObjectIdPk[User] with USAUserVerification[User] { def meta = User @@ -118,49 +121,44 @@ object User extends User with ProtoAuthUserMeta[User] with RogueMetaRecord[User] /** * Sends an email to the user with a link for logging in. */ - def sendLoginToken(user: User): Unit = { + def sendLoginToken(user: User): Future[Unit] = Future { 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." - for { - token <- token - html <- HtmlEmail.createToken(title, msg, token.url) - } { - sendMail( - From(MongoAuth.systemFancyEmail), - Subject("%s: %s".format(siteName, title)), - To(user.fancyEmail), - html - ) - } + val token = LoginToken.createRecord.userId(user.id.get).save() + val url = "%s%s?token=%s".format(Site.host, MongoAuth.loginTokenUrl.vend, token.id.toString) + val title = "Account Login" + val msg = s"Hello ${user.fname.get}, someone requested a link to log in to your account." + + HtmlEmail.createToken(title, msg, url) map { + sendMail( + From(MongoAuth.systemFancyEmail), + Subject("%s: %s".format(siteName, title)), + To(user.fancyEmail), + _ + ) + } } /** * Sends registration token. */ - def sendRegistrationToken(user: User): Unit = { + def sendRegistrationToken(user: User): Future[Unit] = Future { import net.liftweb.util.Mailer._ - - val token = LoginToken.createForUserIdBox(user.id.get) - val title = "Account Registration" - val msg = - s"Hello ${user.fname.get}, thank you for registering"+ - " 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: %s".format(siteName, title)), - To(user.fancyEmail), - html - ) - } + + val token = LoginToken.createRecord.userId(user.id.get).save() + val url = "%s%s?token=%s".format(Site.host, MongoAuth.loginTokenUrl.vend, token.id.toString) + val title = "Account Registration" + val msg = s"Hello ${user.fname.get}, thank you for registering" + + " and using bitcoin. Please follow the link to complete your registration." + + HtmlEmail.createToken(title, msg, url) map { + sendMail( + From(MongoAuth.systemFancyEmail), + Subject("%s: %s".format(siteName, title)), + To(user.fancyEmail), + _ + ) + } } /* diff --git a/src/main/scala/inc/pyc/snippet/AdminSnip.scala b/src/main/scala/inc/pyc/snippet/AdminSnip.scala @@ -15,6 +15,8 @@ import JsonDSL._ import com.foursquare._ import rogue.LiftRogue._ import net.liftmodules.mongoauth.MongoAuth +import scala.concurrent._ +import ExecutionContext.Implicits.global trait AdminSnip extends AngularSnippet @@ -42,52 +44,54 @@ class VerifyId extends AdminSnip { val fname = user.fname.get val limit = user.purchaseLimit.get val title = "Identity Verification" + val settingsUrl = Site.domain+"/settings" - val html: Box[NodeSeq] = - - if(accepted) { + Future { + val html: Box[NodeSeq] = + if(accepted) { - if(limit == D3000_Pending) user.purchaseLimit(D3000) - else user.purchaseLimit(Unlimited) - user.update + if(limit == D3000_Pending) user.purchaseLimit(D3000) + else user.purchaseLimit(Unlimited) + user.update - val subtitle = s"Congratulations $fname, you've been verified!" - val body = - <div> + val subtitle = s"Congratulations $fname, you've been verified!" + val body = + <div> {subtitle} <br/> <h2>Your new bitcoin purchase limit is {user.purchaseLimit.get}</h2> <br/> To purchase bitcoin from a store ATM, you may need to authenticate face-to-face with the store manager or an authorized employee using a one-time password - available in the <a href={Site.settings.fullUrl}>settings page of your PYC account</a>. + available in the <a href={settingsUrl}>settings page of your PYC account</a>. Note, this password is not related to the bitcoin you possess; it's only a way to prove to the store owner you can purchase up to {user.purchaseLimit.get}. This is a requirement in only some states. For information about the authorization process, read more about FinCen MSB requirements. We apologize for the strict regulations and thank you for your interest in buying bitcoin. - </div> + </div> - HtmlEmail.simpleMessage(title, subtitle, body) + HtmlEmail.simpleMessage(title, subtitle, body) - } else { + } else { - if(limit == D3000_Pending) user.purchaseLimit(D1000) - else user.purchaseLimit(D3000) - user.update + if(limit == D3000_Pending) user.purchaseLimit(D1000) + else user.purchaseLimit(D3000) + user.update - val JString(reason) = model \ "reason" - val subtitle = s"Sorry $fname, your verification failed!" - val body = s"$subtitle $reason -- Your bitcoin buy limit remains at ${user.purchaseLimit.get}" - HtmlEmail.simpleMessage(title, subtitle, Text(body)) - } + val JString(reason) = model \ "reason" + val subtitle = s"Sorry $fname, your verification failed!" + val body = s"$subtitle $reason -- Your bitcoin buy limit remains at ${user.purchaseLimit.get}" + HtmlEmail.simpleMessage(title, subtitle, Text(body)) + } - html map (sendMail( - From(MongoAuth.systemFancyEmail), - Subject("%s: %s".format(MongoAuth.siteName.vend, title)), - To(user.fancyEmail), - _ - )) + html map (sendMail( + From(MongoAuth.systemFancyEmail), + Subject("%s: %s".format(MongoAuth.siteName.vend, title)), + To(user.fancyEmail), + _ + )) + } NgAlert.success("Updated") }