Reputation: 93
I'm developing an iOS application.
Little bit confused about implementing the login module which the (Username/Password, Register and Forgot Password).
New to Couchbase. Used the Couchbase Enterprise Editon "http://192.168.1.126:8091/ui/index.html#/overview"
Set up the Couchbase Lite in Xcode and I dunno what's the next step. Does anyone knows?
Data Modeling: Documents JSON
User ("Set as the EMAIL ID")
{
_id:” ",
username::" ",
password::" ",
email::" ",
type:"user"
}
User Info ("Set as the EMAIL ID")
{
_id:” ",
description:" ",
fb_URL::" ",
Twitter::" ",
Gender::" ",
Age::"[min:, max:]",
type:"user"
}
Upvotes: 1
Views: 251
Reputation: 1144
Users can be created in the Sync Gateway configuration file like so:
{
"databases": {
"app": {
"bucket": "walrus",
"users": {
"john": {"password": "pass"}
}
}
}
}
Then, authentication in the iOS app is enabled for this user:
let manager = CBLManager.sharedInstance()
let database = try! manager.databaseNamed("app")
let url = NSURL(string: "http://localhost:4984/app")!
let push = database.createPushReplication(url)
let pull = database.createPullReplication(url)
push.authenticator = CBLAuthenticator.basicAuthenticatorWithName("john", password: "pass")
pull.authenticator = CBLAuthenticator.basicAuthenticatorWithName("john", password: "pass")
push.start()
pull.start()
For user registration, you'll need to set up an App Server to register users on the Sync Gateway Admin port (4985 by default). To register a user:
$ curl -vX POST -H 'Content-Type: application/json' \
-d '{"name": "user2", "password": "pass"}' \
:4985/app/_user/
For the forgotten password functionality, the App Server should update the user record with the new password:
$ curl -vX PUT -H 'Content-Type: application/json' \
-d '{"name": "user2", "password": "newpass"}' \
:4985/app/_user/user2
Upvotes: 2