Skip to content

Commit

Permalink
fixed errors with reg/login. added alertviews
Browse files Browse the repository at this point in the history
  • Loading branch information
skucheria committed Sep 20, 2019
1 parent 7b5e3f6 commit e09979d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions Helpers/LoginHandlers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ extension LoginVC : UIImagePickerControllerDelegate, UINavigationControllerDeleg
if loginRegSegment.selectedSegmentIndex == 1{ // jif registering
if (email.isEmpty || password.isEmpty || name.isEmpty || self.profileImageView.image == nil){ // if any fields are missing, dont allow registration
// incomplete registration info, dont do anything
print("not enough info for registering")
let alert = UIAlertController(title: "Please enter fill all fields and select profile picture!", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}}))
self.present(alert, animated: true, completion: nil)
}
else{
Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
Expand All @@ -64,7 +74,18 @@ extension LoginVC : UIImagePickerControllerDelegate, UINavigationControllerDeleg
print("user info? ", user?.user.uid)
}
else{
print(error!)
let alert = UIAlertController(title: "A user already exists with this email!", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}}))
self.present(alert, animated: true, completion: nil)
return
}
//save user here
let values = ["name": name, "email": email ]
Expand Down Expand Up @@ -99,7 +120,17 @@ extension LoginVC : UIImagePickerControllerDelegate, UINavigationControllerDeleg
else{ // if logging in
if (email.isEmpty || password.isEmpty){ // if any fields are missing, dont allow registration
// incomplete registration info, dont do anything
print("not enough info for logging in")
let alert = UIAlertController(title: "Please enter email and password!", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}}))
self.present(alert, animated: true, completion: nil)
}
else{ // do the logging in
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
Expand Down
Binary file not shown.

0 comments on commit e09979d

Please sign in to comment.