|
|
|
|
@ -181,16 +181,12 @@ public class Services { |
|
|
|
|
public func createAccount<U: UserPasswordBase, V: UserBase>(user: U) async throws -> V { |
|
|
|
|
|
|
|
|
|
let response: V = try await _runRequest(serviceConf: .createAccount, payload: user) |
|
|
|
|
|
|
|
|
|
// var postRequest = try self._baseRequest(servicePath: "users/", method: .post) |
|
|
|
|
// postRequest.httpBody = try jsonEncoder.encode(user) |
|
|
|
|
// let response: V = try await self.runRequest(postRequest) |
|
|
|
|
let _ = try await requestToken(username: user.username, password: user.password) |
|
|
|
|
// let _ = try await requestToken(username: user.username, password: user.password) |
|
|
|
|
Store.main.setUserName(user.username) |
|
|
|
|
return response |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func requestToken(username: String, password: String) async throws -> String { |
|
|
|
|
public func requestToken(username: String, password: String) async throws -> String { |
|
|
|
|
var postRequest = try self._baseRequest(conf: .requestToken) |
|
|
|
|
let credentials = Credentials(username: username, password: password) |
|
|
|
|
postRequest.httpBody = try jsonEncoder.encode(credentials) |
|
|
|
|
@ -235,12 +231,12 @@ public class Services { |
|
|
|
|
self._storeToken(username: username, token: response.token) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public func forgotPassword(user: UserBase) async throws { |
|
|
|
|
public func forgotPassword(email: String) async throws { |
|
|
|
|
|
|
|
|
|
// var postRequest = try self._baseRequest(servicePath: "forgot-password/", method: .post) |
|
|
|
|
// postRequest.httpBody = try jsonEncoder.encode(credentials) |
|
|
|
|
// let response: User = try await self.runRequest(postRequest) |
|
|
|
|
// let _ = try await requestToken(credentials: credentials) |
|
|
|
|
var postRequest = try self._baseRequest(servicePath: "dj-rest-auth/password/reset/", method: .post) |
|
|
|
|
postRequest.httpBody = try jsonEncoder.encode(Email(email: email)) |
|
|
|
|
let response: Email = try await self._runRequest(postRequest) |
|
|
|
|
Logger.log("response = \(response)") |
|
|
|
|
// return response |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -258,16 +254,17 @@ struct Credentials: Codable { |
|
|
|
|
var username: String |
|
|
|
|
var password: String |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct Token: Codable { |
|
|
|
|
var token: String |
|
|
|
|
} |
|
|
|
|
struct Email: Codable { |
|
|
|
|
var email: String |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public protocol UserBase: Codable { |
|
|
|
|
var id: String { get } |
|
|
|
|
var username: String { get } |
|
|
|
|
// var password: String? { get } |
|
|
|
|
var email: String? { get } |
|
|
|
|
var email: String { get } |
|
|
|
|
|
|
|
|
|
func uuid() throws -> UUID |
|
|
|
|
} |
|
|
|
|
|