Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Get all users
  • Get one/create/modify/delete user
  • Verify email/phone with code or link (primary ones)
  • Get/update/delete custom user fields (dictionary with any keys/values)
  • Get/update user enterprise
  • Get password requirements (min and max password length)
  • Get user's legal info
  • Migrate user to other namespace
  • Change password
  • Get/update custom permission
  • Get/update builtin and custom roles
  • Get/report strong identification
  • Get/update student info

User management

Code Block
languagepy
from trivoreid.utils.criteria import Filter
from trivoreid.models.email import EmailAddress
from trivoreid.models.user import (User,
                                   Names,
                                   Mobile,
                                   Address)

# get list of users
users = api.user_service.get_all(Filter(Filter.EQUAL, 'nsCode', 'examplecode')).resources

# create new user object
user_to_create = User({
		'nsCode' : 'testsdk',
		'emails' : ['example1@trivore.com'],
		'memberOf' : ['gr003', 'gr004'] # if groups with user's nsCode and member
										# names don't exist, they will be created
		})


user_names = Names({
		'givenName' : 'First Name',
		'middleName' : 'Middle Name',
		'familyName' : 'Last Name'})

user_addresses = [Address({
		'addressName' : 'address',
		'name' : 'home',
		'country' : 'FI',
		'locality' : 'fi',
		'postalCode' : '20750',
		'region' : 'Region',
		'streetAddress' : 'Street Address 5C'})]

email1 = EmailAddress({'address' : 'example1@trivore.com'})
email2 = EmailAddress({'address' : 'example2@trivore.com',
							'tags' : ['tag1', 'tag2'], 'name' : 'work'})

user_emails = [email1, email2]

mobile1 = Mobile({'number' : '+358402592078'})
mobile2 = Mobile({'number' : '+358402592077',
							'tags' : ['tag1', 'tag2'], 'name' : 'work'})

user_mobiles = [mobile1, mobile2]

user_to_create.name = user_names
user_to_create.addresses = user_addresses
user_to_create.emails = user_emails
user_to_create.mobiles = user_mobiles

# user service returns new user object and a randomly generated password with
# the defined length (15 by default).
new_user = api.user_service.create(user_to_create, password_length=30)[0]

user = api.user_service.get(new_user.user_fields['id'])

print('Password : {}'.format(new_user.serialize()['password']))
print('\n User fields \n {}'.format(user.serialize()))

# deleting user account
api.user_service.delete(user.user_fields['id'])

# creating multiple users
user_list = []
for _ in range(5):
	user_list.append(User({'nsCode' : 'testsdk'}))

# result is the list of created users
result = api.user_service.create(user_list)

...

Code Block
languagepy
from trivoreid.models.user import Consents

user = api.user_servise.get('userID')

# modify user consents
user.consents.marketingPost = True
user.consents.marketingOther = True
user.consents.profiling = True

api.user_service.update(user)

User Service Models

...

Migrate namespace

Warning: Original user will be deleted and another will be created in the target namespace. Not all information will be migrated!

Code Block
languagepy
from trivoreid.models.user import NamespaceMigrationOptions

user = api.user_servise.get('userID')

# migrate user to the exampleCode namespace
options = NamespaceMigrationOptions()
options.keepMobiles = False
options.targetNsCode = 'exampleCode'

# 
user = api.user_servise.migrate_namespace(user.id, options)

Legal info

Code Block
languagepy
user = api.user_servise.get('userID')

# get user's legal info
info = api.user_servise.get_legal_info(user.id)

Student state

Code Block
languagepy
from trivoreid.models.user import StudentState, StudentStatus

user = api.user_servise.get('userID')

# get user's legal info
state = api.user_service.get_student_state(user.id)

# update student state of the user
state.state = StudentStatus.FULL_TIME
state = api.user_service.update_student_state(user.id, state)

User Service Models

/wiki/spaces/TISpubdoc/pages/20515245

/wiki/spaces/TISpubdoc/pages/20515276

Names

Mobile/wiki/spaces/TISpubdoc/pages/20515253

/wiki/spaces/TISpubdoc/pages/20515254

/wiki/spaces/TISpubdoc/pages/20515250

...

/wiki/spaces/TISpubdoc/pages/20515252

/wiki/spaces/TISpubdoc/pages/75825224

/wiki/spaces/TISpubdoc/pages/85491757

/wiki/spaces/TISpubdoc/pages/88277051