This file contains 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
dependencies { | |
implementation 'com.amplifyframework:aws-api:1.37.3' | |
implementation 'com.amplifyframework:aws-datastore:1.37.3' | |
} |
This file contains 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
//extention method to call in the Application class | |
fun Application.configureRouting(authController: AuthController) { | |
routing { | |
authenticationRoutes(authController) | |
} | |
} | |
//Register route | |
fun Route.authenticationRoutes(controller: AuthController) { |
This file contains 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
@Serializable | |
data class UserDetails(val id: String, val username: String, val email: String, val user_type: String) | |
@Serializable | |
data class UserDetailResponse( | |
override val status: State, | |
override val message: String, | |
val user: UserDetails? = null | |
) : Response { |
This file contains 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
/** | |
* Authentication controller | |
[authDao] was created earlier, an interface that we use to communicate with our database | |
[jwt controller] a class for user authentication | |
[encryptor] an helper method for enrypting password string | |
* */ | |
class AuthController( | |
private val authDao: AuthDao, | |
private val jwt: JwtController, | |
private val encryptor: (String) -> String |
This file contains 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
class AuthDaoImpl : AuthDao { | |
//add a new user into database | |
override fun registerUser( | |
username: String, | |
email: String, | |
usertype: String, | |
password: String | |
): User = transaction { | |
EntityUser.new { | |
this.username = username |
This file contains 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
interface AuthDao { | |
/**** | |
* add a new user to database | |
* */ | |
fun registerUser( | |
username: String, | |
email: String, | |
password: String, | |
): User | |
This file contains 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
//extention method to call in the Application class | |
fun Application.configureRouting(authController: AuthController) { | |
routing { | |
authenticationRoutes(authController) | |
} | |
} | |
//Register route | |
fun Route.authenticationRoutes(controller: AuthController) { |
This file contains 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
/** | |
* Authentication controller | |
[authDao] was created earlier, an interface that we use to communicate with our database | |
[jwt controller] a class for user authentication | |
[encryptor] an helper method for enrypting password string | |
* */ | |
class AuthController( | |
private val authDao: AuthDao, | |
private val jwt: JwtController, | |
private val encryptor: (String) -> String |
This file contains 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
class AuthDaoImpl : AuthDao { | |
//add a new user into database | |
override fun registerUser( | |
username: String, | |
email: String, | |
usertype: String, | |
password: String | |
): User = transaction { | |
EntityUser.new { | |
this.username = username |
This file contains 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
interface AuthDao { | |
/**** | |
* add a new user to database | |
* */ | |
fun registerUser( | |
username: String, | |
email: String, | |
password: String, | |
): User | |