Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reset and update password for end users #120

Merged
merged 7 commits into from
Mar 15, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions OmiseGO.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
032CEF24211D685600E44445 /* secret.plist in Resources */ = {isa = PBXBuildFile; fileRef = 032CEF22211D685600E44445 /* secret.plist */; };
032CEF2A211D783D00E44445 /* LiveTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032CEF29211D783D00E44445 /* LiveTestCase.swift */; };
033802AB215B9D2500C2501F /* AccountGetParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033802AA215B9D2500C2501F /* AccountGetParams.swift */; };
033D1889223A0E6B00B6B8D9 /* UserResetPasswordParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033D1888223A0E6B00B6B8D9 /* UserResetPasswordParams.swift */; };
033D188B223A0E8000B6B8D9 /* UserUpdatePasswordParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033D188A223A0E8000B6B8D9 /* UserUpdatePasswordParams.swift */; };
0341BCA2216B395D001928FE /* TransactionRequestParams+Admin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0341BCA1216B395D001928FE /* TransactionRequestParams+Admin.swift */; };
0341BCA4216B3DC5001928FE /* TransactionConsumptionParams+Admin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0341BCA3216B3DC5001928FE /* TransactionConsumptionParams+Admin.swift */; };
0341BCA7216B4024001928FE /* AdminEncodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0341BCA6216B4024001928FE /* AdminEncodeTests.swift */; };
Expand Down Expand Up @@ -302,6 +304,8 @@
032CEF22211D685600E44445 /* secret.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = secret.plist; sourceTree = "<group>"; };
032CEF29211D783D00E44445 /* LiveTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveTestCase.swift; sourceTree = "<group>"; };
033802AA215B9D2500C2501F /* AccountGetParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountGetParams.swift; sourceTree = "<group>"; };
033D1888223A0E6B00B6B8D9 /* UserResetPasswordParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserResetPasswordParams.swift; sourceTree = "<group>"; };
033D188A223A0E8000B6B8D9 /* UserUpdatePasswordParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserUpdatePasswordParams.swift; sourceTree = "<group>"; };
0341BCA1216B395D001928FE /* TransactionRequestParams+Admin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TransactionRequestParams+Admin.swift"; sourceTree = "<group>"; };
0341BCA3216B3DC5001928FE /* TransactionConsumptionParams+Admin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TransactionConsumptionParams+Admin.swift"; sourceTree = "<group>"; };
0341BCA6216B4024001928FE /* AdminEncodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdminEncodeTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -439,6 +443,8 @@
0320EAB92119499B0006685C /* TransactionRequest+Client.swift */,
0306DC9E215A2E0200612953 /* TransactionListParams.swift */,
0380AAE8212D2D78006B2193 /* SignupParams.swift */,
033D1888223A0E6B00B6B8D9 /* UserResetPasswordParams.swift */,
033D188A223A0E8000B6B8D9 /* UserUpdatePasswordParams.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -1169,6 +1175,7 @@
033802AB215B9D2500C2501F /* AccountGetParams.swift in Sources */,
0379E7F721184BC900E65D4F /* TransactionParams.swift in Sources */,
0379E80621184BC900E65D4F /* Account.swift in Sources */,
033D188B223A0E8000B6B8D9 /* UserUpdatePasswordParams.swift in Sources */,
034F1523214FA205002BB513 /* SortParams.swift in Sources */,
0379E80B21184BC900E65D4F /* Listable.swift in Sources */,
0379E81321184BC900E65D4F /* QRScannerViewController.swift in Sources */,
Expand Down Expand Up @@ -1238,6 +1245,7 @@
0341BCAC216B4316001928FE /* TransactionRequest+Admin.swift in Sources */,
03E72EDB2124177E0060E1D7 /* LoginParams.swift in Sources */,
034F1529214FA6FB002BB513 /* PaginatedListParams.swift in Sources */,
033D1889223A0E6B00B6B8D9 /* UserResetPasswordParams.swift in Sources */,
03E565B5211AFBB100BC9124 /* QRScannerViewController+Client.swift in Sources */,
034F1527214FA228002BB513 /* PaginationParams.swift in Sources */,
0379E81221184BC900E65D4F /* QRScannerLoadingView.swift in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions Source/Admin/API/APIAdminEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum APIAdminEndpoint: APIEndpoint {
case transactionRequestCreate(params: TransactionRequestCreateParams)
case transactionRequestGet(params: TransactionRequestGetParams)
case transactionRequestConsume(params: TransactionConsumptionParams)
case transactionConsumptionCancel(params: TransactionConsumptionCancellationParams)
case transactionConsumptionApprove(params: TransactionConsumptionConfirmationParams)
case transactionConsumptionReject(params: TransactionConsumptionConfirmationParams)

Expand Down Expand Up @@ -49,6 +50,8 @@ enum APIAdminEndpoint: APIEndpoint {
return "/transaction_request.get"
case .transactionRequestConsume:
return "/transaction_request.consume"
case .transactionConsumptionCancel:
return "/transaction_consumption.cancel"
case .transactionConsumptionApprove:
return "/transaction_consumption.approve"
case .transactionConsumptionReject:
Expand Down Expand Up @@ -82,6 +85,8 @@ enum APIAdminEndpoint: APIEndpoint {
return .requestParameters(parameters: parameters)
case let .transactionConsumptionApprove(parameters):
return .requestParameters(parameters: parameters)
case let .transactionConsumptionCancel(parameters):
return .requestParameters(parameters: parameters)
case let .transactionConsumptionReject(parameters):
return .requestParameters(parameters: parameters)
default:
Expand Down
15 changes: 15 additions & 0 deletions Source/Admin/Models/TransactionConsumption+Admin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ extension TransactionConsumption {
callback: callback)
}

@discardableResult
/// Cancel the transaction consumption
///
/// - Parameters:
/// - client: An API client.
/// This client need to be initialized with a AdminConfiguration struct before being used.
/// - callback: The closure called when the request is completed
/// - Returns: An optional cancellable request.
public func cancel(using client: HTTPAdminAPI,
callback: @escaping TransactionConsumption.RetrieveRequestCallback)
-> TransactionConsumption.RetrieveRequest? {
let params = TransactionConsumptionCancellationParams(id: id)
return self.retrieve(using: client, endpoint: APIAdminEndpoint.transactionConsumptionCancel(params: params), callback: callback)
}

@discardableResult
/// Approve the transaction consumption
///
Expand Down
12 changes: 12 additions & 0 deletions Source/Admin/Models/TransactionRequestParams+Admin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ extension TransactionRequestCreateParams {
/// - allowAmountOverride: Allow or not the consumer to override the amount specified in the request
/// This needs to be true if the amount is not specified
/// - maxConsumptionsPerUser: The maximum number of consumptions allowed per unique user
/// - consumptionIntervalDuration: The duration (in milliseconds) during which the maxConsumptionsPerInterval and
/// maxConsumptionsPerIntervalPerUser attributes take effect.
/// - maxConsumptionsPerInterval: The total number of times the request can be consumed in the defined interval
/// (like 3 times every 24 hours)
/// - maxConsumptionsPerIntervalPerUser: The total number of times one unique user can consume the request
/// (like once every 24 hours)
/// - exchangeAccountId: The account to use for the token exchange (if any)
/// - exchangeWalletAddress: The wallet address to use for the token exchange (if any)
/// - metadata: Additional metadata embeded with the request
Expand All @@ -48,6 +54,9 @@ extension TransactionRequestCreateParams {
expirationDate: Date? = nil,
allowAmountOverride: Bool,
maxConsumptionsPerUser: Int? = nil,
consumptionIntervalDuration: Int? = nil,
maxConsumptionsPerInterval: Int? = nil,
maxConsumptionsPerIntervalPerUser: Int? = nil,
exchangeAccountId: String? = nil,
exchangeWalletAddress: String? = nil,
metadata: [String: Any] = [:],
Expand All @@ -67,6 +76,9 @@ extension TransactionRequestCreateParams {
self.expirationDate = expirationDate
self.allowAmountOverride = allowAmountOverride
self.maxConsumptionsPerUser = maxConsumptionsPerUser
self.consumptionIntervalDuration = consumptionIntervalDuration
self.maxConsumptionsPerInterval = maxConsumptionsPerInterval
self.maxConsumptionsPerIntervalPerUser = maxConsumptionsPerIntervalPerUser
self.metadata = metadata
self.encryptedMetadata = encryptedMetadata
self.exchangeAccountId = exchangeAccountId
Expand Down
19 changes: 17 additions & 2 deletions Source/Client/API/APIClientEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ enum APIClientEndpoint: APIEndpoint {
case transactionRequestCreate(params: TransactionRequestCreateParams)
case transactionRequestGet(params: TransactionRequestGetParams)
case transactionRequestConsume(params: TransactionConsumptionParams)
case transactionConsumptionCancel(params: TransactionConsumptionCancellationParams)
case transactionConsumptionApprove(params: TransactionConsumptionConfirmationParams)
case transactionConsumptionReject(params: TransactionConsumptionConfirmationParams)
case resetPassword(params: UserResetPasswordParams)
case updatePassword(params: UserUpdatePasswordParams)
case signup(params: SignupParams)
case login(params: LoginParams)
case logout
Expand All @@ -40,14 +43,20 @@ enum APIClientEndpoint: APIEndpoint {
return "/me.get_transaction_request"
case .transactionRequestConsume:
return "/me.consume_transaction_request"
case .transactionConsumptionCancel:
return "/me.cancel_transaction_consumption"
case .transactionConsumptionApprove:
return "/me.approve_transaction_consumption"
case .transactionConsumptionReject:
return "/me.reject_transaction_consumption"
case .resetPassword:
return "/user.reset_password"
case .updatePassword:
return "/user.update_password"
case .signup:
return "user.signup"
return "/user.signup"
case .login:
return "user.login"
return "/user.login"
case .logout:
return "/me.logout"
}
Expand All @@ -65,10 +74,16 @@ enum APIClientEndpoint: APIEndpoint {
return .requestParameters(parameters: parameters)
case let .getTransactions(parameters):
return .requestParameters(parameters: parameters)
case let .transactionConsumptionCancel(parameters):
return .requestParameters(parameters: parameters)
case let .transactionConsumptionApprove(parameters):
return .requestParameters(parameters: parameters)
case let .transactionConsumptionReject(parameters):
return .requestParameters(parameters: parameters)
case let .resetPassword(parameters):
return .requestParameters(parameters: parameters)
case let .updatePassword(parameters):
return .requestParameters(parameters: parameters)
case let .signup(parameters):
return .requestParameters(parameters: parameters)
case let .login(parameters):
Expand Down
15 changes: 15 additions & 0 deletions Source/Client/Models/TransactionConsumption+Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ extension TransactionConsumption {
callback: callback)
}

@discardableResult
/// Cancel the transaction consumption
///
/// - Parameters:
/// - client: An API client.
/// This client need to be initialized with a ClientConfiguration struct before being used.
/// - callback: The closure called when the request is completed
/// - Returns: An optional cancellable request.
public func cancel(using client: HTTPClientAPI,
callback: @escaping TransactionConsumption.RetrieveRequestCallback)
-> TransactionConsumption.RetrieveRequest? {
let params = TransactionConsumptionCancellationParams(id: id)
return self.retrieve(using: client, endpoint: APIClientEndpoint.transactionConsumptionCancel(params: params), callback: callback)
}

@discardableResult
/// Approve the transaction consumption
///
Expand Down
34 changes: 34 additions & 0 deletions Source/Client/Models/User+Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,38 @@ extension User: Retrievable {
callback: @escaping User.RetrieveRequestCallback) -> User.RetrieveRequest? {
return self.retrieve(using: client, endpoint: APIClientEndpoint.getCurrentUser, callback: callback)
}

@discardableResult
/// Request to reset the user's password
///
/// - Parameters:
/// - client: An API client.
/// This client need to be initialized with a ClientConfiguration struct before being used.
/// - params: The UserResetPasswordParams object to use to perform the request
/// - callback: The closure called when the request is completed
/// - Returns: An optional cancellable request.
public static func resetPassword(using client: HTTPClientAPI,
params: UserResetPasswordParams,
callback: @escaping Request<EmptyResponse>.Callback) -> Request<EmptyResponse>? {
let request: Request<EmptyResponse>? =
client.request(toEndpoint: APIClientEndpoint.resetPassword(params: params), callback: callback)
return request
}

@discardableResult
/// Update the password of a user given a valid token obtained following a reset password email link
///
/// - Parameters:
/// - client: An API client.
/// This client need to be initialized with a ClientConfiguration struct before being used.
/// - params: The UserUpdatePasswordParams object to use to perform the request
/// - callback: The closure called when the request is completed
/// - Returns: An optional cancellable request.
public static func updatePassword(using client: HTTPClientAPI,
params: UserUpdatePasswordParams,
callback: @escaping Request<EmptyResponse>.Callback) -> Request<EmptyResponse>? {
let request: Request<EmptyResponse>? =
client.request(toEndpoint: APIClientEndpoint.updatePassword(params: params), callback: callback)
return request
}
}
39 changes: 39 additions & 0 deletions Source/Client/Models/UserResetPasswordParams.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// UserResetPasswordParams.swift
// OmiseGO
//
// Created by Mederic Petit on 14/3/19.
// Copyright © 2019 Omise Go Pte. Ltd. All rights reserved.
//

/// Represents a structure used to request a password reset for the user
public struct UserResetPasswordParams {
/// The email of the user
public let email: String
/// The URL where the user will be taken when clicking the link in the email
public let redirectUrl: String

/// Initialize the params used to request a password reset for the user
///
/// - Parameters:
/// - email: The email of the user
/// - redirectUrl: The URL where the user will be taken when clicking the link in the email
public init(email: String,
redirectUrl: String) {
self.email = email
self.redirectUrl = redirectUrl
}
}

extension UserResetPasswordParams: APIParameters {
private enum CodingKeys: String, CodingKey {
case email
case redirectUrl = "redirect_url"
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(email, forKey: .email)
try container.encode(redirectUrl, forKey: .redirectUrl)
}
}
53 changes: 53 additions & 0 deletions Source/Client/Models/UserUpdatePasswordParams.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// UserUpdatePasswordParams.swift
// OmiseGO
//
// Created by Mederic Petit on 14/3/19.
// Copyright © 2019 Omise Go Pte. Ltd. All rights reserved.
//

/// Represents a structure used to update the password of a user following a reset
public struct UserUpdatePasswordParams {
/// The email of the user (obtained from the params in the link sent to the email of the user)
public let email: String
/// The unique reset password token obtained from the params in the link sent to the email of the user
public let token: String?
/// The updated password
public let password: String
/// The password confirmation that should match the updated password
public let passwordConfirmation: String

/// Initialize the params used to signup a user
///
/// - Parameters:
/// - email: The email of the user (obtained from the params in the link sent to the email of the user)
/// - token: The unique reset password token obtained from the params in the link sent to the email of the user
/// - password: The updated password
/// - passwordConfirmation: The password confirmation that should match the updated password
public init(email: String,
token: String,
password: String,
passwordConfirmation: String) {
self.email = email
self.token = token
self.password = password
self.passwordConfirmation = passwordConfirmation
}
}

extension UserUpdatePasswordParams: APIParameters {
private enum CodingKeys: String, CodingKey {
case email
case token
case password
case passwordConfirmation = "password_confirmation"
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(email, forKey: .email)
try container.encode(token, forKey: .token)
try container.encode(password, forKey: .password)
try container.encode(passwordConfirmation, forKey: .passwordConfirmation)
}
}
5 changes: 5 additions & 0 deletions Source/Core/Models/TransactionConsumption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum TransactionConsumptionStatus: String, Decodable {
case confirmed
case approved
case rejected
case cancelled
case failed
case expired
}
Expand Down Expand Up @@ -68,6 +69,8 @@ public struct TransactionConsumption {
public let rejectedAt: Date?
/// The date when the consumption got confirmed
public let confirmedAt: Date?
/// The date when the consumption got cancelled
public let cancelledAt: Date?
/// The date when the consumption failed
public let failedAt: Date?
/// The date when the consumption expired
Expand Down Expand Up @@ -113,6 +116,7 @@ extension TransactionConsumption: Decodable {
case approvedAt = "approved_at"
case rejectedAt = "rejected_at"
case confirmedAt = "confirmed_at"
case cancelledAt = "cancelled_at"
case failedAt = "failed_at"
case expiredAt = "expired_at"
case metadata
Expand Down Expand Up @@ -145,6 +149,7 @@ extension TransactionConsumption: Decodable {
approvedAt = try container.decodeIfPresent(Date.self, forKey: .approvedAt)
rejectedAt = try container.decodeIfPresent(Date.self, forKey: .rejectedAt)
confirmedAt = try container.decodeIfPresent(Date.self, forKey: .confirmedAt)
cancelledAt = try container.decodeIfPresent(Date.self, forKey: .cancelledAt)
failedAt = try container.decodeIfPresent(Date.self, forKey: .failedAt)
expiredAt = try container.decodeIfPresent(Date.self, forKey: .expiredAt)
createdAt = try container.decode(Date.self, forKey: .createdAt)
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Models/TransactionConsumptionParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,8 @@ extension TransactionConsumptionParams: APIParameters {
struct TransactionConsumptionConfirmationParams: APIParameters {
let id: String
}

/// Represents a structure used to cancel a transaction consumption from its id
struct TransactionConsumptionCancellationParams: APIParameters {
let id: String
}