Switch branches/tags
Nothing to show
Clone or download
Latest commit 973d19d Sep 17, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example test change Sep 7, 2018
MinterMy Changed docs Sep 7, 2018
.gitignore Initial commit May 1, 2018
.travis.yml changed schemes Sep 7, 2018
Cartfile fixed podspec Aug 28, 2018
LICENSE Initial commit May 1, 2018
MinterMy.podspec fixed podspec Aug 28, 2018
README.md Update README.md Sep 17, 2018
_Pods.xcodeproj Initial commit May 1, 2018
minter-logo.svg added logo Sep 17, 2018

README.md

Version CI Status Version Platform License Last commit

MinterMy

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

MinterMy is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MinterMy'

How-to

Check if username taken

/// 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)
})

Login user

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)
}

Register user

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)
}

User info by address

let addresses = ["Mx5g57b689ec01k09r26436f3o08e3eb5c08bfarp5"]
infoManager.info(by: addresses, completion: { (response, error) in
  print(response)
  print(error)
}

Address info by email or username

infoManager.address(email: "email&@gmail.com") { [weak self] (address, user, error) in
  print(address)
  print(user)
  print(error)
}

Get user profile

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)
})

Update user profile

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)
})

Update user avatar

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)
})

Delete user avatar

profileManager?.deleteAvatar(with: { (error) in
  print(error)
})

Author

sidorov.panda, ody344@gmail.com

License

MinterMy is available under the MIT license. See the LICENSE file for more info.