コード例 #1
0
ファイル: MemberModule.cs プロジェクト: half-ogre/rpg-rooms
        static object GetMember(
            NancyContext context,
            IDocumentSession documentSession,
            string alias)
        {
            if (context == null) throw new ArgumentNullException("context");
            if (documentSession == null) throw new ArgumentNullException("documentSession");

            if (String.IsNullOrEmpty(alias))
                return 404;

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

            var member = documentSession.GetMemberByAlias(alias);
            if (member == null)
                return 404;

            var currentMember = context.GetCurrentMember(documentSession);
            Debug.Assert(currentMember != null, "`requireSignedUp()` should ensure the current member is not null.");
            if (!member.Alias.Equals(currentMember.Alias, StringComparison.OrdinalIgnoreCase))
                return 403;

            var rooms = documentSession.GetRoomsByOwner(member.Id);

            return new MemberResponse(member, rooms);
        }
コード例 #2
0
ファイル: MemberModule.cs プロジェクト: half-ogre/rpg-rooms
        static object DeleteMember(
            NancyContext context,
            IDocumentSession documentSession,
            string alias)
        {
            if (context == null) throw new ArgumentNullException("context");
            if (documentSession == null) throw new ArgumentNullException("documentSession");

            if (String.IsNullOrEmpty(alias))
                return 404;

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

            var memberToDelete = documentSession.GetMemberByAlias(alias);
            if (memberToDelete == null)
                return 404;

            var currentMember = context.GetCurrentMember(documentSession);
            Debug.Assert(currentMember != null, "`requireSignedUp()` should ensure the current member is not null.");

            if (!memberToDelete.Alias.Equals(currentMember.Alias, StringComparison.OrdinalIgnoreCase))
                return 403;

            documentSession.DeleteMember(memberToDelete.Id);

            context.SetAlert("Your membership was deleted.", type: AlertType.Success);

            context.SignOutOfTwitter();

            return context.Redirect(Paths.Home());
        }
コード例 #3
0
ファイル: MembersModule.cs プロジェクト: half-ogre/rpg-rooms
        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));
        }