1

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"
}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Anne Bernadette
  • 93
  • 1
  • 12

1 Answers1

2

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
jamiltz
  • 1,144
  • 8
  • 15
  • But how the implementation works in Objective C? Big help. Thank you in advance :) @jamiltz – Anne Bernadette Jul 17 '16 at 17:06
  • @AnneBernadette Nearly exactly the same as the Switft implementations...just switch out CBLManager.sharedInstance() with [CBLManager sharedInstance] etc. – borrrden Jul 17 '16 at 21:49