Skip to content

Commit 85550bc

Browse files
committed
duplicate email check
1 parent d86a695 commit 85550bc

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Sources/LocalAuthentication/Schema/Account.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,25 @@ public class Account: PostgresStORM {
7575
}
7676
}
7777

78+
public func isUnique() throws {
79+
// checks for email address already existing
80+
let this = Account()
81+
do {
82+
try this.find(["email":email])
83+
if this.results.foundSetCount > 0 {
84+
throw OAuth2ServerError.registerError
85+
}
86+
} catch {
87+
print(error)
88+
}
89+
}
90+
7891
// Register User
7992
public static func register(_ u: String, _ e: String, _ ut: AccountType = .provisional, baseURL: String) -> OAuth2ServerError {
8093
let r = URandom()
8194
let acc = Account(r.secureToken, u, "", e, ut)
8295
do {
96+
try acc.isUnique()
8397
try acc.create()
8498
} catch {
8599
print(error)

0 commit comments

Comments
 (0)