Registers a new user for the caller identity.
(
&self,
input: RegisterUserInput,
ctx: &CallContext,
)
| 85 | |
| 86 | /// Registers a new user for the caller identity. |
| 87 | pub async fn register_user( |
| 88 | &self, |
| 89 | input: RegisterUserInput, |
| 90 | ctx: &CallContext, |
| 91 | ) -> ServiceResult<User, ApiError> { |
| 92 | self.assert_identity_is_unregistered(&ctx.caller())?; |
| 93 | |
| 94 | if ctx.caller() == Principal::anonymous() { |
| 95 | Err(UserError::ValidationError { |
| 96 | info: "The caller identity cannot be anonymous.".to_string(), |
| 97 | })? |
| 98 | } |
| 99 | |
| 100 | let user_id = generate_uuid_v4().await; |
| 101 | let user_identity = ctx.caller(); |
| 102 | let user = User::new_from_register_input(*user_id.as_bytes(), input.clone(), user_identity); |
| 103 | |
| 104 | user.validate()?; |
| 105 | self.user_repository.insert(UserKey(user.id), user.clone()); |
| 106 | |
| 107 | Ok(user) |
| 108 | } |
| 109 | |
| 110 | pub async fn remove_user( |
| 111 | &self, |
no test coverage detected