|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package com.iqball.app.page
|
|
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
|
@ -13,7 +12,6 @@ import androidx.compose.material3.OutlinedTextField
|
|
|
|
|
import androidx.compose.material3.Surface
|
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
@ -21,18 +19,16 @@ import androidx.compose.runtime.setValue
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import arrow.core.Either
|
|
|
|
|
import com.iqball.app.api.service.AuthService
|
|
|
|
|
import com.iqball.app.api.service.IQBallService
|
|
|
|
|
import com.iqball.app.session.Authentication
|
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
|
import kotlinx.datetime.LocalDateTime
|
|
|
|
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun RegisterPage(service: AuthService, onLoginSuccess: (Authentication) -> Unit) {
|
|
|
|
|
fun RegisterPage(service: AuthService, onRegisterSuccess: (Authentication) -> Unit) {
|
|
|
|
|
var username by remember { mutableStateOf("") }
|
|
|
|
|
var email by remember { mutableStateOf("") }
|
|
|
|
|
var password by remember { mutableStateOf("") }
|
|
|
|
@ -76,7 +72,8 @@ fun RegisterPage(service: AuthService, onLoginSuccess: (Authentication) -> Unit)
|
|
|
|
|
value = password,
|
|
|
|
|
onValueChange = { password = it },
|
|
|
|
|
label = { Text("Mot de passe") },
|
|
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
visualTransformation = PasswordVisualTransformation()
|
|
|
|
|
)
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
|
OutlinedTextField(
|
|
|
|
@ -90,11 +87,18 @@ fun RegisterPage(service: AuthService, onLoginSuccess: (Authentication) -> Unit)
|
|
|
|
|
when (val response =
|
|
|
|
|
service.register(AuthService.RegisterRequest(username, email, password))) {
|
|
|
|
|
is Either.Left -> {
|
|
|
|
|
errors = response.value.toList().flatMap { entry -> entry.second.map { "${entry.first} : ${it}" } }.joinToString("\n")
|
|
|
|
|
errors = response.value.toList()
|
|
|
|
|
.flatMap { entry -> entry.second.map { "${entry.first} : ${it}" } }
|
|
|
|
|
.joinToString("\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
is Either.Right -> {
|
|
|
|
|
onLoginSuccess(Authentication(response.value.token,LocalDateTime.parse(response.value.expirationDate)))
|
|
|
|
|
onRegisterSuccess(
|
|
|
|
|
Authentication(
|
|
|
|
|
response.value.token,
|
|
|
|
|
response.value.expirationDate
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|