Пример #1
0
        static object GetSignUpForm(
            NancyContext context, 
            IDocumentSession documentSession)
        {
            context.Ensure("context");
            documentSession.Ensure("documentSession");

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

            var currentMember = context.GetCurrentMember(documentSession);

            if (currentMember != null)
                return 403;

            return new SignUpFormResponse();
        }
Пример #2
0
        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));
        }