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


C# NancyContext.ReadSession方法代码示例

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


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

示例1: PostMember

        public static object PostMember(
            NancyContext context,
            IDocumentSession documentSession,
            string alias, 
            string emailAddress)
        {
            context.Ensure("context");
            documentSession.Ensure("documentSession");

            if (!context.IsSignedIn())
                return 403;

            var errors = new List<string>();
            errors.AddRange(fn.ValidateRequired("Alias", alias));
            errors.AddRange(fn.ValidateLength("Alias", alias, 32));
            errors.AddRange(fn.ValidateFormat("Alias", alias, new Regex("[a-z][a-z0-9_-]+")));
            errors.AddRange(fn.ValidateRequired("Email Address", emailAddress));
            errors.AddRange(fn.ValidateLength("Email Address", emailAddress, 1024));

            var member = documentSession.GetMemberByAlias(alias);
            if (member != null)
                errors.Add(Strings.AliasNotAvailable(alias));

            if (errors.Count > 0)
                return context.ModelWithStatus(new SignUpFormResponse(alias, emailAddress, errors), 400);

            var authType = context.ReadSession<string>(Constants.AuthTypeSessionKey);
            var authId = context.ReadSession<string>(Constants.AuthIdSessionKey);

            if (String.IsNullOrEmpty(authType))
                throw new InvalidOperationException(Strings.AuthTypeMissing());

            if (String.IsNullOrEmpty(authId))
                throw new InvalidOperationException(Strings.AuthIdMissing());

            member = documentSession.CreateMember(authType, authId, alias, emailAddress);

            var returnUrl = context.GetReturnUrl();

            return context.Redirect(returnUrl ?? Paths.Member(member.Alias));
        }
开发者ID:half-ogre,项目名称:rpg-rooms,代码行数:41,代码来源:MembersModule.cs

示例2: GetReceiver

        public static object GetReceiver(
            NancyContext context,
            IConfiguration configuration,
            IDocumentSession documentSession,
            string oAuthToken,
            string oAuthVerifier)
        {
            if (String.IsNullOrEmpty(oAuthToken))
                return 400;

            if (String.IsNullOrEmpty(oAuthVerifier))
                return 400;

            var storedToken = context.ReadSession<string>(Constants.TwitterAuth.SessionKey);
            if (storedToken == null ||
                !storedToken.Equals(
                    oAuthToken,
                    StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException("Stored OAuth token doesn't match incoming OAuth token.");
            }

            var oAuthRequest = OAuthRequest.ForAccessToken(
                configuration.TwitterAuthConsumerKey,
                configuration.TwitterAuthConsumerSecret,
                oAuthToken,
                oAuthVerifier);
            oAuthRequest.RequestUrl = Constants.TwitterAuth.AccessTokenUrl;

            var authResponse = fn.SendGet(
                new Uri(oAuthRequest.RequestUrl),
                addHeader => addHeader("Authorization", oAuthRequest.GetAuthorizationHeader()));

            var authParams = fn.ParseQueryString(authResponse);

            var twitterUserId = authParams[Constants.TwitterAuth.UserIdParamName];

            if (String.IsNullOrEmpty(twitterUserId))
                throw new InvalidOperationException("No user ID in the Twitter auth params.");

            var authId = GetOrCreateUser(context, twitterUserId);

                var location = GetRedirectLocation(context, authId, documentSession);

                var response = context.Redirect(location);

                var authenticationCookie = MakeCookie(authId);

                response.AddCookie(authenticationCookie);

                return response;
        }
开发者ID:half-ogre,项目名称:rpg-rooms,代码行数:52,代码来源:TwitterAuthReceiverModule.cs


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