userOperator
This module provides user operator management functionality for the Smart1 SDK.
Overview
The userOperator module allows you to:
Register new user operators
Get user operator profiles
Delete user operator accounts
Main Components
RegisterUserOperator
Registers a new user operator in the system.
Parameters:
temporalToken: String- Temporal token for the registration requestregistrationUserOperatorData: RegistrationUserOperatorData- User registration data
Returns: ResultS1SDK<Boolean, ErrorS1SDK>
GetUserOperatorProfile
Retrieves the profile of the current user operator.
Returns: ResultS1SDK<UserOperatorProfile, ErrorS1SDK>
DeleteUserOperatorAccount
Deletes the current user operator account.
Returns: ResultS1SDK<Boolean, ErrorS1SDK>
Models
RegistrationUserOperatorData
Data required for user operator registration.
Properties:
name: String- User's first name (4-50 chars)lastname: String- User's last name (4-150 chars)identification: String- User's identification (4-150 chars)email: String- User's emailphone: String- User's phone numberpassword: String- User's password (>= 12 chars)
UserOperatorProfile
Complete user operator profile information.
Properties:
id: Long- User IDidentification: String- User identificationcompanyId: List<Long>- Company IDs the user belongs toname: String- First namelastname: String- Last nameusername: String- Usernameemail: String- Email addressphone: String- Phone numberimageUrl: String- Profile image URLroleName: String- Role nameuid: String- User UIDoperatorId: List<Long>- Operator IDs (for multi-company registration)
Usage Examples
Register New User Operator
import com.servinformacion.smart1sdk.android.user_operator.RegisterUserOperator
import com.servinformacion.smart1sdk.android.user_operator.model.RegistrationUserOperatorData
import com.servinformacion.smart1sdk.android.core.ResultS1SDK
class RegistrationViewModel : ViewModel() {
private val registerUserOperator = RegisterUserOperator()
suspend fun registerUser(
temporalToken: String,
name: String,
lastname: String,
identification: String,
email: String,
phone: String,
password: String
) {
val registrationData = RegistrationUserOperatorData(
name = name,
lastname = lastname,
identification = identification,
email = email,
phone = phone,
password = password
)
val result = registerUserOperator(
temporalToken = temporalToken,
registrationUserOperatorData = registrationData
)
when (result) {
is ResultS1SDK.Success -> {
println("User registered successfully")
// Navigate to login or main screen
}
is ResultS1SDK.Error -> {
println("Registration failed: ${result.error}")
}
}
}
}Get User Profile
import com.servinformacion.smart1sdk.android.user_operator.GetUserOperatorProfile
class ProfileViewModel : ViewModel() {
private val getUserProfile = GetUserOperatorProfile()
suspend fun loadUserProfile() {
val result = getUserProfile()
when (result) {
is ResultS1SDK.Success -> {
val profile = result.data
println("Name: ${profile.name} ${profile.lastname}")
println("Username: ${profile.username}")
println("Email: ${profile.email}")
println("Phone: ${profile.phone}")
println("Profile Image: ${profile.imageUrl}")
println("Role: ${profile.roleName}")
println("Companies: ${profile.companyId}")
// Update UI with profile data
}
is ResultS1SDK.Error -> {
println("Failed to load profile: ${result.error}")
}
}
}
}Delete User Account
import com.servinformacion.smart1sdk.android.user_operator.DeleteUserOperatorAccount
suspend fun deleteAccount() {
val deleteAccount = DeleteUserOperatorAccount()
val result = deleteAccount()
when (result) {
is ResultS1SDK.Success -> {
println("Account deleted successfully")
// Navigate to login screen
}
is ResultS1SDK.Error -> {
println("Failed to delete account: ${result.error}")
}
}
}Profile Management Screen
class ProfileManagementViewModel : ViewModel() {
private val getProfile = GetUserOperatorProfile()
private val deleteAccount = DeleteUserOperatorAccount()
private val _profileState = MutableStateFlow<ProfileState>(ProfileState.Loading)
val profileState: StateFlow<ProfileState> = _profileState
fun loadProfile() {
viewModelScope.launch {
_profileState.value = ProfileState.Loading
val result = getProfile()
_profileState.value = when (result) {
is ResultS1SDK.Success -> ProfileState.Loaded(result.data)
is ResultS1SDK.Error -> ProfileState.Error(result.error)
}
}
}
fun requestAccountDeletion() {
viewModelScope.launch {
val result = deleteAccount()
when (result) {
is ResultS1SDK.Success -> {
// Account deleted, navigate to login
_profileState.value = ProfileState.Deleted
}
is ResultS1SDK.Error -> {
_profileState.value = ProfileState.Error(result.error)
}
}
}
}
}
sealed class ProfileState {
object Loading : ProfileState()
data class Loaded(val profile: UserOperatorProfile) : ProfileState()
data class Error(val error: ErrorS1SDK) : ProfileState()
object Deleted : ProfileState()
}Important Notes
Temporal Tokens: Registration requires a temporal token for the request. You can use the same sdkApiKey that is used on the InitSDKConfig.
Session Required: Profile operations require an active session.
Account Deletion: Deleting an account is permanent and cannot be undone.
Password Security: Passwords must be at least 12 characters long.
Field Validation:
Name: 4-50 characters
Lastname: 4-150 characters
Identification: 4-150 characters
Best Practices
Validate Input: Validate user input before submitting registration
Secure Passwords: Enforce strong password requirements (>= 12 chars)
Error Handling: Provide clear error messages to users
Confirmation Dialogs: Confirm before deleting accounts
Profile Updates: Keep user profiles up to date
Use Cases
User Registration: Register new user operators
Profile Management: View and manage user profiles
Account Deletion: Allow users to delete their accounts