Skip to content

Commit

Permalink
Finished sign up, working on networking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elijah Cobb committed Jul 9, 2019
1 parent 3017217 commit fc07fa4
Show file tree
Hide file tree
Showing 7 changed files with 393 additions and 221 deletions.
62 changes: 62 additions & 0 deletions subscribeto/subscribeto/API/API.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// API.swift
// subscribeto
//
// Created by Elijah Cobb on 9/07/19.
// Copyright © 2019 subscribeto. All rights reserved.
//

import Foundation

struct S2NetworkError {
let code: Int
let msg: String
}

struct S2Request {

enum Method: String {
case get = "GET"
case post = "POST"
case delete = "DELETE"
case put = "PUT"
}

enum Token {
case session
case totp(String)
case email(String)
case sms(String)
}

static let baseUrl = "http://api.scribe.to"
static var sessionToken: String?

var method: Method
var endpoint: String
var token: Token

func makeRequest(_ handler: @escaping (Data?, S2NetworkError?) -> Void) {

let session = URLSession.init()
guard let url = URL.init(string: S2Request.baseUrl + "/" + endpoint) else { return handler(nil, S2NetworkError(code: -1, msg: "The url created was invalid.")) }
let urlRequest = URLRequest.init(url: url)

session.dataTask(with: urlRequest) { (data: Data?, response: URLResponse?, error: Error?) in

if data != nil { handler(data, nil) }
else {

guard let err = error else {
return handler(nil, S2NetworkError(code: -1, msg: "Both "))
}

handler(nil, S2NetworkError(code: -1, msg: err.localizedDescription))

}

}

}

}
61 changes: 35 additions & 26 deletions subscribeto/subscribeto/Account Session/SignInVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,53 @@ import UIKit

class SignInVC: UIViewController {

@IBOutlet var topViewContraint: NSLayoutConstraint!
@IBOutlet var topView: UIView!
@IBOutlet var topLabel: UILabel!
@IBOutlet var emailField: S2Field!
@IBOutlet var passwordField: S2Field!
@IBOutlet var signUpButton: S2Button!
@IBOutlet var imageViewHeightConstraint: NSLayoutConstraint!
@IBOutlet var buttonTrayBaseConstraint: NSLayoutConstraint!
@IBOutlet var emailField: S2UIField!
@IBOutlet var passwordField: S2UIField!
@IBOutlet var signInButton: S2UIButton!
@IBOutlet var signUpButton: S2UIButton!

func handleKeyboardDidPresent(frame: CGRect) {
func handleFieldKeyboardUpdate(_ frame: CGRect = CGRect(x: 0, y: 0, width: 0, height: 20)) {

self.buttonTrayBaseConstraint.constant = frame.size.height - 20
self.imageViewHeightConstraint.constant = self.view.frame.size.height - self.buttonTrayBaseConstraint.constant - 300

UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: [], animations: {

self.view.layoutIfNeeded()

})
}

func signIn() {

let h1 = self.view.frame.size.height
let h2 = signUpButton.frame.size.height
let h3 = passwordField.frame.size.height
let h4 = emailField.frame.size.height
let h5 = frame.size.height
topViewContraint.constant = h1 - h2 - h3 - h4 - h5 - 140

self.view.layoutIfNeeded()

}

func signUp() {



}

override func viewDidLoad() {

super.viewDidLoad()

view.backgroundColor = UIColor.subscribeto.black
topLabel.textColor = UIColor.subscribeto.blue1

emailField.setType(type: .email)
emailField.onDone { (value: String) in

print("Email: \(value)")
self.passwordField.becomeActive()

}
emailField.onKeyboardDidPresent(handleKeyboardDidPresent)
passwordField.onKeyboardDidPresent(handleKeyboardDidPresent)
passwordField.setType(type: .password)
handleKeyboardDidPresent(frame: CGRect(x: 0, y: 0, width: 0, height: 0))

passwordField.onEndEditing { self.handleFieldKeyboardUpdate() }
emailField.onEndEditing { self.handleFieldKeyboardUpdate() }

emailField.onKeyboardWillChangeFrame(handleFieldKeyboardUpdate)
passwordField.onKeyboardWillChangeFrame(handleFieldKeyboardUpdate)

signInButton.onClick(signIn)
signUpButton.onClick(signUp)

}

}
Expand Down
Loading

0 comments on commit fc07fa4

Please sign in to comment.