Correction TP6
This commit is contained in:
@@ -7,6 +7,10 @@ import retrofit2.http.Body
|
|||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
|
|
||||||
|
data class EmailDTO(var email: String) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
interface AuthService {
|
interface AuthService {
|
||||||
|
|
||||||
@POST("login")
|
@POST("login")
|
||||||
@@ -15,6 +19,9 @@ interface AuthService {
|
|||||||
@POST("signup")
|
@POST("signup")
|
||||||
suspend fun signup(@Body signUpRequestDTO: SignUpRequestDTO) : ServiceResponseDTO<SignUpRequestDTO>
|
suspend fun signup(@Body signUpRequestDTO: SignUpRequestDTO) : ServiceResponseDTO<SignUpRequestDTO>
|
||||||
|
|
||||||
|
@POST("reset-password")
|
||||||
|
suspend fun resetPassword(@Body email: EmailDTO) : ServiceResponseDTO<String>
|
||||||
|
|
||||||
object AuthApi {
|
object AuthApi {
|
||||||
val authService : AuthService by lazy { retrofit.create(AuthService::class.java) }
|
val authService : AuthService by lazy { retrofit.create(AuthService::class.java) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import androidx.compose.foundation.Image
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
@@ -19,18 +21,22 @@ import com.example.tpfilrouge.ui.theme.EniPage
|
|||||||
import com.example.tpfilrouge.ui.theme.EniTextField
|
import com.example.tpfilrouge.ui.theme.EniTextField
|
||||||
|
|
||||||
class ResetPasswordActivity : ComponentActivity() {
|
class ResetPasswordActivity : ComponentActivity() {
|
||||||
|
|
||||||
|
var resetPasswordViewModel = ResetPasswordViewModel();
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
ResetPasswordActivityPage()
|
ResetPasswordActivityPage(resetPasswordViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ResetPasswordActivityPage() {
|
fun ResetPasswordActivityPage(resetPasswordViewModel: ResetPasswordViewModel) {
|
||||||
|
val emailField by resetPasswordViewModel.email.collectAsState();
|
||||||
|
|
||||||
EniPage {
|
EniPage {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
@@ -39,8 +45,8 @@ fun ResetPasswordActivityPage() {
|
|||||||
painter = painterResource(id = R.drawable.reset_password_ic),
|
painter = painterResource(id = R.drawable.reset_password_ic),
|
||||||
contentDescription = "Logo SignUp",
|
contentDescription = "Logo SignUp",
|
||||||
modifier = Modifier.padding(vertical = 40.dp))
|
modifier = Modifier.padding(vertical = 40.dp))
|
||||||
EniTextField("Email")
|
EniTextField("Email", value = emailField, onValueChange = { value -> resetPasswordViewModel.email.value = value})
|
||||||
EniButton("Envoyer le lien de récupération", onClick = {})
|
EniButton("Envoyer le lien de récupération", onClick = { resetPasswordViewModel.callResetPasswordApi() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,5 +54,5 @@ fun ResetPasswordActivityPage() {
|
|||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun ResetPasswordActivityPreview() {
|
fun ResetPasswordActivityPreview() {
|
||||||
ResetPasswordActivityPage()
|
ResetPasswordActivityPage(ResetPasswordViewModel())
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.example.tpfilrouge.auth
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.example.tpfilrouge.helpers.AlertDialogHelpers
|
||||||
|
import com.example.tpfilrouge.helpers.AppDialogHelpers
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class ResetPasswordViewModel : ViewModel() {
|
||||||
|
|
||||||
|
var email = MutableStateFlow("isaac@gmail.com")
|
||||||
|
|
||||||
|
fun callResetPasswordApi(){
|
||||||
|
AppDialogHelpers.get().showDialog("Envoie du mail de réinitialisation");
|
||||||
|
|
||||||
|
viewModelScope.launch {
|
||||||
|
// Appel api async
|
||||||
|
val emailDTO = EmailDTO(email.value);
|
||||||
|
val responseService = AuthService.AuthApi.authService.resetPassword(emailDTO);
|
||||||
|
|
||||||
|
// Fermer la popup de chargement aprés l'appel de API
|
||||||
|
AppDialogHelpers.get().closeDialog()
|
||||||
|
|
||||||
|
// Afficher le resultat de l'api
|
||||||
|
AlertDialogHelpers.get().show(responseService.message, onClose = {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user