I have username, email and password textfields and register button
when i type a userName that is not in backendless users table, everything works fine.
but lets say i have user1 in my backendless users table and i try to register user1, the code works and tells me that the name is used, then if i change user1 to user (which doesn’t exist in the users table) the app will crush saying that password is required. Below are my 3 functions and the error log. Would really appreciate if you could look at it and help me out.
@IBAction func registerTap(sender: AnyObject)
if usernameTextfield.text != “” && emailTextfield.text != “” && passwordTextfield.text != “”{
//checking if username is available
userSearch(usernameTextfield.text!)
} else {
print(“All fields are required, including Profile Photo and at least one Skill”)
}
}
func userSearch(user: String) {
let whereClause = “name = ‘(user)’”
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = whereClause
let dataStore = backendless.persistenceService.of(BackendlessUser.ofClass())
dataStore.find(dataQuery, response: { (users : BackendlessCollection!) -> Void in
let users = users.data as! [BackendlessUser]
if users.count == 0 {
print(“doesnt have same user”)
self.register(self.emailText.text!, username: self.Username.text!, password: self.PasswordText.text!)
} else {
print(“user exist”)
}
}, error: { ( fault : Fault!) -> () in
print(“Server reported and error: (fault)”)
}
)
}
func register(email: String, username: String, password: String) {
print("my email: (email)
print("my username: (username)
print("my password: (password)
newUser = BackendlessUser()
newUser!.email = email
newUser!.password = password
newUser!.name = username
print("user email: (newUser.email)
print("user username: (newUser.name)
print("user password: (newUser.password)
backendless.userService.registering(newUser, response: { (registeredUser : BackendlessUser!) -> () in
//login user
},
error: { ( fault : Fault!) -> () in
Print(“Couldn’t register: (fault)”)
}
)
}
ERROR LOG
//when i tried to register existing user name
user exist
//the i tried again with different username
doesnt have same user
my email: user@mail.com
my username: user
my password: password
user email: nil
user username: nil
user password: nil
Couldn’t register: FAULT = ‘3011’ [Property ‘password’ is required] <Property ‘password’ is required>