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 changePassword(userId: Id @@ User, | |
| currentPassword: String, | |
| newPassword: String): ConnectionIO[Unit] = | |
| for { | |
| user <- userOrNotFound(UserModel.findById(userId)) | |
| _ <- verifyPassword(user, currentPassword) | |
| _ = logger.debug(s"Changing password for user: $userId") | |
| _ <- UserModel.updatePassword(userId, User.hashPassword(newPassword)) | |
| } yield () |
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
| object UserModel { | |
| def findById(id: Id @@ User): ConnectionIO[Option[User]] = { | |
| findBy(fr"id = $id") | |
| } | |
| def findByEmail(email: String @@ LowerCased): ConnectionIO[Option[User]] = { | |
| findBy(fr"email_lowercase = $email") | |
| } | |
| private def findBy(by: Fragment): ConnectionIO[Option[User]] = { |
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
| import io.circe.Decoder | |
| import com.softwaremill.bootzooka.infrastructure.Json._ | |
| case class Register_IN(login: String, email: String, password: String) | |
| implicitly[Decoder[Register_IN]] |
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
| import com.softwaremill.tagging.@@ | |
| import io.circe.generic.AutoDerivation | |
| import io.circe.java8.time.{JavaTimeDecoders, JavaTimeEncoders} | |
| import io.circe.{Decoder, Encoder, Printer} | |
| object Json extends AutoDerivation with JavaTimeDecoders with JavaTimeEncoders { | |
| val noNullsPrinter: Printer = Printer.noSpaces.copy(dropNullValues = true) | |
| implicit def taggedStringEncoder[U]: Encoder[String @@ U] = | |
| Encoder.encodeString.asInstanceOf[Encoder[String @@ U]] |
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
| private val updateUserEndpoint = secureEndpoint.post | |
| .in(User) | |
| .in(jsonBody[UpdateUser_IN]) | |
| .out(jsonBody[UpdateUser_OUT]) | |
| .serverLogic { | |
| case (authData, data) => | |
| (for { | |
| userId <- auth(authData) | |
| _ <- userService.changeUser(userId, data.login, data.email).transact(xa) | |
| } yield UpdateUser_OUT()).toOut |
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
| case class DBConfig(username: String, password: String, url: String, | |
| migrateOnStart: Boolean, driver: String, connectThreadPoolSize: Int) { | |
| override def toString: String = | |
| s"DBConfig($username,***,$url,$migrateOnStart,$driver,$connectThreadPoolSize)" | |
| } | |
| case class HttpConfig(host: String, port: Int) | |
| // ... other config classes ... | |
| case class Config(db: DBConfig, api: HttpConfig, email: EmailConfig, | |
| passwordReset: PasswordResetConfig, user: UserConfig) |
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
| trait EmailModule extends BaseModule { | |
| lazy val emailService = new EmailService(idGenerator, emailSender, config.email, xa) | |
| // the EmailService implements the EmailScheduler functionality - hence, creating | |
| // an alias for this dependency | |
| lazy val emailScheduler: EmailScheduler = emailService | |
| lazy val emailTemplates = new EmailTemplates() | |
| // depending on the configuration, creating the appropriate EmailSender instance | |
| lazy val emailSender: EmailSender = if (config.email.mailgun.enabled) { | |
| new MailgunEmailSender(config.email.mailgun)(sttpBackend) | |
| } else if (config.email.smtp.enabled) { |
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
| { | |
| "contractName": "Tender", | |
| "abi": [ | |
| { | |
| "constant": true, | |
| "inputs": [ | |
| { | |
| "name": "", | |
| "type": "uint256" | |
| } |
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
| val ae = IO.effectAsync[Any, Throwable, Unit] { cb => | |
| ec3.submit(new Runnable { | |
| override def run(): Unit = { | |
| println(Thread.currentThread().getName + " (async)") | |
| cb(IO.fail(new IllegalStateException())) | |
| } | |
| }) | |
| } | |
| run("async shift error") { |
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
| run("async shift error") { | |
| ae.guarantee(IO.shift(ec1)).guarantee(printThread) | |
| } | |
| /* | |
| Outputs: | |
| -- async shift error -- | |
| ec3-1-785992331 (async) | |
| ec1-2-274064559 |