//

//  UserModel.swift

//  FreeTalk

//

//  Created by stayfoolish on 2018. 9. 9..

//  Copyright © 2018년 stayfoolish. All rights reserved.

//


import UIKit


class UserModel: NSObject {

    

    @objc var profileImageUrl: String?

    @objc var userName: String?

    @objc var uid: String?


}




//

//  ChatModel.swift

//  FreeTalk

//

//  Created by stayfoolish on 2018. 9. 10..

//  Copyright © 2018년 stayfoolish. All rights reserved.

//


import UIKit


class ChatModel: NSObject {

    var uid: String?

    var destinationUid:String?

}




//

//  ChatViewController.swift

//  FreeTalk

//

//  Created by stayfoolish on 2018. 9. 10..

//  Copyright © 2018년 stayfoolish. All rights reserved.

//


import UIKit

import Firebase


class ChatViewController: UIViewController {


    @IBOutlet var sendButton: UIButton!

    public var destinationUid: String? // 나중에 내가 채팅할 대상의 uid

    override func viewDidLoad() {

        super.viewDidLoad()


        sendButton.addTarget(self, action: #selector(createRoom), for: .touchUpInside)

        // Do any additional setup after loading the view.

    }


    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

    

    @objc func createRoom(){

        let createRoomInfo = [

            "uid":Auth.auth().currentUser?.uid,

            "destinationUid" : destinationUid

        ]

        

        Database.database().reference().child("chatrooms").childByAutoId().setValue(createRoomInfo)

    }


    /*

    // MARK: - Navigation


    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        // Get the new view controller using segue.destinationViewController.

        // Pass the selected object to the new view controller.

    }

    */


}






//

//  SignupViewController.swift

//  FreeTalk

//

//  Created by stayfoolish on 2018. 9. 5..

//  Copyright © 2018년 stayfoolish. All rights reserved.

//


import UIKit

import Firebase


class SignupViewController: UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate {

    

    @IBOutlet var imageView: UIImageView!

    

    @IBOutlet var email: UITextField!

    @IBOutlet var name: UITextField!

    

    @IBOutlet var password: UITextField!

   

    @IBOutlet var signup: UIButton!

    @IBOutlet var cancel: UIButton!

    

    let remoteConfig = RemoteConfig.remoteConfig()

    var color: String?


    override func viewDidLoad() {

        super.viewDidLoad()


        let statusBar = UIView()

        self.view.addSubview(statusBar)

        statusBar.snp.makeConstraints {(m) in

            m.right.top.left.equalTo(self.view)

            m.height.equalTo(20)

        }

        color = remoteConfig["splash_background"].stringValue

        

        statusBar.backgroundColor = UIColor(hex: color!)

        

        

        imageView.isUserInteractionEnabled = true

        imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imagePicker)))

        

        

        signup.backgroundColor = UIColor(hex: color!)

        cancel.backgroundColor = UIColor(hex: color!)

        

        signup.addTarget(self, action: #selector(signupEvent), for: .touchUpInside)

        cancel.addTarget(self, action: #selector(cancelevent), for: .touchUpInside)

        // Do any additional setup after loading the view.

    }

    @objc func imagePicker(){

        

        let imagePicker = UIImagePickerController()

        imagePicker.delegate = self

        imagePicker.allowsEditing = true

        imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary

        

        self.present(imagePicker, animated: true, completion: nil)

    }

    

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){

        imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage

        

        dismiss(animated: true, completion: nil)

    }

    

    @objc func signupEvent(){

        Auth.auth().createUser(withEmail: email.text!, password: password.text!) {(user, err) in

            let uid = user?.uid

            

            let image = UIImageJPEGRepresentation(self.imageView.image!, 0.1)

            

            Storage.storage().reference().child("userImages").child(uid!).putData(image!, metadata: nil, completion: { (data, error) in

             

                let imageUrl = data?.downloadURL()?.absoluteString

                let values = ["userName":self.name.text!,"profileImageUrl":imageUrl, "uid":Auth.auth().currentUser?.uid]

                

                Database.database().reference().child("users").child(uid!).setValue(values, withCompletionBlock:

                    { (err, ref) in

                        if(err==nil){

                            self.cancelevent()

                        }

                })

            })

        }

    }

    

    @objc func cancelevent(){

        self.dismiss(animated: true, completion: nil)

    }

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

    


    /*

    // MARK: - Navigation


    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        // Get the new view controller using segue.destinationViewController.

        // Pass the selected object to the new view controller.

    }

    */


}











+ Recent posts