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


C# IAuthSession.ConvertTo方法代码示例

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


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

示例1: OnAuthenticated

        public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
        {
            base.OnAuthenticated(authService, session, tokens, authInfo);

            //Populate all matching fields from this session to your own custom User table
            var user = session.ConvertTo<User>();
            user.Id = int.Parse(session.UserAuthId);
            user.GravatarImageUrl64 = !session.Email.IsNullOrEmpty()
                ? CreateGravatarUrl(session.Email, 64)
                : null;

            foreach (var authToken in session.ProviderOAuthAccess)
            {
                if (authToken.Provider == FacebookAuthProvider.Name)
                {
                    user.FacebookName = authToken.DisplayName;
                    user.FacebookFirstName = authToken.FirstName;
                    user.FacebookLastName = authToken.LastName;
                    user.FacebookEmail = authToken.Email;
                }
                else if (authToken.Provider == TwitterAuthProvider.Name)
                {
                    user.TwitterName = user.DisplayName = authToken.UserName;
                }
                else if (authToken.Provider == GoogleOpenIdOAuthProvider.Name)
                {
                    user.GoogleUserId = authToken.UserId;
                    user.GoogleFullName = authToken.FullName;
                    user.GoogleEmail = authToken.Email;
                }
                else if (authToken.Provider == YahooOpenIdOAuthProvider.Name)
                {
                    user.YahooUserId = authToken.UserId;
                    user.YahooFullName = authToken.FullName;
                    user.YahooEmail = authToken.Email;
                }
            }

            if (AppHost.AppConfig.AdminUserNames.Contains(session.UserAuthName)
                && !session.HasRole(RoleNames.Admin))
            {
                using (var assignRoles = authService.ResolveService<AssignRolesService>())
                {
                    assignRoles.Post(new AssignRoles {
                        UserName = session.UserAuthName,
                        Roles = { RoleNames.Admin }
                    });
                }
            }

            //Resolve the DbFactory from the IOC and persist the user info
            using (var db = authService.TryResolve<IDbConnectionFactory>().Open())
                db.Save(user);
        }
开发者ID:Wolfium,项目名称:SocialBootstrapApi,代码行数:54,代码来源:CustomUserSession.cs

