diff --git a/app/src/main/java/dev/passwordless/sampleapp/AddCredentialFragment.kt b/app/src/main/java/dev/passwordless/sampleapp/AddCredentialFragment.kt index 420435d..43d8329 100644 --- a/app/src/main/java/dev/passwordless/sampleapp/AddCredentialFragment.kt +++ b/app/src/main/java/dev/passwordless/sampleapp/AddCredentialFragment.kt @@ -13,6 +13,7 @@ import dagger.hilt.android.AndroidEntryPoint import dev.passwordless.android.PasswordlessClient import dev.passwordless.android.utils.PasswordlessUtils import dev.passwordless.sampleapp.auth.Session +import dev.passwordless.sampleapp.contracts.AddCredentialRequest import dev.passwordless.sampleapp.contracts.UserRegisterRequest import dev.passwordless.sampleapp.databinding.FragmentAddCredentialBinding import dev.passwordless.sampleapp.yourbackend.YourBackendHttpClient @@ -54,8 +55,7 @@ class AddCredentialFragment : Fragment() { val alias = binding.aliasEditText.text.toString() val username = session.getUsername()!! try { - val response = - httpClient.register(UserRegisterRequest(username, alias)).body()?.token!! + val response = httpClient.addCredential(session.getUserId()!!, AddCredentialRequest(alias)).body()?.token!! passwordless.register( response, alias + username diff --git a/app/src/main/java/dev/passwordless/sampleapp/RegisterFragment.kt b/app/src/main/java/dev/passwordless/sampleapp/RegisterFragment.kt index 307314d..809f987 100644 --- a/app/src/main/java/dev/passwordless/sampleapp/RegisterFragment.kt +++ b/app/src/main/java/dev/passwordless/sampleapp/RegisterFragment.kt @@ -56,13 +56,14 @@ class RegisterFragment : Fragment() { lifecycleScope.launch { val alias = binding.aliasEditText.text.toString() val username = binding.usernameEditText.text.toString() + val firstName = binding.firstNameEditText.text.toString() + val lastName = binding.lastNameEditText.text.toString() try { - val responseToken = - httpClient.register(UserRegisterRequest(username, alias)).body()?.token!! + val registerRequest = UserRegisterRequest(username, alias, firstName, lastName) + val responseToken = httpClient.register(registerRequest).body()?.token!! _passwordless.register( responseToken, - alias + username - ) { success, exception, result -> + alias + username) { success, exception, result -> if (success) { Toast.makeText(context, result.toString(), Toast.LENGTH_SHORT).show() } else { diff --git a/app/src/main/java/dev/passwordless/sampleapp/contracts/AddCredentialResponse.kt b/app/src/main/java/dev/passwordless/sampleapp/contracts/AddCredentialResponse.kt new file mode 100644 index 0000000..6f98426 --- /dev/null +++ b/app/src/main/java/dev/passwordless/sampleapp/contracts/AddCredentialResponse.kt @@ -0,0 +1,3 @@ +package dev.passwordless.sampleapp.contracts + +data class AddCredentialResponse(val token: String) \ No newline at end of file diff --git a/app/src/main/java/dev/passwordless/sampleapp/contracts/UserRegisterRequest.kt b/app/src/main/java/dev/passwordless/sampleapp/contracts/UserRegisterRequest.kt index 30f49ae..34783e6 100644 --- a/app/src/main/java/dev/passwordless/sampleapp/contracts/UserRegisterRequest.kt +++ b/app/src/main/java/dev/passwordless/sampleapp/contracts/UserRegisterRequest.kt @@ -2,5 +2,7 @@ package dev.passwordless.sampleapp.contracts data class UserRegisterRequest( val username:String, - val alias: String + val alias: String, + val firstName: String, + val lastName: String ) diff --git a/app/src/main/java/dev/passwordless/sampleapp/yourbackend/YourBackendHttpClient.kt b/app/src/main/java/dev/passwordless/sampleapp/yourbackend/YourBackendHttpClient.kt index 603d942..4d1e31e 100644 --- a/app/src/main/java/dev/passwordless/sampleapp/yourbackend/YourBackendHttpClient.kt +++ b/app/src/main/java/dev/passwordless/sampleapp/yourbackend/YourBackendHttpClient.kt @@ -1,5 +1,7 @@ package dev.passwordless.sampleapp.yourbackend +import dev.passwordless.sampleapp.contracts.AddCredentialRequest +import dev.passwordless.sampleapp.contracts.AddCredentialResponse import dev.passwordless.sampleapp.contracts.CredentialResponse import dev.passwordless.sampleapp.contracts.RegisterTokenResponse import dev.passwordless.sampleapp.contracts.UserLoginRequest @@ -17,4 +19,7 @@ interface YourBackendHttpClient { @GET("/users/{userId}/credentials") suspend fun getCredentials(@Path("userId") userId: String): Response> + + @POST("/users/{userId}/credentials") + suspend fun addCredential(@Path("userId") userId: String, @Body request: AddCredentialRequest): Response } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_register.xml b/app/src/main/res/layout/fragment_register.xml index 355ef1e..88bc2a8 100644 --- a/app/src/main/res/layout/fragment_register.xml +++ b/app/src/main/res/layout/fragment_register.xml @@ -17,13 +17,36 @@ + + + android:gravity="center" + android:hint="@string/firstname_hint" + android:inputType="text" + android:maxLength="30" /> + + + android:inputType="text" + android:maxLength="20" /> Passwordless.dev Android Sample Settings - Registration Login Credentials @@ -12,6 +11,8 @@ Previous Username + First Name + Last Name Alias Alias (optional) When \'alias\' is left empty, your credential will be discoverable. You won\'t have to enter the \'alias\' value entered previously to log in.