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_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 ⇒ Account
Get currently logged in user data as JSON object.
-
#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.
-
#initialize(client) ⇒ Account
constructor
A new instance of Account.
-
#list_logs(queries: nil) ⇒ LogList
Get currently logged in user list of latest security activity logs.
-
#list_sessions ⇒ SessionList
Get currently logged in user list of active sessions across different devices.
-
#update_email(email:, password:) ⇒ Account
Update currently logged in user account email address.
-
#update_name(name:) ⇒ Account
Update currently logged in user account name.
-
#update_password(password:, old_password: nil) ⇒ Account
Update currently logged in user password.
-
#update_phone(phone:, password:) ⇒ Account
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:) ⇒ Account
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 ⇒ Account
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.
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/appwrite/services/account.rb', line 625 def create_phone_verification() path = '/account/verification/phone' params = { } headers = { "content-type": 'application/json', } @client.call( method: 'POST', path: path, headers: headers, params: 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.
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 |
# File 'lib/appwrite/services/account.rb', line 277 def create_recovery(email:, url:) 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 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#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.
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/appwrite/services/account.rb', line 552 def create_verification(url:) path = '/account/verification' if url.nil? raise Appwrite::Exception.new('Missing required parameter: "url"') end 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.
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/appwrite/services/account.rb', line 483 def delete_session(session_id:) path = '/account/sessions/{sessionId}' .gsub('{sessionId}', session_id) if session_id.nil? raise Appwrite::Exception.new('Missing required parameter: "sessionId"') end 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.
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/appwrite/services/account.rb', line 393 def delete_sessions() path = '/account/sessions' params = { } headers = { "content-type": 'application/json', } @client.call( method: 'DELETE', path: path, headers: headers, params: params, ) end |
#get ⇒ Account
Get currently logged in user data as JSON object.
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() path = '/account' params = { } headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: path, headers: headers, params: params, response_type: Models::Account ) end |
#get_prefs ⇒ Preferences
Get currently logged in user preferences as a key-value object.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/appwrite/services/account.rb', line 212 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.
418 419 420 421 422 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 418 def get_session(session_id:) path = '/account/sessions/{sessionId}' .gsub('{sessionId}', session_id) if session_id.nil? raise Appwrite::Exception.new('Missing required parameter: "sessionId"') end params = { } headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: path, headers: headers, params: params, response_type: Models::Session ) end |
#list_logs(queries: 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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/appwrite/services/account.rb', line 83 def list_logs(queries: nil) path = '/account/logs' params = { queries: queries, } headers = { "content-type": 'application/json', } @client.call( method: 'GET', path: path, headers: headers, params: params, response_type: Models::LogList ) end |
#list_sessions ⇒ SessionList
Get currently logged in user list of active sessions across different devices.
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/appwrite/services/account.rb', line 368 def list_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:) ⇒ Account
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:) 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 params = { email: email, password: password, } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::Account ) end |
#update_name(name:) ⇒ Account
Update currently logged in user account name.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/appwrite/services/account.rb', line 109 def update_name(name:) path = '/account/name' if name.nil? raise Appwrite::Exception.new('Missing required parameter: "name"') end params = { name: name, } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::Account ) end |
#update_password(password:, old_password: nil) ⇒ Account
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.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/appwrite/services/account.rb', line 142 def update_password(password:, old_password: nil) path = '/account/password' if password.nil? raise Appwrite::Exception.new('Missing required parameter: "password"') end params = { password: password, oldPassword: old_password, } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::Account ) end |
#update_phone(phone:, password:) ⇒ Account
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.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/appwrite/services/account.rb', line 178 def update_phone(phone:, password:) 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 params = { phone: phone, password: password, } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::Account ) 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.
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
# File 'lib/appwrite/services/account.rb', line 654 def update_phone_verification(user_id:, secret:) 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 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 |
#update_prefs(prefs:) ⇒ Account
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.
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/appwrite/services/account.rb', line 239 def update_prefs(prefs:) path = '/account/prefs' if prefs.nil? raise Appwrite::Exception.new('Missing required parameter: "prefs"') end params = { prefs: prefs, } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::Account ) 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.
323 324 325 326 327 328 329 330 331 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 360 |
# File 'lib/appwrite/services/account.rb', line 323 def update_recovery(user_id:, secret:, password:, password_again:) 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 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.
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/appwrite/services/account.rb', line 450 def update_session(session_id:) path = '/account/sessions/{sessionId}' .gsub('{sessionId}', session_id) if session_id.nil? raise Appwrite::Exception.new('Missing required parameter: "sessionId"') end params = { } headers = { "content-type": 'application/json', } @client.call( method: 'PATCH', path: path, headers: headers, params: params, response_type: Models::Session ) end |
#update_status ⇒ Account
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.
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/appwrite/services/account.rb', line 513 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::Account ) 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.
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
# File 'lib/appwrite/services/account.rb', line 586 def update_verification(user_id:, secret:) 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 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 |