MinterMy
示例
要运行示例项目,先从仓库克隆,然后在示例目录中第一次运行 pod install
。
安装
MinterMy 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'MinterMy'
方法
检查用户名是否已被占用
/// Initialize HTTP client
let httpClient = APIClient.shared
/// Initialize manager
let authManager = AuthManager(httpClient: httpClient)
authManager.isTaken(username: "ody344", completion: { [weak self] (respoonse, error) in
print(respoonse)
print(error)
})
登录用户
import CryptoSwift
let username = "ody344"
let rawUserPassword = "123456"
let accounPassword = AuthManager.authPassword(from: rawUserPassword)
authManager.login(username: username, password: accounPassword) { [weak self] (accessToken, refreshToken, user, error) in
print(accessToken)
print(refreshToken)
print(user)
print(error)
}
注册用户
import CryptoSwift
func encryptedMnemonic(mnemonic: String, password: Data) -> Data? {
let aes = try AES(key: password.bytes, blockMode: CBC(iv: self.iv!.bytes))
let ciphertext = try aes.encrypt(Array(mnemonic.utf8))
guard ciphertext.count > 0 else {
assert(true)
return nil
}
return Data(bytes: ciphertext)
}
let mnemonic = "size holiday develop vibrant chicken renew dad excess acid where ugly license"
let username = "ody344"
let rawUserPassword = "123456"
let accounPassword = AuthManager.authPassword(from: rawUserPassword)
let email = "email@&gmail.com"
let address = "Mx5g57b689ec01k09r26436f3o08e3eb5c08bfarp5"
let account = Account(id: id, encryptedBy: .me, address: address)
let encryptionKey: Data? = rawUserPassword.bytes.sha256()
let encrypted = encryptedMnemonic(mnemonic: mnemonic, password: encryptionKey!)
authManager.register(username: username, password: accountPassword, email: email, phone: nil, account: account, encrypted: encrypted) { [weak self] (isRegistered, error) in
print(isRegistered)
print(error)
}
通过地址获取用户信息
let addresses = ["Mx5g57b689ec01k09r26436f3o08e3eb5c08bfarp5"]
infoManager.info(by: addresses, completion: { (response, error) in
print(response)
print(error)
}
通过电子邮件或用户名获取地址信息
infoManager.address(email: "email&@gmail.com") { [weak self] (address, user, error) in
print(address)
print(user)
print(error)
}
获取用户资料
let accessToken = "Your access token"
let client = APIClient(headers: ["Authorization" : "Bearer " + accessToken])
let profileManager = ProfileManager(httpClient: client)
profileManager.profile(completion: { [weak self] (user, error) in
print(user)
print(error)
})
更新用户资料
let accessToken = "Your access token"
let client = APIClient(headers: ["Authorization" : "Bearer " + accessToken])
let profileManager = ProfileManager(httpClient: client)
let user = User()
user.username = "newUsername"
profileManager.updateProfile(user: user, completion: { [weak self] (updated, error) in
print(updated)
print(error)
})
更新用户头像
let accessToken = "Your access token"
let client = APIClient(headers: ["Authorization" : "Bearer " + accessToken])
let profileManager = ProfileManager(httpClient: client)
let base64 = "base64ImageString"
profileManager.uploadAvatar(imageBase64: base64, completion: { (succeed, url, error) in
print(succeed)
print(url)
print(error)
})
删除用户头像
profileManager?.deleteAvatar(with: { (error) in
print(error)
})
作者
sidorov.panda, [email protected]
许可证
MinterMy可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。