Adding Authentication with AllIn API
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
7dfe35caeb
commit
b7337e679a
Binary file not shown.
Binary file not shown.
@ -0,0 +1,2 @@
|
|||||||
|
store=keys/keystore.jks
|
||||||
|
password=placeYourBets
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="app_name" translatable="false">Allin_DEBUG</string>
|
||||||
|
</resources>
|
@ -0,0 +1,71 @@
|
|||||||
|
package fr.iut.alldev.allin.ui.core
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
import fr.iut.alldev.allin.R
|
||||||
|
import fr.iut.alldev.allin.ui.theme.AllInTheme
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun AllInAlertDialog(
|
||||||
|
enabled: Boolean = true,
|
||||||
|
title: String,
|
||||||
|
text: String,
|
||||||
|
confirmText: String = stringResource(id = R.string.Ok),
|
||||||
|
onDismiss: ()->Unit,
|
||||||
|
onConfirm: ()->Unit = onDismiss
|
||||||
|
) {
|
||||||
|
if(enabled) {
|
||||||
|
AlertDialog(
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = title,
|
||||||
|
fontSize = 20.sp,
|
||||||
|
style = AllInTheme.typography.h1
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
style = AllInTheme.typography.r
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = onConfirm
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = confirmText,
|
||||||
|
fontSize = 15.sp,
|
||||||
|
style = AllInTheme.typography.h1.copy(
|
||||||
|
brush = AllInTheme.colors.allIn_MainGradient
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
containerColor = AllInTheme.themeColors.main_surface,
|
||||||
|
titleContentColor = AllInTheme.themeColors.on_main_surface,
|
||||||
|
textContentColor = AllInTheme.themeColors.on_background_2,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
|
@Composable
|
||||||
|
private fun AllInAlertDialogPreview() {
|
||||||
|
AllInTheme {
|
||||||
|
AllInAlertDialog(
|
||||||
|
title = "Titre",
|
||||||
|
text = "Lorem Ipsum",
|
||||||
|
onDismiss = {}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package fr.iut.alldev.allin.data.di
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
|
||||||
|
@Module(includes = [DebugNetworkModule::class])
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
object DebugModule
|
@ -0,0 +1,25 @@
|
|||||||
|
package fr.iut.alldev.allin.data.di
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
internal object DebugNetworkModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideOkHttpClient(): OkHttpClient =
|
||||||
|
OkHttpClient.Builder()
|
||||||
|
.addInterceptor(
|
||||||
|
HttpLoggingInterceptor().apply {
|
||||||
|
level = HttpLoggingInterceptor.Level.BODY
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package fr.iut.alldev.allin.data.api
|
||||||
|
|
||||||
|
import fr.iut.alldev.allin.data.api.model.CheckUser
|
||||||
|
import fr.iut.alldev.allin.data.api.model.ResponseUser
|
||||||
|
import retrofit2.http.Body
|
||||||
|
import retrofit2.http.POST
|
||||||
|
|
||||||
|
|
||||||
|
interface AllInApi {
|
||||||
|
@POST("users/login")
|
||||||
|
suspend fun login(
|
||||||
|
@Body body: CheckUser
|
||||||
|
): ResponseUser
|
||||||
|
|
||||||
|
@POST("users/register")
|
||||||
|
suspend fun register(
|
||||||
|
@Body body: ResponseUser
|
||||||
|
): ResponseUser
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package fr.iut.alldev.allin.data.api.model
|
||||||
|
|
||||||
|
import androidx.annotation.Keep
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
@Serializable
|
||||||
|
data class ResponseUser(
|
||||||
|
val username: String,
|
||||||
|
val email: String,
|
||||||
|
val password: String,
|
||||||
|
var nbCoins: Int,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
@Serializable
|
||||||
|
data class CheckUser(
|
||||||
|
val username: String,
|
||||||
|
val password: String,
|
||||||
|
)
|
@ -0,0 +1,23 @@
|
|||||||
|
package fr.iut.alldev.allin.data.di
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import fr.iut.alldev.allin.data.api.AllInApi
|
||||||
|
import fr.iut.alldev.allin.data.di.NetworkModule.createRetrofit
|
||||||
|
import okhttp3.HttpUrl
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
class ApiModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideAllInApi(@AllInUrl url: HttpUrl, okHttpClient: OkHttpClient): AllInApi {
|
||||||
|
val retrofit = createRetrofit(url = url, okHttpClient = okHttpClient)
|
||||||
|
return retrofit.create(AllInApi::class.java)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package fr.iut.alldev.allin.data.di
|
||||||
|
|
||||||
|
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import okhttp3.HttpUrl
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
import javax.inject.Qualifier
|
||||||
|
|
||||||
|
internal val json by lazy {
|
||||||
|
Json {
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
encodeDefaults = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Qualifier
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
annotation class AllInUrl
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
internal object NetworkModule {
|
||||||
|
|
||||||
|
@AllInUrl
|
||||||
|
@Provides
|
||||||
|
fun provideUrl(): HttpUrl = "https://codefirst.iut.uca.fr/containers/AllDev-api/".toHttpUrl()
|
||||||
|
|
||||||
|
fun createRetrofit(url: HttpUrl, okHttpClient: OkHttpClient): Retrofit =
|
||||||
|
Retrofit.Builder()
|
||||||
|
.client(okHttpClient)
|
||||||
|
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
|
||||||
|
.baseUrl(url)
|
||||||
|
.build()
|
||||||
|
}
|
@ -1,4 +1,13 @@
|
|||||||
package fr.iut.alldev.allin.data.repository
|
package fr.iut.alldev.allin.data.repository
|
||||||
|
|
||||||
abstract class UserRepository {
|
abstract class UserRepository {
|
||||||
|
abstract suspend fun login(
|
||||||
|
username: String,
|
||||||
|
password: String
|
||||||
|
)
|
||||||
|
abstract suspend fun register(
|
||||||
|
username: String,
|
||||||
|
email: String,
|
||||||
|
password: String
|
||||||
|
)
|
||||||
}
|
}
|
@ -1,10 +1,32 @@
|
|||||||
package fr.iut.alldev.allin.data.repository.impl
|
package fr.iut.alldev.allin.data.repository.impl
|
||||||
|
|
||||||
|
import fr.iut.alldev.allin.data.api.AllInApi
|
||||||
|
import fr.iut.alldev.allin.data.api.model.CheckUser
|
||||||
|
import fr.iut.alldev.allin.data.api.model.ResponseUser
|
||||||
import fr.iut.alldev.allin.data.repository.UserRepository
|
import fr.iut.alldev.allin.data.repository.UserRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class UserRepositoryImpl @Inject constructor(
|
class UserRepositoryImpl @Inject constructor(
|
||||||
|
private val api: AllInApi,
|
||||||
) : UserRepository() {
|
) : UserRepository() {
|
||||||
|
override suspend fun login(username: String, password: String) {
|
||||||
|
api.login(
|
||||||
|
CheckUser(
|
||||||
|
username = username,
|
||||||
|
password = password
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun register(username: String, email: String, password: String) {
|
||||||
|
api.register(
|
||||||
|
ResponseUser(
|
||||||
|
username = username,
|
||||||
|
email = email,
|
||||||
|
password = password,
|
||||||
|
nbCoins = 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package fr.iut.alldev.allin.data.di
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module(includes = [ReleaseNetworkModule::class])
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
object ReleaseModule
|
@ -0,0 +1,20 @@
|
|||||||
|
package fr.iut.alldev.allin.data.di
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
internal object ReleaseNetworkModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideOkHttpClient(): OkHttpClient =
|
||||||
|
OkHttpClient.Builder()
|
||||||
|
.build()
|
||||||
|
}
|
Loading…
Reference in new issue