Class: Appwrite::Account
- Defined in:
- lib/appwrite/services/account.rb
Instance Method Summary collapse
-
#create_phone_verification ⇒ Token
Use this endpoint to send a verification SMS to the currently logged in user.
-
#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_identity(identity_id:) ⇒ Object
Delete an identity by its unique ID.
-
#delete_session(session_id:) ⇒ Object
Logout the user.
-
#delete_sessions ⇒ Object
Delete all sessions from the user account and remove any sessions cookies from the end client.
-
#get ⇒ User
Get the currently logged in user.
-
#get_prefs ⇒ Preferences
Get the preferences as a key-value object for the currently logged in user.
-
#get_session(session_id:) ⇒ Session
Use this endpoint to get a logged in user’s session using a Session ID.
-
#initialize(client) ⇒ Account
constructor
A new instance of Account.
-
#list_identities(queries: nil) ⇒ IdentityList
Get the list of identities for the currently logged in user.
-
#list_logs(queries: nil) ⇒ LogList
Get the list of latest security activity logs for the currently logged in user.
-
#list_sessions ⇒ SessionList
Get the list of active sessions across different devices for the currently logged in user.
-
#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_phone(phone:, password:) ⇒ User
Update the currently logged in user’s phone number.
-
#update_phone_verification(user_id:, secret:) ⇒ Token
Use this endpoint to complete the user phone verification process.
-
#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.
Constructor Details
#initialize(client) ⇒ Account
Returns a new instance of Account.
6 7 8 |
# File 'lib/appwrite/services/account.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#create_phone_verification ⇒ Token
Use this endpoint to send a verification SMS to the currently logged in user. This endpoint is meant for use after updating a user’s phone number using the [accountUpdatePhone](/docs/client/account#accountUpdatePhone) endpoint. Learn more about how to [complete the verification process](/docs/client/account#accountUpdatePhoneVerification). The verification code sent to the user’s phone number is valid for 15 minutes.
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/appwrite/services/account.rb', line 680 def create_phone_verification() api_path = '/account/verification/phone' api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Token ) end |
#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.
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/appwrite/services/account.rb', line 332 def create_recovery(email:, url:) api_path = '/account/recovery' if email.nil? raise Appwrite::Exception.new('Missing required parameter: "email"') end if url.nil? raise Appwrite::Exception.new('Missing required parameter: "url"') end api_params = { email: email, url: url, } api_headers = { "content-type": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_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#accountUpdateEmailVerification). 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.
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
# File 'lib/appwrite/services/account.rb', line 607 def create_verification(url:) api_path = '/account/verification' if url.nil? raise Appwrite::Exception.new('Missing required parameter: "url"') end api_params = { url: url, } api_headers = { "content-type": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Token ) end |
#delete_identity(identity_id:) ⇒ Object
Delete an identity by its unique ID.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/appwrite/services/account.rb', line 108 def delete_identity(identity_id:) api_path = '/account/identities/{identityId}' .gsub('{identityId}', identity_id) if identity_id.nil? raise Appwrite::Exception.new('Missing required parameter: "identityId"') end api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'DELETE', path: api_path, headers: api_headers, params: api_params, ) end |
#delete_session(session_id:) ⇒ Object
Logout the user. Use ‘current’ as the session ID to logout on this device, use a session ID to logout on another device. If you’re looking to logout the user on all devices, use [Delete Sessions](/docs/client/account#accountDeleteSessions) instead.
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/appwrite/services/account.rb', line 538 def delete_session(session_id:) api_path = '/account/sessions/{sessionId}' .gsub('{sessionId}', session_id) if session_id.nil? raise Appwrite::Exception.new('Missing required parameter: "sessionId"') end api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'DELETE', path: api_path, headers: api_headers, params: api_params, ) end |
#delete_sessions ⇒ Object
Delete all sessions from the user account and remove any sessions cookies from the end client.
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/appwrite/services/account.rb', line 448 def delete_sessions() api_path = '/account/sessions' api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'DELETE', path: api_path, headers: api_headers, params: api_params, ) end |
#get ⇒ User
Get the currently logged in user.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/appwrite/services/account.rb', line 14 def get() api_path = '/account' api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::User ) end |
#get_prefs ⇒ Preferences
Get the preferences as a key-value object for the currently logged in user.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/appwrite/services/account.rb', line 267 def get_prefs() api_path = '/account/prefs' api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_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.
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/appwrite/services/account.rb', line 473 def get_session(session_id:) api_path = '/account/sessions/{sessionId}' .gsub('{sessionId}', session_id) if session_id.nil? raise Appwrite::Exception.new('Missing required parameter: "sessionId"') end api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::Session ) end |
#list_identities(queries: nil) ⇒ IdentityList
Get the list of identities for the currently logged in user.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/appwrite/services/account.rb', line 82 def list_identities(queries: nil) api_path = '/account/identities' api_params = { queries: queries, } api_headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::IdentityList ) end |
#list_logs(queries: nil) ⇒ LogList
Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/appwrite/services/account.rb', line 138 def list_logs(queries: nil) api_path = '/account/logs' api_params = { queries: queries, } api_headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::LogList ) end |
#list_sessions ⇒ SessionList
Get the list of active sessions across different devices for the currently logged in user.
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/appwrite/services/account.rb', line 423 def list_sessions() api_path = '/account/sessions' api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_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.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/appwrite/services/account.rb', line 47 def update_email(email:, password:) api_path = '/account/email' if email.nil? raise Appwrite::Exception.new('Missing required parameter: "email"') end if password.nil? raise Appwrite::Exception.new('Missing required parameter: "password"') end api_params = { email: email, password: password, } api_headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: api_path, headers: api_headers, params: api_params, response_type: Models::User ) end |
#update_name(name:) ⇒ User
Update currently logged in user account name.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/appwrite/services/account.rb', line 164 def update_name(name:) api_path = '/account/name' if name.nil? raise Appwrite::Exception.new('Missing required parameter: "name"') end api_params = { name: name, } api_headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: api_path, headers: api_headers, params: api_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.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/appwrite/services/account.rb', line 197 def update_password(password:, old_password: nil) api_path = '/account/password' if password.nil? raise Appwrite::Exception.new('Missing required parameter: "password"') end api_params = { password: password, oldPassword: old_password, } api_headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: api_path, headers: api_headers, params: api_params, response_type: Models::User ) end |
#update_phone(phone:, password:) ⇒ User
Update the currently logged in user’s phone number. After updating the phone number, the phone verification status will be reset. A confirmation SMS is not sent automatically, however you can use the [POST /account/verification/phone](/docs/client/account#accountCreatePhoneVerification) endpoint to send a confirmation SMS.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/appwrite/services/account.rb', line 233 def update_phone(phone:, password:) api_path = '/account/phone' if phone.nil? raise Appwrite::Exception.new('Missing required parameter: "phone"') end if password.nil? raise Appwrite::Exception.new('Missing required parameter: "password"') end api_params = { phone: phone, password: password, } api_headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: api_path, headers: api_headers, params: api_params, response_type: Models::User ) end |
#update_phone_verification(user_id:, secret:) ⇒ Token
Use this endpoint to complete the user phone verification process. Use the userId and secret that were sent to your user’s phone number to verify the user email ownership. If confirmed this route will return a 200 status code.
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
# File 'lib/appwrite/services/account.rb', line 709 def update_phone_verification(user_id:, secret:) api_path = '/account/verification/phone' 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 api_params = { userId: user_id, secret: secret, } api_headers = { "content-type": 'application/json', } @client.call( method: 'PUT', path: api_path, headers: api_headers, params: api_params, response_type: Models::Token ) 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.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/appwrite/services/account.rb', line 294 def update_prefs(prefs:) api_path = '/account/prefs' if prefs.nil? raise Appwrite::Exception.new('Missing required parameter: "prefs"') end api_params = { prefs: prefs, } api_headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: api_path, headers: api_headers, params: api_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.
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/appwrite/services/account.rb', line 378 def update_recovery(user_id:, secret:, password:, password_again:) api_path = '/account/recovery' 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 api_params = { userId: user_id, secret: secret, password: password, passwordAgain: password_again, } api_headers = { "content-type": 'application/json', } @client.call( method: 'PUT', path: api_path, headers: api_headers, params: api_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.
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/appwrite/services/account.rb', line 505 def update_session(session_id:) api_path = '/account/sessions/{sessionId}' .gsub('{sessionId}', session_id) if session_id.nil? raise Appwrite::Exception.new('Missing required parameter: "sessionId"') end api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: api_path, headers: api_headers, params: api_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.
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/appwrite/services/account.rb', line 568 def update_status() api_path = '/account/status' api_params = { } api_headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: api_path, headers: api_headers, params: api_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.
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
# File 'lib/appwrite/services/account.rb', line 641 def update_verification(user_id:, secret:) api_path = '/account/verification' 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 api_params = { userId: user_id, secret: secret, } api_headers = { "content-type": 'application/json', } @client.call( method: 'PUT', path: api_path, headers: api_headers, params: api_params, response_type: Models::Token ) end |