Guest User

Untitled

a guest
Feb 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. private func saveUserInfo(firstLastName: String, user: User!, location: String, biography: String, password: String, phoneNumber: String){
  2. let locationRef = Global.refString
  3. let userInfo = ["firstLastName": firstLastName, "email": user.email!, "password": password, "location": location, "phoneNumber": phoneNumber, "biography": biography, "uid": user.uid, "photoURL": String(describing: user.photoURL!)] as [String : Any]
  4.  
  5. let userRef = dataBaseRef.child(locationRef!).child(user.uid)
  6. userRef.setValue(userInfo) { (error, ref) in
  7. if error == nil{
  8. print("USER SAVED")
  9. self.logIn(email: user.email!, password: password)
  10. }else{
  11. print(error?.localizedDescription)
  12.  
  13. }
  14. }
  15. }
  16.  
  17.  
  18.  
  19. func loadUserInfo(){
  20.  
  21. let locationRef = Global.refString
  22. let userRef = dataBaseRef.child(locationRef!).child(Auth.auth().currentUser!.uid)
  23.  
  24. userRef.observe(.value, with: { (snapshot) in
  25.  
  26. let user = Users(snapshot: snapshot)
  27.  
  28. if let username = user.name{
  29. self.nameLabel.text = username
  30. }
  31.  
  32. if let number = user.phoneNumber{
  33. self.phone = Int(number)
  34. }
  35. if let userLocation = user.location{
  36. self.bioLabel.text = userLocation
  37. }
  38. self.storageRef.storage.reference(forURL: imageOld).getData(maxSize: 10 * 1024 * 1024, completion: { (imgData, error) in
  39.  
  40. if error == nil {
  41. DispatchQueue.main.async {
  42. if let data = imgData {
  43. self.avatar.image = UIImage(data: data)
  44. }
  45. }
  46. }else {
  47. print(error!.localizedDescription)
  48.  
  49. }
  50. }
  51. )}
  52. }) { (error) in
  53. print(error.localizedDescription)
  54. }
  55. }
  56. }
  57.  
  58.  
  59.  
  60. struct Global
  61. {
  62. static var Location : String!
  63. static var usersListSent
  64. = [String]()
  65. static var refString: String!
  66. }
Add Comment
Please, Sign In to add comment