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 request

  • registrationUserOperatorData: 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 email

  • phone: String - User's phone number

  • password: String - User's password (>= 12 chars)

UserOperatorProfile

Complete user operator profile information.

Properties:

  • id: Long - User ID

  • identification: String - User identification

  • companyId: List<Long> - Company IDs the user belongs to

  • name: String - First name

  • lastname: String - Last name

  • username: String - Username

  • email: String - Email address

  • phone: String - Phone number

  • imageUrl: String - Profile image URL

  • roleName: String - Role name

  • uid: String - User UID

  • operatorId: 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

  1. Temporal Tokens: Registration requires a temporal token for the request. You can use the same sdkApiKey that is used on the InitSDKConfig.

  2. Session Required: Profile operations require an active session.

  3. Account Deletion: Deleting an account is permanent and cannot be undone.

  4. Password Security: Passwords must be at least 12 characters long.

  5. Field Validation:

    • Name: 4-50 characters

    • Lastname: 4-150 characters

    • Identification: 4-150 characters

Best Practices

  1. Validate Input: Validate user input before submitting registration

  2. Secure Passwords: Enforce strong password requirements (>= 12 chars)

  3. Error Handling: Provide clear error messages to users

  4. Confirmation Dialogs: Confirm before deleting accounts

  5. 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

Packages