示例2: SaveUserAuth

        public void SaveUserAuth(IAuthSession authSession)
        {
            var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
                ? (UserAuth)GetUserAuth(authSession.UserAuthId)
                : authSession.ConvertTo<UserAuth>();

            if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
                userAuth.Id = int.Parse(authSession.UserAuthId);

            userAuth.ModifiedDate = DateTime.UtcNow;
            if (userAuth.CreatedDate == default(DateTime))
                userAuth.CreatedDate = userAuth.ModifiedDate;

            mongoDatabase.GetCollection<UserAuth>(UserAuthCol);
            SaveUser(userAuth);
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:16,代码来源:MongoDbAuthRepository.cs

示例3: SaveUserAuth

		public void SaveUserAuth(IAuthSession authSession)
		{
            using (_session)
			{
				int idInt = int.Parse(authSession.UserAuthId);

				var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
                                   ? _session.Load<UserAuth>(idInt)
                                   : authSession.ConvertTo<UserAuth>();

				if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
					userAuth.Id = idInt;

				userAuth.ModifiedDate = DateTime.UtcNow;
				if (userAuth.CreatedDate == default(DateTime))
					userAuth.CreatedDate = userAuth.ModifiedDate;

                _session.Store(userAuth);
                _session.SaveChanges();
			}
		}
开发者ID:JackFong,项目名称:ServiceStack.Contrib,代码行数:21,代码来源:RavenUserAuthRepository.cs

示例4: SaveUserAuth

        public void SaveUserAuth(IAuthSession authSession)
        {
            var nhSession = GetCurrentSessionFn(sessionFactory);
            var userAuth = !string.IsNullOrEmpty(authSession.UserAuthId)
                ? nhSession.Load<UserAuthNHibernate>(int.Parse(authSession.UserAuthId))
                : authSession.ConvertTo<UserAuth>();

            if (userAuth.Id == default(int) && !string.IsNullOrEmpty(authSession.UserAuthId))
                userAuth.Id = int.Parse(authSession.UserAuthId);

            userAuth.ModifiedDate = userAuth.ModifiedDate;
            if (userAuth.CreatedDate == default(DateTime))
                userAuth.CreatedDate = userAuth.ModifiedDate;

            nhSession.Save(new UserAuthNHibernate(userAuth));
        }
开发者ID:rudygt,项目名称:ServiceStack,代码行数:16,代码来源:NHibernateUserAuthRepository.cs

示例5: SaveUserAuth

        public void SaveUserAuth(IAuthSession authSession)
        {
            using (var redis = factory.GetClient())
            {
                var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
                    ? GetUserAuth(redis, authSession.UserAuthId)
                    : authSession.ConvertTo<UserAuth>();

                if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
                    userAuth.Id = int.Parse(authSession.UserAuthId);

                userAuth.ModifiedDate = DateTime.UtcNow;
                if (userAuth.CreatedDate == default(DateTime))
                    userAuth.CreatedDate = userAuth.ModifiedDate;

                redis.Store(userAuth);
            }
        }
开发者ID:ELHANAFI,项目名称:ServiceStack,代码行数:18,代码来源:RedisAuthRepository.cs

示例6: SaveUserAuth

        public void SaveUserAuth(IAuthSession authSession)
        {
            var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
                ? Session.Load<UserAuthPersistenceDto>(int.Parse(authSession.UserAuthId))
                : authSession.ConvertTo<UserAuth>();

            if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
                userAuth.Id = int.Parse(authSession.UserAuthId);

            userAuth.ModifiedDate = userAuth.ModifiedDate;
            if (userAuth.CreatedDate == default(DateTime))
                userAuth.CreatedDate = userAuth.ModifiedDate;

            Session.Save(new UserAuthPersistenceDto(userAuth));
        }
开发者ID:JackFong,项目名称:ServiceStack.Contrib,代码行数:15,代码来源:NHibernateUserAuthRepository.cs

示例7: SaveUserAuth

        public void SaveUserAuth(IAuthSession authSession)
        {
            using (var db = dbFactory.Open())
            {
                var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
                    ? db.GetByIdOrDefault<UserAuth>(authSession.UserAuthId)
                    : authSession.ConvertTo<UserAuth>();

                if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
                    userAuth.Id = int.Parse(authSession.UserAuthId);

                userAuth.ModifiedDate = DateTime.UtcNow;
                if (userAuth.CreatedDate == default(DateTime))
                    userAuth.CreatedDate = userAuth.ModifiedDate;

                db.Save(userAuth);
            };
        }
开发者ID:remkoboschker,项目名称:ServiceStack,代码行数:18,代码来源:OrmLiteAuthRepository.cs

示例8: SaveUserAuth

        /// <summary>
        /// Save the UserAuth from the session.
        /// </summary>
        /// <param name="authSession">The auth session.</param>
        public void SaveUserAuth(IAuthSession authSession)
        {
            var userAuth =
                !string.IsNullOrEmpty(authSession.UserAuthId)
                    ? this.GetUserAuth(authSession.UserAuthId)
                    : authSession.ConvertTo<LightSpeed.UserAuth>();

            if (userAuth.Id == default(int)
                && !string.IsNullOrEmpty(authSession.UserAuthId))
            {
                userAuth.Id = int.Parse(authSession.UserAuthId);
            }

            this.SaveUserAuth(userAuth);
        }
开发者ID:hhandoko,项目名称:ServiceStack.Authentication.LightSpeed,代码行数:19,代码来源:LightSpeedUserAuthRepository.cs


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