-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewUserVC.swift
44 lines (38 loc) · 1.65 KB
/
NewUserVC.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// NewUserVC.swift
// CaseEvents
//
// Created by A❤Y on 4/29/16.
// Copyright © 2016 Xiaohan Wang. All rights reserved.
//
import UIKit
class NewUserVC: UIViewController {
@IBOutlet weak var email: UITextField!
@IBOutlet weak var password: UITextField!
@IBOutlet weak var alert: UILabel!
let uref = Firebase(url: "https://flickering-heat-8881.firebaseio.com/Users")
@IBAction func saveUser(sender: AnyObject) {
if let newemail = email.text, newpassword = password.text {
let ref = Firebase(url: "https://flickering-heat-8881.firebaseio.com")
ref.createUser(newemail, password: newpassword,
withValueCompletionBlock: { error, result in
if error != nil {
self.alert.text = "User name already exists!"
} else {
let uid = result["uid"] as? String
let newUserInfo = ["uid": uid!, "username": "None", "email": newemail, "faved": ""]
let newRef = self.uref.childByAppendingPath(uid)
newRef.setValue(newUserInfo)
print("Successfully created user account with uid: \(uid)")
self.performSegueWithIdentifier("accountcreated", sender: nil)
}
})
}
else {
self.alert.text = "Both fields are required!"
}
}
@IBAction func cancel(sender: AnyObject) {
self.performSegueWithIdentifier("accountcreated", sender: nil)
}
}