Пример #1
0
        internal Task UpgradeToRevocableSessionAsync(Task toAwait, CancellationToken cancellationToken)
        {
            string sessionToken = SessionToken;

            return(toAwait.OnSuccess(_ => {
                return ParseSession.UpgradeToRevocableSessionAsync(sessionToken, cancellationToken);
            }).Unwrap().OnSuccess(t => {
                return SetSessionTokenAsync(t.Result);
            }).Unwrap());
        }
Пример #2
0
        internal static Task <string> UpgradeToRevocableSessionAsync(string sessionToken, CancellationToken cancellationToken)
        {
            if (sessionToken == null || SessionController.IsRevocableSessionToken(sessionToken))
            {
                return(Task <string> .FromResult(sessionToken));
            }

            return(SessionController.UpgradeToRevocableSessionAsync(sessionToken, cancellationToken).OnSuccess(t => {
                ParseSession session = ParseObject.FromState <ParseSession>(t.Result, "_Session");
                return session.SessionToken;
            }));
        }
Пример #3
0
        internal Task LogOutAsync(Task toAwait, CancellationToken cancellationToken)
        {
            string oldSessionToken = SessionToken;

            if (oldSessionToken == null)
            {
                return(Task.FromResult(0));
            }

            // Cleanup in-memory session.
            MutateState(mutableClone => {
                mutableClone.ServerData.Remove("sessionToken");
            });
            var revokeSessionTask = ParseSession.RevokeAsync(oldSessionToken, cancellationToken);

            return(Task.WhenAll(revokeSessionTask, CurrentUserController.LogOutAsync(cancellationToken)));
        }
Пример #4
0
        /// <summary>
        /// Gets the current <see cref="ParseSession"/> object related to the current user.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token</param>
        public static Task <ParseSession> GetCurrentSessionAsync(CancellationToken cancellationToken)
        {
            return(ParseUser.GetCurrentUserAsync().OnSuccess(t1 => {
                ParseUser user = t1.Result;
                if (user == null)
                {
                    return Task <ParseSession> .FromResult((ParseSession)null);
                }

                string sessionToken = user.SessionToken;
                if (sessionToken == null)
                {
                    return Task <ParseSession> .FromResult((ParseSession)null);
                }

                return SessionController.GetSessionAsync(sessionToken, cancellationToken).OnSuccess(t => {
                    ParseSession session = ParseObject.FromState <ParseSession>(t.Result, "_Session");
                    return session;
                });
            }).Unwrap());
        }
        /// <summary>
        /// Gets the current <see cref="ParseSession"/> object related to the current user.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token</param>
        public static Task <ParseSession> GetCurrentSessionAsync(CancellationToken cancellationToken)
        {
            return(ParseUser.GetCurrentUserAsync().OnSuccess(t1 => {
                ParseUser user = t1.Result;
                if (user == null)
                {
                    return Task <ParseSession> .FromResult((ParseSession)null);
                }

                string sessionToken = user.SessionToken;
                if (sessionToken == null)
                {
                    return Task <ParseSession> .FromResult((ParseSession)null);
                }

                return SessionController.GetSessionAsync(sessionToken, cancellationToken).OnSuccess(t => {
                    ParseSession session = (ParseSession)ParseObject.CreateWithoutData <ParseSession>(null);
                    session.HandleFetchResult(t.Result);
                    return session;
                });
            }).Unwrap());
        }