problem registering user (error code 3011)

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>

Hi David,
Please explain more precisely, do you try to UPDATE user if it exists and the request fails?
Artur

First, please, upgrade the latest Backendless SDK via CocoaPods (3.0.32 release) or from ios-SDK github (CommLibiOS and backendless).

Then, investigate this our sample project - it demonstrates how a registering have to be do.

Hi Artur,

No I dont try to Update the user. This is what I have:

  1. Before user can register, I do a check to see if username is used by other user (users cannot have same email or username).

so before I call the function to register a user, im calling a function tat searches users table with where clause name = to provided username. If there is no user with that name, the registration is called.

Lets take 2 scenarios.
In my users table, I have 2 users (username: user1, email: user1@mail.com and username: user2, email user2@mail.com)

Scenario 1 :if I try to register user3 wirh email user3@mail.com, the name check function returns 0 matches and registration is successful, everything works.

Scenario 2: If I try to register user2 with email user3@mail.com the name check function returns that the user2 name is used, please choose another name. The i update the name to user3 and click register again. Name check function is called again and returns 0 matches and it calls register function which throws error Couldn’t register: FAULT = ‘3011’ [Property ‘password’ is required] <Property ‘password’ is required>.

And as you can see from error log, Im printing out email, username and password variables right before I create BackendlessUser and then I print the backendlessUser details right below.
This printout is from scenario 2.

I will test it when I get home. Will share my project as well so you can have a look

Hi, David.
According to the code you provided :

newUser = BackendlessUser()

print("user email: \(newUser.email)




print("user username: \(newUser.name)




print("user password: \(newUser.password)




backendless.userService.registering(newUser, response: { ... }

you print the values of newUser before registering him. Here’s you output for this:

user email: nil

user username: nil

user password: nil

It looks like you are trying to register user without password and get the corresponding error message.
Please check it again - the password should not be nil when you register user.

Hi Anatoli,

You dont need to register user in backendless to be able to print his info.
In creating user and setting the values of its name, password and email.

if you look at the code, you can see that the values i set are not nil, but they dont get setted for some reason because when i print the backendless user info they are nil.

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)")





David, it is not covered by Backendless Support.

Just use some more time for debugging your app and I’m sure you’ll find the reason of error.

This issue is fixed, please update the latest Backendless SDK (pod 3.0.37 release) or from ios-SDK github (CommLibiOS and backendless).