Correction Sign Up
This commit is contained in:
@@ -29,9 +29,10 @@
|
|||||||
android:theme="@style/Theme.TpFilRouge" />
|
android:theme="@style/Theme.TpFilRouge" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".auth.SignUpActivity"
|
android:name=".auth.SignUpActivity"
|
||||||
android:exported="false"
|
android:exported="true"
|
||||||
android:label="@string/title_activity_sign_up"
|
android:label="@string/title_activity_sign_up"
|
||||||
android:theme="@style/Theme.TpFilRouge" />
|
android:theme="@style/Theme.TpFilRouge">
|
||||||
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".auth.LoginActivity"
|
android:name=".auth.LoginActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ interface AuthService {
|
|||||||
@POST("login")
|
@POST("login")
|
||||||
suspend fun login(@Body loginRequestDTO: LoginRequestDTO) : ServiceResponseDTO<String>
|
suspend fun login(@Body loginRequestDTO: LoginRequestDTO) : ServiceResponseDTO<String>
|
||||||
|
|
||||||
|
@POST("signup")
|
||||||
|
suspend fun signup(@Body signUpRequestDTO: SignUpRequestDTO) : ServiceResponseDTO<SignUpRequestDTO>
|
||||||
|
|
||||||
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,17 +21,29 @@ import com.example.tpfilrouge.ui.theme.EniPage
|
|||||||
import com.example.tpfilrouge.ui.theme.EniTextField
|
import com.example.tpfilrouge.ui.theme.EniTextField
|
||||||
|
|
||||||
class SignUpActivity : ComponentActivity() {
|
class SignUpActivity : ComponentActivity() {
|
||||||
|
|
||||||
|
var signUpViewModel = SignUpViewModel();
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
SignUpActivityPage()
|
SignUpActivityPage(signUpViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SignUpActivityPage() {
|
fun SignUpActivityPage(signUpViewModel: SignUpViewModel) {
|
||||||
|
// Ecouter et synchronser les champs saisies
|
||||||
|
val emailField by signUpViewModel.email.collectAsState()
|
||||||
|
val pseudoField by signUpViewModel.pseudo.collectAsState()
|
||||||
|
val passwordField by signUpViewModel.password.collectAsState()
|
||||||
|
val passwordConfirmField by signUpViewModel.passwordConfirm.collectAsState()
|
||||||
|
val cityCodeField by signUpViewModel.cityCode.collectAsState()
|
||||||
|
val cityField by signUpViewModel.city.collectAsState()
|
||||||
|
val phoneField by signUpViewModel.phone.collectAsState()
|
||||||
|
|
||||||
EniPage {
|
EniPage {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
@@ -38,14 +52,14 @@ fun SignUpActivityPage() {
|
|||||||
painter = painterResource(id = R.drawable.sign_up),
|
painter = painterResource(id = R.drawable.sign_up),
|
||||||
contentDescription = "Logo SignUp",
|
contentDescription = "Logo SignUp",
|
||||||
modifier = Modifier.padding(vertical = 10.dp))
|
modifier = Modifier.padding(vertical = 10.dp))
|
||||||
EniTextField("Pseudo")
|
EniTextField("Pseudo", value = pseudoField, onValueChange = { value -> signUpViewModel.pseudo.value = value; })
|
||||||
EniTextField("Email")
|
EniTextField("Email", value = emailField, onValueChange = { value -> signUpViewModel.email.value = value; })
|
||||||
EniTextField("Password")
|
EniTextField("Password", value = passwordField, onValueChange = { value -> signUpViewModel.password.value = value; })
|
||||||
EniTextField("Password Confirmation")
|
EniTextField("Password Confirmation", value = passwordConfirmField, onValueChange = { value -> signUpViewModel.passwordConfirm.value = value; })
|
||||||
EniTextField("City Code")
|
EniTextField("City Code", value = cityCodeField, onValueChange = { value -> signUpViewModel.cityCode.value = value; })
|
||||||
EniTextField("City")
|
EniTextField("City", value = cityField, onValueChange = { value -> signUpViewModel.city.value = value; })
|
||||||
EniTextField("Phone Number")
|
EniTextField("Phone Number", value = phoneField, onValueChange = { value -> signUpViewModel.phone.value = value; })
|
||||||
EniButton("Sign Up", onClick = {})
|
EniButton("Sign Up", onClick = { signUpViewModel.callSignUpApi() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,5 +67,5 @@ fun SignUpActivityPage() {
|
|||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun SignUpActivityPreview() {
|
fun SignUpActivityPreview() {
|
||||||
SignUpActivityPage()
|
SignUpActivityPage(SignUpViewModel())
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.example.tpfilrouge.auth
|
||||||
|
|
||||||
|
data class SignUpRequestDTO(var email : String, var pseudo : String,
|
||||||
|
var password : String, var passwordConfirm : String = "",
|
||||||
|
var cityCode: String, var city: String, var phone : String
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
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 SignUpViewModel : ViewModel() {
|
||||||
|
|
||||||
|
var email = MutableStateFlow("velocipastor@gmail.com")
|
||||||
|
var pseudo = MutableStateFlow("Lepuitdefou")
|
||||||
|
var password = MutableStateFlow("13456")
|
||||||
|
var passwordConfirm = MutableStateFlow("13456")
|
||||||
|
var cityCode = MutableStateFlow("44300")
|
||||||
|
var city = MutableStateFlow("Nantes")
|
||||||
|
var phone = MutableStateFlow("0612326699")
|
||||||
|
|
||||||
|
fun callSignUpApi(){
|
||||||
|
AppDialogHelpers.get().showDialog("Inscription en cours");
|
||||||
|
|
||||||
|
viewModelScope.launch {
|
||||||
|
// Preparer le DTO à envoyer dans request body
|
||||||
|
// Le DTO qui contient : email et password
|
||||||
|
val signUpRequestDTO = SignUpRequestDTO(email.value, pseudo.value, password.value,
|
||||||
|
passwordConfirm.value, cityCode.value, city.value, phone.value);
|
||||||
|
|
||||||
|
// Appel api async
|
||||||
|
val responseService = AuthService.AuthApi.authService.signup(signUpRequestDTO);
|
||||||
|
|
||||||
|
// Fermer la popup de chargement aprés l'appel de API
|
||||||
|
AppDialogHelpers.get().closeDialog()
|
||||||
|
|
||||||
|
// Si connexion ok
|
||||||
|
if (responseService.code.equals("200")){
|
||||||
|
//AlertDialogHelpers.get().show(responseService.message, onClose = { onSuccess() })
|
||||||
|
AlertDialogHelpers.get().show(responseService.message, onClose = {})
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// Erreur
|
||||||
|
AlertDialogHelpers.get().show(responseService.message, onClose = {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user