当前位置: 首页>>代码示例>>C#>>正文


C# IUsersService.Add方法代码示例

本文整理汇总了C#中IUsersService.Add方法的典型用法代码示例。如果您正苦于以下问题:C# IUsersService.Add方法的具体用法?C# IUsersService.Add怎么用?C# IUsersService.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IUsersService的用法示例。


在下文中一共展示了IUsersService.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryFinishMembershipLogin

        /// <summary>
        /// Logs the user in or creates the a site user account if the user does not exist, based on membership user.
        /// Sets the logged user in the session.
        /// </summary>
        /// <exception cref="ValidationException"></exception>
        /// <returns>The user id of the authenticated user</returns>
        public static int TryFinishMembershipLogin(SessionWrapper session, MembershipUser membershipUser, IUsersService service)
        {
            if (membershipUser == null)
            {
                throw new ArgumentNullException("Can not finish membership signin with membership not set.");
            }
            var siteUser = service.GetByProviderId(AuthenticationProvider.Membership, membershipUser.ProviderUserKey.ToString());

            if (siteUser == null)
            {
                //User does not exist on Nearforums db
                siteUser = new User();
                siteUser.UserName = membershipUser.UserName;
                siteUser.Email = membershipUser.Email;
                siteUser = service.Add(siteUser, AuthenticationProvider.Membership, membershipUser.ProviderUserKey.ToString());
            }
            session.SetUser(siteUser, AuthenticationProvider.Membership);

            return siteUser.Id;
        }
开发者ID:jorgebay,项目名称:nearforums,代码行数:26,代码来源:SecurityHelper.cs

示例2: OpenIdFinishLogin

        /// <summary>
        /// Logs the user in or creates the user account if the user does not exist.
        /// Sets the logged user in the session.
        /// </summary>
        public static int OpenIdFinishLogin(IAuthenticationResponse response, SessionWrapper session, IUsersService service, bool enableClaimsRequest)
        {
            string externalId = response.ClaimedIdentifier.ToString();
            User user = service.GetByProviderId(AuthenticationProvider.OpenId, externalId);

            var claimsResponse = response.GetExtension<ClaimsResponse>();
            string name = enableClaimsRequest ? claimsResponse.Nickname : response.FriendlyIdentifierForDisplay;

            if (user == null)
            {
                user = new User(0, name);

                if (enableClaimsRequest)
                {
                    user.Email = claimsResponse.Email;
                    user.BirthDate = claimsResponse.BirthDate;
                }

                user = service.Add(user, AuthenticationProvider.OpenId, externalId);
            }
            else
            {
                if (enableClaimsRequest && !claimsResponse.Email.Equals(user.Email, StringComparison.CurrentCultureIgnoreCase))
                {
                    user.Email = claimsResponse.Email;
                    service.Edit(user);
                }
            }

            session.SetUser(user, AuthenticationProvider.OpenId);

            return user.Id;
        }
开发者ID:jorgebay,项目名称:nearforums,代码行数:37,代码来源:SecurityHelper.cs


注:本文中的IUsersService.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。