diff --git a/CHANGELOG.md b/CHANGELOG.md index f7044156..176efe4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 20.1.0 + +* Deprecate `createVerification` method in `Account` service +* Add `createEmailVerification` method in `Account` service + ## 19.1.0 * Add `orderRandom` query support diff --git a/README.md b/README.md index bba49076..e24685c6 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - appwrite: ^20.0.0 + appwrite: ^20.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..823ea2f2 --- /dev/null +++ b/docs/examples/account/create-email-verification.md @@ -0,0 +1,11 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +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..927aadf1 --- /dev/null +++ b/docs/examples/account/update-email-verification.md @@ -0,0 +1,12 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +Token result = await account.updateEmailVerification( + userId: '', + secret: '', +); diff --git a/lib/services/account.dart b/lib/services/account.dart index 00287c89..08d25f6f 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -1378,8 +1378,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 { + const 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 { - const String apiPath = '/account/verification'; + const String apiPath = '/account/verifications/email'; final Map apiParams = {'url': url}; @@ -1399,11 +1434,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 { + const 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 { - const String apiPath = '/account/verification'; + const String apiPath = '/account/verifications/email'; final Map apiParams = {'userId': userId, 'secret': secret}; @@ -1428,7 +1490,7 @@ class Account extends Service { /// The verification code sent to the user's phone number is valid for 15 /// minutes. Future createPhoneVerification() async { - const String apiPath = '/account/verification/phone'; + const String apiPath = '/account/verifications/phone'; final Map apiParams = {}; @@ -1452,7 +1514,7 @@ class Account extends Service { required String userId, required String secret, }) async { - const String apiPath = '/account/verification/phone'; + const String apiPath = '/account/verifications/phone'; final Map apiParams = {'userId': userId, 'secret': secret}; diff --git a/lib/services/tables_db.dart b/lib/services/tables_db.dart index 2c6f1c09..2ed5b29f 100644 --- a/lib/services/tables_db.dart +++ b/lib/services/tables_db.dart @@ -31,7 +31,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, @@ -92,7 +92,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 c8083904..ec2126e3 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -40,7 +40,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '20.0.0', + 'x-sdk-version': '20.1.0', 'X-Appwrite-Response-Format': '1.8.0', }; diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index 981a7c65..a811ce67 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -58,7 +58,7 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '20.0.0', + 'x-sdk-version': '20.1.0', 'X-Appwrite-Response-Format': '1.8.0', }; diff --git a/pubspec.yaml b/pubspec.yaml index b488c68a..fbb10dba 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: appwrite -version: 20.0.0 +version: 20.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-flutter diff --git a/test/services/account_test.dart b/test/services/account_test.dart index ac86fdd1..3276e3e3 100644 --- a/test/services/account_test.dart +++ b/test/services/account_test.dart @@ -1380,6 +1380,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', @@ -1402,6 +1424,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',