1

我正在开发iOS应用程序。Couchbase服务器到iOS电话

对实现登录模块(用户名/密码,注册和忘记密码)有点困惑。

Couchbase的新手。使用Couchbase Enterprise Editon "http://192.168.1.126:8091/ui/index.html#/overview"在Xcode中设置Couchbase Lite,我不知道下一步是什么。有谁知道?

数据建模:文档JSON

User ("Set as the EMAIL ID") 
{ 
    _id:” ", 
    username::" ", 
    password::" ", 
    email::" ", 
    type:"user" 
} 

用户信息( “设置为电子邮件ID”)

{ 
    _id:” ", 
    description:" ", 
    fb_URL::" ", 
    Twitter::" ", 
    Gender::" ", 
    Age::"[min:, max:]", 
    type:"user" 
} 
+0

你看了示例应用程序?这是一个很好的方式来熟悉如何工作... https://github.com/couchbaselabs/ToDoLite-iOS – combinatorial

+0

将试试这:)大的帮助。 @combinatorial –

回答

2

用户可以同步网关配置文件中创建像这样:

{ 
    "databases": { 
    "app": { 
     "bucket": "walrus", 
     "users": { 
     "john": {"password": "pass"} 
     } 
    } 
    } 
} 

然后,为该用户启用iOS应用中的验证:

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

对于用户注册,您需要设置一个应用服务器以在Sync Gateway管理端口注册用户(默认为4985)。要注册一个用户:

$ curl -vX POST -H 'Content-Type: application/json' \ 
     -d '{"name": "user2", "password": "pass"}' \ 
     :4985/app/_user/ 

对于忘记的密码功能,应用服务器应当更新使用新密码的用户记录:

$ curl -vX PUT -H 'Content-Type: application/json' \ 
      -d '{"name": "user2", "password": "newpass"}' \ 
      :4985/app/_user/user2 
+0

但是Objective C中的实现如何工作?大的帮助。在此先感谢您:) @jamiltz –

+0

@AneneBernadette与Switft实现几乎完全相同...只需将[CBLManager sharedInstance]与CBLManager.sharedInstance()切换出来等。 – borrrden