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

## 13.1.0

* Deprecate `createVerification` method in `Account` service
* Add `createEmailVerification` method in `Account` service

## 10.2.0

* Update sdk to use swift-native doc comments instead of jsdoc styled comments as per [Swift Documentation Comments](https://github.com/swiftlang/swift/blob/main/docs/DocumentationComments.md)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:

```swift
dependencies: [
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "13.0.0"),
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "13.1.0"),
],
```

Expand Down
2 changes: 1 addition & 1 deletion Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open class Client {
"x-sdk-name": "Apple",
"x-sdk-platform": "client",
"x-sdk-language": "apple",
"x-sdk-version": "13.0.0",
"x-sdk-version": "13.1.0",
"x-appwrite-response-format": "1.8.0"
]

Expand Down
98 changes: 94 additions & 4 deletions Sources/Appwrite/Services/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2210,10 +2210,59 @@ open class Account: Service {
/// - Throws: Exception if the request fails
/// - Returns: AppwriteModels.Token
///
open func createEmailVerification(
url: String
) async throws -> AppwriteModels.Token {
let apiPath: String = "/account/verifications/email"

let apiParams: [String: Any?] = [
"url": url
]

let apiHeaders: [String: String] = [
"content-type": "application/json"
]

let converter: (Any) -> AppwriteModels.Token = { response in
return AppwriteModels.Token.from(map: response as! [String: Any])
}

return try await client.call(
method: "POST",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}

///
/// 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.
///
///
/// - Parameters:
/// - url: String
/// - Throws: Exception if the request fails
/// - Returns: AppwriteModels.Token
///
@available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.createEmailVerification` instead.")
open func createVerification(
url: String
) async throws -> AppwriteModels.Token {
let apiPath: String = "/account/verification"
let apiPath: String = "/account/verifications/email"

let apiParams: [String: Any?] = [
"url": url
Expand Down Expand Up @@ -2248,11 +2297,52 @@ open class Account: Service {
/// - Throws: Exception if the request fails
/// - Returns: AppwriteModels.Token
///
open func updateEmailVerification(
userId: String,
secret: String
) async throws -> AppwriteModels.Token {
let apiPath: String = "/account/verifications/email"

let apiParams: [String: Any?] = [
"userId": userId,
"secret": secret
]

let apiHeaders: [String: String] = [
"content-type": "application/json"
]

let converter: (Any) -> AppwriteModels.Token = { response in
return AppwriteModels.Token.from(map: response as! [String: Any])
}

return try await client.call(
method: "PUT",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}

///
/// 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:
/// - userId: String
/// - secret: String
/// - Throws: Exception if the request fails
/// - Returns: AppwriteModels.Token
///
@available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.updateEmailVerification` instead.")
open func updateVerification(
userId: String,
secret: String
) async throws -> AppwriteModels.Token {
let apiPath: String = "/account/verification"
let apiPath: String = "/account/verifications/email"

let apiParams: [String: Any?] = [
"userId": userId,
Expand Down Expand Up @@ -2291,7 +2381,7 @@ open class Account: Service {
///
open func createPhoneVerification(
) async throws -> AppwriteModels.Token {
let apiPath: String = "/account/verification/phone"
let apiPath: String = "/account/verifications/phone"

let apiParams: [String: Any] = [:]

Expand Down Expand Up @@ -2328,7 +2418,7 @@ open class Account: Service {
userId: String,
secret: String
) async throws -> AppwriteModels.Token {
let apiPath: String = "/account/verification/phone"
let apiPath: String = "/account/verifications/phone"

let apiParams: [String: Any?] = [
"userId": userId,
Expand Down
8 changes: 4 additions & 4 deletions Sources/Appwrite/Services/TablesDb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ open class TablesDB: 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.
///
/// - Parameters:
Expand Down Expand Up @@ -125,7 +125,7 @@ open class TablesDB: 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.
///
/// - Parameters:
Expand Down Expand Up @@ -227,7 +227,7 @@ open class TablesDB: 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.
///
/// - Parameters:
Expand Down Expand Up @@ -277,7 +277,7 @@ open class TablesDB: 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.
///
/// - Parameters:
Expand Down
12 changes: 12 additions & 0 deletions docs/examples/account/create-email-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Appwrite

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

let account = Account(client)

let token = try await account.createEmailVerification(
url: "https://example.com"
)

13 changes: 13 additions & 0 deletions docs/examples/account/update-email-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Appwrite

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

let account = Account(client)

let token = try await account.updateEmailVerification(
userId: "<USER_ID>",
secret: "<SECRET>"
)