Ejemplo n.º 1
0
        public static LinkAccountModel ForUser(IDataContext context, IIdentity identity)
        {
            var user = context.GetUser(identity);

            var allProviders = OAuthWebSecurity.RegisteredClientData.Select(c => c.DisplayName).ToArray();

            //  Match each linked provider to the member of allProviders as allProviders has proper casing (Google, not google)
            var linkedProviders = OAuthWebSecurity.GetAccountsFromUserName(user.MembershipUserIdentifier)
                .Select(lp => allProviders.Single(ap => ap.ToLower() == lp.Provider.ToLower()))
                .ToArray();

            var loginMethodCount = linkedProviders.Count() + (OAuthWebSecurity.HasLocalAccount(user.UserId) ? 1 : 0);

            var model = new LinkAccountModel()
            {
                OpenIDProvidersLinked = linkedProviders,
                OpenIDProvidersAvailable = allProviders.Where(p => !linkedProviders.Contains(p)),
                AllowRemovingLogin = loginMethodCount > 1
            };
            return model;
        }
Ejemplo n.º 2
0
        public static LinkAccountModel ForUser(IDataContext context, IIdentity identity)
        {
            var user = context.GetUser(identity);

            var allProviders = OAuthWebSecurity.RegisteredClientData.Select(c => c.DisplayName).ToArray();

            //  Match each linked provider to the member of allProviders as allProviders has proper casing (Google, not google)
            var linkedProviders = OAuthWebSecurity.GetAccountsFromUserName(user.MembershipUserIdentifier)
                                  .Select(lp => allProviders.Single(ap => ap.ToLower() == lp.Provider.ToLower()))
                                  .ToArray();

            var loginMethodCount = linkedProviders.Count() + (OAuthWebSecurity.HasLocalAccount(user.UserId) ? 1 : 0);

            var model = new LinkAccountModel()
            {
                OpenIDProvidersLinked    = linkedProviders,
                OpenIDProvidersAvailable = allProviders.Where(p => !linkedProviders.Contains(p)),
                AllowRemovingLogin       = loginMethodCount > 1
            };

            return(model);
        }