如何从Xamarin应用程序在沙发上创建用户?

问题描述 投票:1回答:1

我正在创建一个使用Couchbase Lite,同步网关和Couchbase服务器的xamarin应用程序,

我遵循了本教程:https://docs.couchbase.com/userprofile-couchbase-mobile/sync/userprofile/xamarin/userprofile_sync.html(但我使用服务器:127.0.0.1而不是海象)

这里是从同步网关的配置文件中创建用户,以便能够在服务器上同步用户及其数据,但是我需要从应用程序本身而不是从配置文件中创建用户,我该怎么做请吗?

这是我在其中创建用户的配置文件:

    {
     "log": ["*","Debug"],
     "databases": {
     "userprofile": {
     "server": "http://127.0.0.1:8091",
     "bucket": "userprofile",
     "username": "Maria", 
     "password": "123456", 
     "enable_shared_bucket_access": true, 
     "import_docs": "continuous",
     "num_index_replicas": 0, 
     "delta_sync" :{"enabled":true},
      "users": {
      "Maria": { "password": "123456"},
      "Mina": { "password": "123456"},
      "GUEST": { "disabled": false, "admin_channels": ["*"] }
  },
      "sync": `
      function sync(doc, oldDoc) {

     /* Authorization */

     // Verify the user making the request is the same as the one in doc's email
     requireUser(doc.email);
     /* Data Validation */

  if (!isDelete()) {
  // Validate the presence of email fields
  validateNotEmpty("email", doc.email);

  // Check if document is being created / added for first time
  // We allow any user to create the document
  if (isCreate()) {

    // Validate that the document Id _id is prefixed by owner.
    var expectedDocId = "user" + "::" + doc.email;

    if (expectedDocId != doc._id) {
        throw({forbidden: "user doc Id must be of form user:email"});

    }

  } else {       

     // Validate that the email hasn't changed.
    validateReadOnly("email", doc.email, oldDoc.email);
  }

}


 /* Routing */
 // Subsequent updates to document must be authorized
 var email = getEmail();

 // Add doc to the user's channel.
 channel("channel." + email);

 /* Access Control */
 // Give user read access to channel
 if (!isDelete()) {
 // Deletion of user document is essentially deletion of user
   access(email,"channel." + email)
 }

 // get type property 
 function getType() {
 return (isDelete() ? oldDoc.type : doc.type);
 }

 // get email Id property
function getEmail() {
return (isDelete() ? oldDoc.email : doc.email);
 }

 // Check if document is being created/added for first time
 function isCreate() {
 // Checking false for the Admin UI to work
  return ((oldDoc == false) || (oldDoc == null || oldDoc._deleted) && !isDelete());
 }

 // Check if this is a document update
 function isUpdate() {
  return (!isCreate() && !isDelete());
}

// Check if this is a document delete
 function isDelete() {
  return (doc._deleted == true);
}

// Verify that specified property exists
function validateNotEmpty(key, value) {
  if (!value) {
    throw({forbidden: key + " is not provided."});
  }
}

// Verify that specified property value has not changed during update
function validateReadOnly(name, value, oldValue) {
  if (value != oldValue) {
    throw({forbidden: name + " is read-only."});
    }
  }
 }
   `
  }
 }
}
c# authentication xamarin couchbase-lite couchbase-sync-gateway
1个回答
0
投票

在上面的示例中,您必须创建一个名为userprofile

© www.soinside.com 2019 - 2024. All rights reserved.