Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions docs/examples/account/create-email-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:appwrite/appwrite.dart';

Client client = Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

Account account = Account(client);

Token result = await account.createEmailVerification(
url: 'https://example.com',
);
12 changes: 12 additions & 0 deletions docs/examples/account/update-email-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:appwrite/appwrite.dart';

Client client = Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

Account account = Account(client);

Token result = await account.updateEmailVerification(
userId: '<USER_ID>',
secret: '<SECRET>',
);
70 changes: 66 additions & 4 deletions lib/services/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<models.Token> createEmailVerification({required String url}) async {
const String apiPath = '/account/verifications/email';

final Map<String, dynamic> apiParams = {'url': url};

final Map<String, String> 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<models.Token> createVerification({required String url}) async {
const String apiPath = '/account/verification';
const String apiPath = '/account/verifications/email';

final Map<String, dynamic> apiParams = {'url': url};

Expand All @@ -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<models.Token> updateEmailVerification({
required String userId,
required String secret,
}) async {
const String apiPath = '/account/verifications/email';

final Map<String, dynamic> apiParams = {'userId': userId, 'secret': secret};

final Map<String, String> 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<models.Token> updateVerification({
required String userId,
required String secret,
}) async {
const String apiPath = '/account/verification';
const String apiPath = '/account/verifications/email';

final Map<String, dynamic> apiParams = {'userId': userId, 'secret': secret};

Expand All @@ -1428,7 +1490,7 @@ class Account extends Service {
/// The verification code sent to the user's phone number is valid for 15
/// minutes.
Future<models.Token> createPhoneVerification() async {
const String apiPath = '/account/verification/phone';
const String apiPath = '/account/verifications/phone';

final Map<String, dynamic> apiParams = {};

Expand All @@ -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<String, dynamic> apiParams = {'userId': userId, 'secret': secret};

Expand Down
4 changes: 2 additions & 2 deletions lib/services/tables_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<models.Row> createRow({
required String databaseId,
Expand Down Expand Up @@ -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<models.Row> upsertRow({
required String databaseId,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

Expand Down
2 changes: 1 addition & 1 deletion lib/src/client_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 45 additions & 0 deletions test/services/account_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,28 @@ void main() {

});

test('test method createEmailVerification()', () async {
final Map<String, dynamic> 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<models.Token>());

});

test('test method createVerification()', () async {
final Map<String, dynamic> data = {
'\$id': 'bb8ea5c16897e',
Expand All @@ -1402,6 +1424,29 @@ void main() {

});

test('test method updateEmailVerification()', () async {
final Map<String, dynamic> 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: '<USER_ID>',
secret: '<SECRET>',
);
expect(response, isA<models.Token>());

});

test('test method updateVerification()', () async {
final Map<String, dynamic> data = {
'\$id': 'bb8ea5c16897e',
Expand Down