translate account confirmation email
parent
265ffb02b8
commit
77e5ee9d7e
|
@ -2,7 +2,7 @@ const fs = require('fs-extra');
|
|||
const parseString = require('xml2js').parseString;
|
||||
|
||||
const baseDir = 'translation/source';
|
||||
const dbs = ['site', 'arena'];
|
||||
const dbs = ['site', 'arena', 'emails'];
|
||||
|
||||
function ucfirst(s) {
|
||||
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||
|
|
|
@ -7,13 +7,16 @@ object I18nDb {
|
|||
sealed trait Ref
|
||||
case object Site extends Ref
|
||||
case object Arena extends Ref
|
||||
case object Emails extends Ref
|
||||
|
||||
val site: Messages = lila.i18n.db.site.Registry.load
|
||||
val arena: Messages = lila.i18n.db.arena.Registry.load
|
||||
val emails: Messages = lila.i18n.db.emails.Registry.load
|
||||
|
||||
def apply(ref: Ref): Messages = ref match {
|
||||
case Site => site
|
||||
case Arena => arena
|
||||
case Emails => emails
|
||||
}
|
||||
|
||||
val langs = site.keySet
|
||||
|
|
|
@ -8,13 +8,13 @@ sealed trait I18nKey {
|
|||
|
||||
val key: String
|
||||
|
||||
def literalHtmlTo(lang: Lang, args: Seq[Any]): Html
|
||||
def literalHtmlTo(lang: Lang, args: Seq[Any] = Seq.empty): Html
|
||||
|
||||
def pluralHtmlTo(lang: Lang, count: Count, args: Seq[Any]): Html
|
||||
def pluralHtmlTo(lang: Lang, count: Count, args: Seq[Any] = Nil): Html
|
||||
|
||||
def literalTxtTo(lang: Lang, args: Seq[Any]): String
|
||||
def literalTxtTo(lang: Lang, args: Seq[Any] = Seq.empty): String
|
||||
|
||||
def pluralTxtTo(lang: Lang, count: Count, args: Seq[Any]): String
|
||||
def pluralTxtTo(lang: Lang, count: Count, args: Seq[Any] = Nil): String
|
||||
|
||||
/* Implicit context convenience functions */
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Generated with bin/trans-dump.js
|
||||
package lila.i18n
|
||||
|
||||
import I18nDb.{ Site, Arena }
|
||||
import I18nDb.{ Site, Arena, Emails }
|
||||
|
||||
// format: OFF
|
||||
object I18nKeys {
|
||||
|
@ -657,4 +657,12 @@ val `thisIsPrivate` = new Translated("thisIsPrivate", Arena)
|
|||
val `shareUrl` = new Translated("shareUrl", Arena)
|
||||
}
|
||||
|
||||
object emails {
|
||||
val `confirm_subject` = new Translated("confirm_subject", Emails)
|
||||
val `confirm_click` = new Translated("confirm_click", Emails)
|
||||
val `confirm_orPaste` = new Translated("confirm_orPaste", Emails)
|
||||
val `confirm_ignore` = new Translated("confirm_ignore", Emails)
|
||||
val `common_note` = new Translated("common_note", Emails)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,15 @@
|
|||
package lila.security
|
||||
|
||||
import play.api.i18n.Lang
|
||||
import lila.common.EmailAddress
|
||||
import lila.user.{ User, UserRepo }
|
||||
import lila.i18n.I18nKeys.{ emails => trans }
|
||||
|
||||
trait EmailConfirm {
|
||||
|
||||
def effective: Boolean
|
||||
|
||||
def send(user: User, email: EmailAddress): Funit
|
||||
def send(user: User, email: EmailAddress)(implicit lang: Lang): Funit
|
||||
|
||||
def confirm(token: String): Fu[Option[User]]
|
||||
}
|
||||
|
@ -16,7 +18,7 @@ object EmailConfirmSkip extends EmailConfirm {
|
|||
|
||||
def effective = false
|
||||
|
||||
def send(user: User, email: EmailAddress) = UserRepo setEmailConfirmed user.id
|
||||
def send(user: User, email: EmailAddress)(implicit lang: Lang) = UserRepo setEmailConfirmed user.id
|
||||
|
||||
def confirm(token: String): Fu[Option[User]] = fuccess(none)
|
||||
}
|
||||
|
@ -31,30 +33,35 @@ final class EmailConfirmMailgun(
|
|||
|
||||
val maxTries = 3
|
||||
|
||||
def send(user: User, email: EmailAddress): Funit = tokener make user.id flatMap { token =>
|
||||
def send(user: User, email: EmailAddress)(implicit lang: Lang): Funit = tokener make user.id flatMap { token =>
|
||||
lila.mon.email.confirmation()
|
||||
val url = s"$baseUrl/signup/confirm/$token"
|
||||
mailgun send Mailgun.Message(
|
||||
to = email,
|
||||
subject = s"Confirm your lichess.org account, ${user.username}",
|
||||
subject = trans.confirm_subject.literalTxtTo(lang, List(user.username)),
|
||||
text = s"""
|
||||
Final step!
|
||||
|
||||
Confirm your email address to complete your lichess account. It's easy — just click on the link below.
|
||||
${trans.confirm_click.literalTxtTo(lang)}
|
||||
|
||||
$url
|
||||
|
||||
(Clicking not working? Try pasting it into your browser!)
|
||||
${trans.confirm_orPaste.literalTxtTo(lang)}
|
||||
|
||||
This is a service email related to your use of lichess.org. If you did not register with Lichess you can safely ignore this message.""",
|
||||
${Mailgun.txt.serviceNote}
|
||||
${trans.confirm_ignore.literalTxtTo(lang, List("https://lichess.org"))}
|
||||
""",
|
||||
htmlBody = s"""
|
||||
<div itemscope itemtype="http://schema.org/EmailMessage">
|
||||
<strong>Final step!</strong>
|
||||
<p itemprop="description">Confirm your email address to activate your Lichess account. It's easy — just click the link below.</p>
|
||||
<p itemprop="description">${trans.confirm_click.literalHtmlTo(lang)}</p>
|
||||
<div itemprop="potentialAction" itemscope itemtype="http://schema.org/ViewAction">
|
||||
<meta itemprop="name" content="Activate account">
|
||||
${Mailgun.html.url(url)}
|
||||
</div>
|
||||
<div itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
||||
<small>
|
||||
${Mailgun.html.serviceNote}
|
||||
${trans.confirm_orPaste.literalTxtTo(lang)}
|
||||
</small>
|
||||
</div>
|
||||
${Mailgun.html.serviceNote}
|
||||
</div>""".some
|
||||
)
|
||||
|
|
|
@ -3,11 +3,13 @@ package lila.security
|
|||
import scala.concurrent.duration._
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import play.api.i18n.Lang
|
||||
import play.api.libs.ws.{ WS, WSAuthScheme }
|
||||
import play.api.Play.current
|
||||
import play.twirl.api.Html
|
||||
|
||||
import lila.common.EmailAddress
|
||||
import lila.i18n.I18nKeys.{ emails => trans }
|
||||
|
||||
final class Mailgun(
|
||||
apiUrl: String,
|
||||
|
@ -57,18 +59,26 @@ object Mailgun {
|
|||
retriesLeft: Int = 3
|
||||
)
|
||||
|
||||
object txt {
|
||||
|
||||
def serviceNote(implicit lang: Lang) =
|
||||
trans.common_note.literalHtmlTo(lang, List("https://lichess.org"))
|
||||
}
|
||||
|
||||
object html {
|
||||
|
||||
val serviceNote = """
|
||||
private val noteLink = """<a itemprop="url" href="https://lichess.org/"><span itemprop="name">lichess.org</span></a>"""
|
||||
|
||||
def serviceNote(implicit lang: Lang) = s"""
|
||||
<div itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
||||
<small>This is a service email related to your use of <a itemprop="url" href="https://lichess.org/"><span itemprop="name">lichess.org</span></a>.</small>
|
||||
<small>${trans.common_note.literalHtmlTo(lang, List(noteLink))}.</small>
|
||||
</div>
|
||||
"""
|
||||
|
||||
def url(u: String) = s"""
|
||||
def url(u: String)(implicit lang: Lang) = s"""
|
||||
<meta itemprop="url" content="$u">
|
||||
<p><a itemprop="target" href="$u">$u</a></p>
|
||||
<p>(Clicking not working? Try pasting it into your browser!)</p>
|
||||
<p>${trans.confirm_orPaste.literalHtmlTo(lang)}</p>
|
||||
"""
|
||||
|
||||
private[Mailgun] def wrap(subject: String, body: String) = s"""<!doctype html>
|
||||
|
|
|
@ -236,7 +236,7 @@ object ApplicationBuild extends Build {
|
|||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val security = project("security", Seq(common, hub, db, user)).settings(
|
||||
lazy val security = project("security", Seq(common, hub, db, user, i18n)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver, maxmind, hasher)
|
||||
)
|
||||
|
||||
|
@ -324,7 +324,7 @@ object ApplicationBuild extends Build {
|
|||
MessageCompiler(
|
||||
sourceDir = new File("translation/source"),
|
||||
destDir = new File("translation/dest"),
|
||||
dbs = List("site", "arena"),
|
||||
dbs = List("site", "arena", "emails"),
|
||||
compileTo = (sourceManaged in Compile).value / "messages"
|
||||
)
|
||||
}.taskValue,
|
||||
|
|
|
@ -15,6 +15,7 @@ object MessageCompiler {
|
|||
|
||||
private def doFile(db: String, sourceFile: File, destDir: File, compileTo: File): Seq[File] = {
|
||||
val startsAt = System.currentTimeMillis()
|
||||
destDir.mkdirs()
|
||||
val registry = ("en-GB" -> sourceFile) :: destDir.list.toList.map { f =>
|
||||
f.takeWhile('.' !=) -> (destDir / f)
|
||||
}.sortBy(_._1)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<resources>
|
||||
<string name="confirm_subject">Confirm your lichess.org account, %s</string>
|
||||
<string name="confirm_click">Click the link to enable your lichess account:</string>
|
||||
<string name="confirm_orPaste">(Clicking not working? Try pasting it into your browser!)</string>
|
||||
<string name="confirm_ignore">If you did not register with Lichess you can safely ignore this message.</string>
|
||||
<string name="common_note">This is a service email related to your use of %s.</string>
|
||||
</resources>
|
Loading…
Reference in New Issue