Commit 5703ecc1 by Dima Bart

Configure login and signup view controllers.

parent e972256c
......@@ -25,16 +25,42 @@
//
import UIKit
import Buy
class LoginViewController: UITableViewController {
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!
var email: String { return self.emailField.text ?? "" }
var password: String { return self.passwordField.text ?? "" }
// ----------------------------------
// MARK: - View Loading -
// MARK: - Actions -
//
override func viewDidLoad() {
super.viewDidLoad()
private func loginUser() {
let credentials = BUYAccountCredentials(items: [
BUYAccountCredentialItem(emailWithValue: self.email),
BUYAccountCredentialItem(passwordWithValue: self.password),
])
BUYClient.sharedClient.loginCustomerWithCredentials(credentials) { (customer, token, error) in
print("Customer: \(customer), Token: \(token), Error: \(error)")
}
}
// ----------------------------------
// MARK: - UITableViewDelegate -
//
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.section == 1 {
if !self.email.isEmpty &&
!self.password.isEmpty {
self.loginUser()
}
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
......@@ -29,12 +29,50 @@ import Buy
class SignupViewController: UITableViewController {
@IBOutlet weak var firstNameField: UITextField!
@IBOutlet weak var lastNameField: UITextField!
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!
@IBOutlet weak var passwordConfirmField: UITextField!
var firstName: String { return self.firstNameField.text ?? "" }
var lastName: String { return self.lastNameField.text ?? "" }
var email: String { return self.emailField.text ?? "" }
var password: String { return self.passwordField.text ?? "" }
var passwordConfirm: String { return self.passwordField.text ?? "" }
// ----------------------------------
// MARK: - View Loading -
// MARK: - Actions -
//
override func viewDidLoad() {
super.viewDidLoad()
private func createUser() {
let credentials = BUYAccountCredentials(items: [
BUYAccountCredentialItem(firstNameWithValue: self.firstName),
BUYAccountCredentialItem(firstNameWithValue: self.lastName),
BUYAccountCredentialItem(emailWithValue: self.email),
BUYAccountCredentialItem(passwordWithValue: self.password),
BUYAccountCredentialItem(passwordConfirmationWithValue: self.passwordConfirm),
])
BUYClient.sharedClient.createCustomerWithCredentials(credentials) { (customer, token, error) in
print("Customer: \(customer), Token: \(token), Error: \(error)")
}
}
// ----------------------------------
// MARK: - UITableViewDelegate -
//
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.section == 1 {
if !self.email.isEmpty &&
!self.password.isEmpty &&
!self.firstName.isEmpty &&
!self.lastName.isEmpty &&
!self.passwordConfirm.isEmpty {
self.createUser()
}
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment