Last active
February 14, 2016 16:24
-
-
Save Akii/2d74060fa1f14f5a7d52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def initiateRegistration(userName: UserName, emailAddress: EmailAddress): Reader[RegistrationRepository, Future[Registration]] = Reader { repo => | |
val exists: OptionT[Future, (Registration, Registration)] = for { | |
e <- repo.findByUserName(userName) | |
u <- repo.findByEmailAddress(emailAddress) | |
} yield (e, u) | |
exists.run.flatMap { | |
case None => | |
val hash = Random.alphanumeric take 32 mkString "" | |
val reg = Registration(UUID.randomUUID(), userName, emailAddress, hash, DateTime.now()) | |
repo.add(reg).map(_ => reg) | |
case _ => | |
Future.failed(new Exception("Thing already exists.")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment