Class: Appwrite::Account

Inherits:
Service show all
Defined in:
lib/appwrite/services/account.rb

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Appwrite::Service

Instance Method Details

#create_phone_verificationToken

Use this endpoint to send a verification message to your user’s phone number to confirm they are the valid owners of that address. The provided secret should 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#accountUpdatePhoneVerification). The verification link sent to the user’s phone number is valid for 15 minutes.

Returns:

  • (Token)


606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# File 'lib/appwrite/services/account.rb', line 606

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.

Parameters:

Returns:

  • (Token)


267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/appwrite/services/account.rb', line 267

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#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.

Parameters:

Returns:

  • (Token)


534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/appwrite/services/account.rb', line 534

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.

Parameters:

  • session_id (string)

    Session ID. Use the string 'current' to delete the current device session.

Returns:



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/appwrite/services/account.rb', line 467

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_sessionsObject

Delete all sessions from the user account and remove any sessions cookies from the end client.

Returns:



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/appwrite/services/account.rb', line 380

def delete_sessions()
    path = '/account/sessions'

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#getUser

Get currently logged in user data as JSON object.

Returns:

  • (User)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/appwrite/services/account.rb', line 11

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.

Parameters:

  • limit (number) (defaults to: nil)

    Maximum number of logs to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

Returns:

  • (LogList)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/appwrite/services/account.rb', line 79

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_prefsPreferences

Get currently logged in user preferences as a key-value object.

Returns:

  • (Preferences)


204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/appwrite/services/account.rb', line 204

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.

Parameters:

  • session_id (string)

    Session ID. Use the string 'current' to get the current device session.

Returns:

  • (Session)


404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/appwrite/services/account.rb', line 404

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_sessionsSessionList

Get currently logged in user list of active sessions across different devices.

Returns:

  • (SessionList)


356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/appwrite/services/account.rb', line 356

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.

Parameters:

  • email (string)

    User email.

  • password (string)

    User password. Must be at least 8 chars.

Returns:

  • (User)


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
70
# File 'lib/appwrite/services/account.rb', line 43

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.

Parameters:

  • name (string)

    User name. Max length: 128 chars.

Returns:

  • (User)


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/appwrite/services/account.rb', line 105

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.

Parameters:

  • password (string)

    New user password. Must be at least 8 chars.

  • old_password (string) (defaults to: nil)

    Current user password. Must be at least 8 chars.

Returns:

  • (User)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/appwrite/services/account.rb', line 137

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_phone(number:, password:) ⇒ User

Update currently logged in user account phone number. After changing phone number, the user confirmation status will get reset. A new confirmation SMS is not sent automatically however you can use the phone confirmation endpoint again to send the confirmation SMS.

Parameters:

  • number (string)

    Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.

  • password (string)

    User password. Must be at least 8 chars.

Returns:

  • (User)


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/appwrite/services/account.rb', line 171

def update_phone(number:, password:)
    if number.nil?
        raise Appwrite::Exception.new('Missing required parameter: "number"')
    end

    if password.nil?
        raise Appwrite::Exception.new('Missing required parameter: "password"')
    end

    path = '/account/phone'

    params = {
        number: number,
        password: password,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: 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.

Parameters:

  • user_id (string)

    User ID.

  • secret (string)

    Valid verification token.

Returns:

  • (Token)


634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/appwrite/services/account.rb', line 634

def update_phone_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/phone'

    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:) ⇒ 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.

Parameters:

  • prefs (object)

    Prefs key-value JSON object.

Returns:

  • (User)


230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/appwrite/services/account.rb', line 230

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.

Parameters:

  • user_id (string)

    User ID.

  • secret (string)

    Valid reset token.

  • password (string)

    New user password. Must be at least 8 chars.

  • password_again (string)

    Repeat new user password. Must be at least 8 chars.

Returns:

  • (Token)


312
313
314
315
316
317
318
319
320
321
322
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
# File 'lib/appwrite/services/account.rb', line 312

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.

Parameters:

  • session_id (string)

    Session ID. Use the string 'current' to update the current device session.

Returns:

  • (Session)


435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/appwrite/services/account.rb', line 435

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_statusUser

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.

Returns:

  • (User)


496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/appwrite/services/account.rb', line 496

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.

Parameters:

  • user_id (string)

    User ID.

  • secret (string)

    Valid verification token.

Returns:

  • (Token)


567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/appwrite/services/account.rb', line 567

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