can't use the same email address more than 4 times per month
parent
5960927a9f
commit
8d71d3c4aa
|
@ -5,6 +5,8 @@ import scala.concurrent.duration._
|
|||
|
||||
import lila.common.EmailAddress
|
||||
import lila.user.{ User, UserRepo }
|
||||
import scala.concurrent.ExecutionContext
|
||||
import org.joda.time.DateTime
|
||||
|
||||
/** Validate and normalize emails
|
||||
*/
|
||||
|
@ -13,7 +15,7 @@ final class EmailAddressValidator(
|
|||
disposable: DisposableEmailDomain,
|
||||
dnsApi: DnsApi,
|
||||
checkMail: CheckMail
|
||||
) {
|
||||
)(implicit ec: ExecutionContext) {
|
||||
|
||||
private def isAcceptable(email: EmailAddress): Boolean =
|
||||
email.domain exists disposable.isOk
|
||||
|
@ -35,7 +37,8 @@ final class EmailAddressValidator(
|
|||
}
|
||||
|
||||
private def wasUsedTwiceRecently(email: EmailAddress): Fu[Boolean] =
|
||||
userRepo.countRecentByPrevEmail(email.normalize).dmap(1 <)
|
||||
userRepo.countRecentByPrevEmail(email.normalize, DateTime.now.minusWeeks(1)).dmap(_ >= 2) >>|
|
||||
userRepo.countRecentByPrevEmail(email.normalize, DateTime.now.minusMonths(1)).dmap(_ >= 4)
|
||||
|
||||
val acceptableConstraint = Constraint[String]("constraint.email_acceptable") { e =>
|
||||
if (EmailAddress.from(e).exists(isAcceptable)) Valid
|
||||
|
|
|
@ -52,10 +52,7 @@ final class UserRepo(val coll: Coll)(implicit ec: scala.concurrent.ExecutionCont
|
|||
.cursor[Bdoc](readPreference)
|
||||
}
|
||||
|
||||
def countRecentByPrevEmail(
|
||||
email: NormalizedEmailAddress,
|
||||
since: DateTime = DateTime.now.minusWeeks(1)
|
||||
): Fu[Int] =
|
||||
def countRecentByPrevEmail(email: NormalizedEmailAddress, since: DateTime): Fu[Int] =
|
||||
coll.countSel($doc(F.prevEmail -> email, F.createdAt $gt since))
|
||||
|
||||
def pair(x: Option[ID], y: Option[ID]): Fu[(Option[User], Option[User])] =
|
||||
|
|
Loading…
Reference in New Issue