Created
August 23, 2019 19:24
-
-
Save araeuchle/55e29a7d5d014ab49b2d9e62156c490c 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
func register(_ req: Request) throws -> Future<UserResponse> { | |
return try req.content.decode(CreateUserRequest.self).flatMap { user -> Future<User> in | |
guard user.password == user.verifyPassword else { | |
throw Abort(.badRequest, reason: "Password and verification must match.") | |
} | |
let hash = try BCrypt.hash(user.password) | |
return User(id: nil, name: user.name, email: user.email, password: hash, acceptedTos: user.acceptedTos, acceptedAds: user.acceptedAds) | |
.save(on: req) | |
}.map { user in | |
let message = Mailgun.TemplateMessage( | |
from: "[email protected]", | |
to: user.email, | |
subject: "Willkommen bei What-To-Eat", | |
template: "registration", | |
templateData: ["verificationUrl": verificationUrl] | |
) | |
let mailgun = try req.make(Mailgun.self) | |
_ = try mailgun.send(message, on: req) | |
return try UserResponse(id: user.requireID(), name: user.name, email: user.email) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment