Class: Appwrite::Account
- Defined in:
- lib/appwrite/services/account.rb
Instance Method Summary collapse
-
#create_recovery(email:, url:) ⇒ Token
Sends the user an email with a temporary secret key for password reset.
-
#create_verification(url:) ⇒ Token
Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address.
-
#delete_session(session_id:) ⇒ Object
Use this endpoint to log out the currently logged in user from all their account sessions across all of their different devices.
-
#delete_sessions ⇒ Object
Delete all sessions from the user account and remove any sessions cookies from the end client.
-
#get ⇒ User
Get currently logged in user data as JSON object.
-
#get_logs(limit: nil, offset: nil) ⇒ LogList
Get currently logged in user list of latest security activity logs.
-
#get_prefs ⇒ Preferences
Get currently logged in user preferences as a key-value object.
-
#get_session(session_id:) ⇒ Session
Use this endpoint to get a logged in user’s session using a Session ID.
-
#get_sessions ⇒ SessionList
Get currently logged in user list of active sessions across different devices.
-
#update_email(email:, password:) ⇒ User
Update currently logged in user account email address.
-
#update_name(name:) ⇒ User
Update currently logged in user account name.
-
#update_password(password:, old_password: nil) ⇒ User
Update currently logged in user password.
-
#update_prefs(prefs:) ⇒ User
Update currently logged in user account preferences.
-
#update_recovery(user_id:, secret:, password:, password_again:) ⇒ Token
Use this endpoint to complete the user account password reset.
-
#update_session(session_id:) ⇒ Session
Access tokens have limited lifespan and expire to mitigate security risks.
-
#update_status ⇒ User
Block the currently logged in user account.
-
#update_verification(user_id:, secret:) ⇒ Token
Use this endpoint to complete the user email verification process.
Methods inherited from Service
Constructor Details
This class inherits a constructor from Appwrite::Service
Instance Method Details
#create_recovery(email:, url:) ⇒ Token
Sends the user an email with a temporary secret key for password reset. When the user clicks the confirmation link he is redirected back to your app password reset URL with the secret key and email address values attached to the URL query string. Use the query string params to submit a request to the [PUT /account/recovery](/docs/client/account#accountUpdateRecovery) endpoint to complete the process. The verification link sent to the user’s email address is valid for 1 hour.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/appwrite/services/account.rb', line 228 def create_recovery(email:, url:) if email.nil? raise Appwrite::Exception.new('Missing required parameter: "email"') end if url.nil? raise Appwrite::Exception.new('Missing required parameter: "url"') end path = '/account/recovery' params = { email: email, url: url, } headers = { "content-type": 'application/json', } @client.call( method: 'POST', path: path, headers: headers, params: params, response_type: Models::Token ) end |
#create_verification(url:) ⇒ Token
Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the userId and secret arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the userId and secret parameters. Learn more about how to [complete the verification process](/docs/client/account#accountUpdateVerification). The verification link sent to the user’s email address is valid for 7 days.
Please note that in order to avoid a [Redirect Attack](github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/appwrite/services/account.rb', line 495 def create_verification(url:) if url.nil? raise Appwrite::Exception.new('Missing required parameter: "url"') end path = '/account/verification' params = { url: url, } headers = { "content-type": 'application/json', } @client.call( method: 'POST', path: path, headers: headers, params: params, response_type: Models::Token ) end |
#delete_session(session_id:) ⇒ Object
Use this endpoint to log out the currently logged in user from all their account sessions across all of their different devices. When using the Session ID argument, only the unique session ID provided is deleted.
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/appwrite/services/account.rb', line 428 def delete_session(session_id:) if session_id.nil? raise Appwrite::Exception.new('Missing required parameter: "sessionId"') end path = '/account/sessions/{sessionId}' .gsub('{sessionId}', session_id) params = { } headers = { "content-type": 'application/json', } @client.call( method: 'DELETE', path: path, headers: headers, params: params, ) end |
#delete_sessions ⇒ Object
Delete all sessions from the user account and remove any sessions cookies from the end client.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/appwrite/services/account.rb', line 341 def delete_sessions() path = '/account/sessions' params = { } headers = { "content-type": 'application/json', } @client.call( method: 'DELETE', path: path, headers: headers, params: params, ) end |
#get ⇒ User
Get currently logged in user data as JSON object.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/appwrite/services/account.rb', line 10 def get() path = '/account' params = { } headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: path, headers: headers, params: params, response_type: Models::User ) end |
#get_logs(limit: nil, offset: nil) ⇒ LogList
Get currently logged in user list of latest security activity logs. Each log returns user IP address, location and date and time of log.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/appwrite/services/account.rb', line 78 def get_logs(limit: nil, offset: nil) path = '/account/logs' params = { limit: limit, offset: offset, } headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: path, headers: headers, params: params, response_type: Models::LogList ) end |
#get_prefs ⇒ Preferences
Get currently logged in user preferences as a key-value object.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/appwrite/services/account.rb', line 165 def get_prefs() path = '/account/prefs' params = { } headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: path, headers: headers, params: params, response_type: Models::Preferences ) end |
#get_session(session_id:) ⇒ Session
Use this endpoint to get a logged in user’s session using a Session ID. Inputting ‘current’ will return the current session being used.
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/appwrite/services/account.rb', line 365 def get_session(session_id:) if session_id.nil? raise Appwrite::Exception.new('Missing required parameter: "sessionId"') end path = '/account/sessions/{sessionId}' .gsub('{sessionId}', session_id) params = { } headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: path, headers: headers, params: params, response_type: Models::Session ) end |
#get_sessions ⇒ SessionList
Get currently logged in user list of active sessions across different devices.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/appwrite/services/account.rb', line 317 def get_sessions() path = '/account/sessions' params = { } headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: path, headers: headers, params: params, response_type: Models::SessionList ) end |
#update_email(email:, password:) ⇒ User
Update currently logged in user account email address. After changing user address, the user confirmation status will get reset. A new confirmation email is not sent automatically however you can use the send confirmation email endpoint again to send the confirmation email. For security measures, user password is required to complete this request. This endpoint can also be used to convert an anonymous account to a normal one, by passing an email address and a new password.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/appwrite/services/account.rb', line 42 def update_email(email:, password:) if email.nil? raise Appwrite::Exception.new('Missing required parameter: "email"') end if password.nil? raise Appwrite::Exception.new('Missing required parameter: "password"') end path = '/account/email' params = { email: email, password: password, } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::User ) end |
#update_name(name:) ⇒ User
Update currently logged in user account name.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/appwrite/services/account.rb', line 104 def update_name(name:) if name.nil? raise Appwrite::Exception.new('Missing required parameter: "name"') end path = '/account/name' params = { name: name, } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::User ) end |
#update_password(password:, old_password: nil) ⇒ User
Update currently logged in user password. For validation, user is required to pass in the new password, and the old password. For users created with OAuth, Team Invites and Magic URL, oldPassword is optional.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/appwrite/services/account.rb', line 136 def update_password(password:, old_password: nil) if password.nil? raise Appwrite::Exception.new('Missing required parameter: "password"') end path = '/account/password' params = { password: password, oldPassword: old_password, } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::User ) end |
#update_prefs(prefs:) ⇒ User
Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/appwrite/services/account.rb', line 191 def update_prefs(prefs:) if prefs.nil? raise Appwrite::Exception.new('Missing required parameter: "prefs"') end path = '/account/prefs' params = { prefs: prefs, } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::User ) end |
#update_recovery(user_id:, secret:, password:, password_again:) ⇒ Token
Use this endpoint to complete the user account password reset. Both the userId and secret arguments will be passed as query parameters to the redirect URL you have provided when sending your request to the [POST /account/recovery](/docs/client/account#accountCreateRecovery) endpoint.
Please note that in order to avoid a [Redirect Attack](github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/appwrite/services/account.rb', line 273 def update_recovery(user_id:, secret:, password:, password_again:) if user_id.nil? raise Appwrite::Exception.new('Missing required parameter: "userId"') end if secret.nil? raise Appwrite::Exception.new('Missing required parameter: "secret"') end if password.nil? raise Appwrite::Exception.new('Missing required parameter: "password"') end if password_again.nil? raise Appwrite::Exception.new('Missing required parameter: "passwordAgain"') end path = '/account/recovery' params = { userId: user_id, secret: secret, password: password, passwordAgain: password_again, } headers = { "content-type": 'application/json', } @client.call( method: 'PUT', path: path, headers: headers, params: params, response_type: Models::Token ) end |
#update_session(session_id:) ⇒ Session
Access tokens have limited lifespan and expire to mitigate security risks. If session was created using an OAuth provider, this route can be used to “refresh” the access token.
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/appwrite/services/account.rb', line 396 def update_session(session_id:) if session_id.nil? raise Appwrite::Exception.new('Missing required parameter: "sessionId"') end path = '/account/sessions/{sessionId}' .gsub('{sessionId}', session_id) params = { } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::Session ) end |
#update_status ⇒ User
Block the currently logged in user account. Behind the scene, the user record is not deleted but permanently blocked from any access. To completely delete a user, use the Users API instead.
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/appwrite/services/account.rb', line 457 def update_status() path = '/account/status' params = { } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::User ) end |
#update_verification(user_id:, secret:) ⇒ Token
Use this endpoint to complete the user email verification process. Use both the userId and secret parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/appwrite/services/account.rb', line 528 def update_verification(user_id:, secret:) if user_id.nil? raise Appwrite::Exception.new('Missing required parameter: "userId"') end if secret.nil? raise Appwrite::Exception.new('Missing required parameter: "secret"') end path = '/account/verification' params = { userId: user_id, secret: secret, } headers = { "content-type": 'application/json', } @client.call( method: 'PUT', path: path, headers: headers, params: params, response_type: Models::Token ) end |