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_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 endpoint to complete the process. The verification link sent to the user's email address is valid for 1 hour.

Parameters:

  • email (string) —

    User email.

  • url (string) —

    URL to redirect the user back to your app from the recovery email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an open redirect attack against your project API.

Returns:

  • (Token)


254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/appwrite/services/account.rb', line 254

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. 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, the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.

Parameters:

  • url (string) —

    URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an open redirect attack against your project API.

Returns:

  • (Token)


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

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 ⇒ Object

Delete a currently logged in user account. Behind the scene, the user record is not deleted but permanently blocked from any access. This is done to avoid deleted accounts being overtaken by new users with the same email address. Any user-related resources like documents or storage files should be deleted separately.

Returns:

  • []



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/appwrite/services/account.rb', line 37

def delete()
    path = '/account'

    params = {
    }

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

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

  • []



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/appwrite/services/account.rb', line 452

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.

Returns:

  • []



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/appwrite/services/account.rb', line 367

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.

Returns:

  • (User)


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.

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

Returns:

  • (LogList)


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

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.

Returns:

  • (Preferences)


191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/appwrite/services/account.rb', line 191

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)


391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/appwrite/services/account.rb', line 391

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.

Returns:

  • (SessionList)


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 343

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)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/appwrite/services/account.rb', line 68

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)


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/appwrite/services/account.rb', line 130

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 and Team Invites, 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)


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/appwrite/services/account.rb', line 162

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.

Parameters:

  • prefs (object) —

    Prefs key-value JSON object.

Returns:

  • (User)


217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/appwrite/services/account.rb', line 217

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

Please note that in order to avoid a Redirect Attack 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)


299
300
301
302
303
304
305
306
307
308
309
310
311
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
# File 'lib/appwrite/services/account.rb', line 299

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

Parameters:

  • session_id (string) —

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

Returns:

  • (Session)


420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/appwrite/services/account.rb', line 420

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_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)


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

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