Example #1
0
 private void CheckSessionAtPath(string sessionPath)
 {
     _session.SendAsyncRequest(HttpMethod.Get, sessionPath, null, (result, e) => {
         if (e != null)
         {
             // If not at /db/_session, try CouchDB location /_session
             var statusCode = ExceptionResolver.GetStatusCode(e);
             if (statusCode.HasValue && statusCode.Value == HttpStatusCode.NotFound &&
                 sessionPath == "_session")
             {
                 CheckSessionAtPath("/_session");
                 return;
             }
             else if (statusCode == HttpStatusCode.Unauthorized)
             {
                 Login();
             }
             else
             {
                 Log.To.Sync.I(Tag, "{0} session check failed: {1}", this, e);
                 OnFinished(e);
             }
         }
         else
         {
             var userName = result?.AsDictionary <string, object>()?.Get("userCtx")?.AsDictionary <string, object>()?.GetCast <string>("name");
             if (userName != null)
             {
                 // Found a login session!
                 Log.To.Sync.I(Tag, "{0}: Active session, logged in as '{1}'", this, new SecureLogString(userName, LogMessageSensitivity.PotentiallyInsecure));
                 OnFinished(null);
             }
             else
             {
                 // No current login session, so continue to regular login:
                 Login();
             }
         }
     });
 }