Beispiel #1
0
 private static bool CurrentUser(string boxUserId)
 {
     var accounts = new AccountLinker("webstudio")
         .GetLinkedObjectsByHashId(HashHelper.MD5(string.Format("{0}/{1}", ProviderConstants.Box, boxUserId)));
     return
         accounts.Select(x =>
                             {
                                 try
                                 {
                                     return new Guid(x);
                                 }
                                 catch
                                 {
                                     return Guid.Empty;
                                 }
                             })
                 .Any(account => account == SecurityContext.CurrentAccount.ID);
 }
        private Guid GetUserGuid(string hashId)
        {
            var accounts = new AccountLinker(WebConfigurationManager.ConnectionStrings["webstudio"]).GetLinkedObjectsByHashId(hashId);

            foreach (var account in accounts.Select(x =>
            {
                try
                {
                    return new Guid(x);
                }
                catch
                {
                    return Guid.Empty;
                }
            }))
            {
                if (CoreContext.UserManager.UserExists(account) && account != Guid.Empty)
                {
                    return account;
                }
            }
            return Guid.Empty;
        }
        private static bool TryByHashId(string hashId, out Guid userId)
        {
            userId = Guid.Empty;
            if (string.IsNullOrEmpty(hashId))
            {
                return false;
            }

            var accountsStrId = new AccountLinker("webstudio").GetLinkedObjectsByHashId(hashId);
            userId = accountsStrId
                .Select(x =>
                {
                    try
                    {
                        return new Guid(x);
                    }
                    catch
                    {
                        return Guid.Empty;
                    }
                })
                .Where(x => x != Guid.Empty)
                .FirstOrDefault(x => CoreContext.UserManager.UserExists(x));

            return true;
        }