diff --git a/api/src/NotesApplication.kt b/api/src/NotesApplication.kt index e862227..2674808 100644 --- a/api/src/NotesApplication.kt +++ b/api/src/NotesApplication.kt @@ -27,7 +27,8 @@ lateinit var kodein: Kodein @Suppress("unused") // Referenced in application.conf fun Application.module() { - features() + // must be first to be loaded + configurationFeature() kodein = Kodein { import(controllerModule) @@ -36,6 +37,8 @@ fun Application.module() { bind() with singleton { Migration(this.kodein) } } + features() + log.debug(kodein.container.tree.bindings.description()) val feature: Feature by kodein.instance() diff --git a/api/src/auth/UsernamePasswordCredential.kt b/api/src/auth/UsernamePasswordCredential.kt new file mode 100644 index 0000000..3d27223 --- /dev/null +++ b/api/src/auth/UsernamePasswordCredential.kt @@ -0,0 +1,10 @@ +package be.vandewalleh.auth + +import io.ktor.auth.Credential + +/** + * Represents a simple user [username] and [password] credential pair + * @property username + * @property password + */ +data class UsernamePasswordCredential(val username: String, val password: String) : Credential \ No newline at end of file diff --git a/api/src/controllers/Controllers.kt b/api/src/controllers/Controllers.kt index 3bfc19a..874570b 100644 --- a/api/src/controllers/Controllers.kt +++ b/api/src/controllers/Controllers.kt @@ -13,4 +13,5 @@ val controllerModule = Kodein.Module(name = "Controller") { bind() from setBinding() bind().inSet() with singleton { TestController(this.kodein) } + bind().inSet() with singleton { UserController(this.kodein) } } \ No newline at end of file diff --git a/api/src/controllers/UserController.kt b/api/src/controllers/UserController.kt new file mode 100644 index 0000000..700df0a --- /dev/null +++ b/api/src/controllers/UserController.kt @@ -0,0 +1,33 @@ +package be.vandewalleh.controllers + +import be.vandewalleh.auth.SimpleJWT +import be.vandewalleh.auth.UsernamePasswordCredential +import io.ktor.application.call +import io.ktor.locations.Location +import io.ktor.locations.post +import io.ktor.request.receive +import io.ktor.response.respond +import io.ktor.routing.Routing +import org.kodein.di.Kodein +import org.kodein.di.generic.instance + +class UserController(kodein: Kodein) : KodeinController(kodein) { + private val simpleJwt by instance() + + override fun Routing.registerRoutes() { + post { + val post = call.receive() + + // TODO check db + if (post.username != "test" || post.password != "test") + error("Invalid Credentials") + + call.respond(mapOf("token" to simpleJwt.sign("test@test.be"))) + } + } + + object Routes { + @Location("/auth") + class Auth + } +} \ No newline at end of file diff --git a/api/src/features/Features.kt b/api/src/features/Features.kt index b594a0f..c77a1e1 100644 --- a/api/src/features/Features.kt +++ b/api/src/features/Features.kt @@ -6,9 +6,6 @@ import org.kodein.di.Kodein import org.kodein.di.KodeinAware fun Application.features() { - // must be first to be loaded - configurationFeature() - locationFeature() corsFeature() contentNegotiationFeature()