diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e337941..c25e6670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 19.1.0 + +* Deprecate `createVerification` method in `Account` service +* Add `createEmailVerification` method in `Account` service + ## 18.1.0 * Add `orderRandom` query support diff --git a/README.md b/README.md index 40a3279f..8bc658f6 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - dart_appwrite: ^19.0.0 + dart_appwrite: ^19.1.0 ``` You can install packages from the command line: diff --git a/docs/examples/account/create-email-verification.md b/docs/examples/account/create-email-verification.md new file mode 100644 index 00000000..b10173d1 --- /dev/null +++ b/docs/examples/account/create-email-verification.md @@ -0,0 +1,12 @@ +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Account account = Account(client); + +Token result = await account.createEmailVerification( + url: 'https://example.com', +); diff --git a/docs/examples/account/update-email-verification.md b/docs/examples/account/update-email-verification.md new file mode 100644 index 00000000..b48535a3 --- /dev/null +++ b/docs/examples/account/update-email-verification.md @@ -0,0 +1,13 @@ +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Account account = Account(client); + +Token result = await account.updateEmailVerification( + userId: '', + secret: '', +); diff --git a/lib/services/account.dart b/lib/services/account.dart index 7044c030..8f03bbf3 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -1235,8 +1235,43 @@ class Account extends Service { /// the only valid redirect URLs are the ones from domains you have set when /// adding your platforms in the console interface. /// + Future createEmailVerification({required String url}) async { + final String apiPath = '/account/verifications/email'; + + final Map apiParams = {'url': url}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.post, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.Token.fromMap(res.data); + } + + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). + /// 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](https://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. + /// + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.createEmailVerification` instead.', + ) Future createVerification({required String url}) async { - final String apiPath = '/account/verification'; + final String apiPath = '/account/verifications/email'; final Map apiParams = {'url': url}; @@ -1256,11 +1291,38 @@ class Account extends Service { /// 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. + Future updateEmailVerification({ + required String userId, + required String secret, + }) async { + final String apiPath = '/account/verifications/email'; + + final Map apiParams = {'userId': userId, 'secret': secret}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.put, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.Token.fromMap(res.data); + } + + /// 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. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.updateEmailVerification` instead.', + ) Future updateVerification({ required String userId, required String secret, }) async { - final String apiPath = '/account/verification'; + final String apiPath = '/account/verifications/email'; final Map apiParams = {'userId': userId, 'secret': secret}; @@ -1285,7 +1347,7 @@ class Account extends Service { /// The verification code sent to the user's phone number is valid for 15 /// minutes. Future createPhoneVerification() async { - final String apiPath = '/account/verification/phone'; + final String apiPath = '/account/verifications/phone'; final Map apiParams = {}; @@ -1309,7 +1371,7 @@ class Account extends Service { required String userId, required String secret, }) async { - final String apiPath = '/account/verification/phone'; + final String apiPath = '/account/verifications/phone'; final Map apiParams = {'userId': userId, 'secret': secret}; diff --git a/lib/services/functions.dart b/lib/services/functions.dart index e86f1afe..d0687a9b 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -360,7 +360,7 @@ class Functions extends Service { /// Create a deployment based on a template. /// /// Use this endpoint with combination of - /// [listTemplates](https://appwrite.io/docs/server/functions#listTemplates) to + /// [listTemplates](https://appwrite.io/docs/products/functions/templates) to /// find the template details. Future createTemplateDeployment({ required String functionId, diff --git a/lib/services/sites.dart b/lib/services/sites.dart index d89f2192..792f3a7b 100644 --- a/lib/services/sites.dart +++ b/lib/services/sites.dart @@ -338,8 +338,8 @@ class Sites extends Service { /// Create a deployment based on a template. /// /// Use this endpoint with combination of - /// [listTemplates](https://appwrite.io/docs/server/sites#listTemplates) to - /// find the template details. + /// [listTemplates](https://appwrite.io/docs/products/sites/templates) to find + /// the template details. Future createTemplateDeployment({ required String siteId, required String repository, diff --git a/lib/services/tables_db.dart b/lib/services/tables_db.dart index 560b7358..06600c20 100644 --- a/lib/services/tables_db.dart +++ b/lib/services/tables_db.dart @@ -155,7 +155,7 @@ class TablesDB extends Service { /// Create a new Table. Before using this route, you should create a new /// database resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. Future createTable({ required String databaseId, @@ -1396,7 +1396,7 @@ class TablesDB extends Service { /// Create a new Row. Before using this route, you should create a new table /// resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. Future createRow({ required String databaseId, @@ -1429,7 +1429,7 @@ class TablesDB extends Service { /// Create new Rows. Before using this route, you should create a new table /// resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. Future createRows({ required String databaseId, @@ -1456,7 +1456,7 @@ class TablesDB extends Service { /// Create or update Rows. Before using this route, you should create a new /// table resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// Future upsertRows({ @@ -1563,7 +1563,7 @@ class TablesDB extends Service { /// Create or update a Row. Before using this route, you should create a new /// table resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. Future upsertRow({ required String databaseId, diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index 1eab0a58..820e6d71 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -30,7 +30,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '19.0.0', + 'x-sdk-version': '19.1.0', 'X-Appwrite-Response-Format': '1.8.0', }; diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index b534d2a7..a4965e3b 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -36,9 +36,9 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '19.0.0', + 'x-sdk-version': '19.1.0', 'user-agent': - 'AppwriteDartSDK/19.0.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', + 'AppwriteDartSDK/19.1.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', 'X-Appwrite-Response-Format': '1.8.0', }; diff --git a/pubspec.yaml b/pubspec.yaml index 0a9e397e..fede227c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: dart_appwrite -version: 19.0.0 +version: 19.1.0 description: Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API homepage: https://appwrite.io repository: https://github.com/appwrite/sdk-for-dart diff --git a/test/services/account_test.dart b/test/services/account_test.dart index 5f8488fe..ed00b277 100644 --- a/test/services/account_test.dart +++ b/test/services/account_test.dart @@ -1300,6 +1300,28 @@ void main() { }); + test('test method createEmailVerification()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createEmailVerification( + url: 'https://example.com', + ); + expect(response, isA()); + + }); + test('test method createVerification()', () async { final Map data = { '\$id': 'bb8ea5c16897e', @@ -1322,6 +1344,29 @@ void main() { }); + test('test method updateEmailVerification()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateEmailVerification( + userId: '', + secret: '', + ); + expect(response, isA()); + + }); + test('test method updateVerification()', () async { final Map data = { '\$id': 'bb8ea5c16897e',