mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-03-19 04:19 pm

[dw-free] New create account flow

[commit: http://hg.dwscoalition.org/dw-free/rev/2e5ff7fd3f07]

http://bugs.dwscoalition.org/show_bug.cgi?id=373

These files were accidentally left out on the commit for the new account
creation flow.

Patch by [personal profile] janinedog.

Files modified:
  • cgi-bin/LJ/Widget/CreateAccountEnterCode.pm
  • cgi-bin/LJ/Widget/CreateAccountInviter.pm
  • cgi-bin/LJ/Widget/CreateAccountUpgrade.pm
  • htdocs/create/confirm.bml
  • htdocs/create/index.bml
  • htdocs/create/setup.bml
  • htdocs/create/upgrade.bml
--------------------------------------------------------------------------------
diff -r 6dc682922d77 -r 2e5ff7fd3f07 cgi-bin/LJ/Widget/CreateAccountEnterCode.pm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/LJ/Widget/CreateAccountEnterCode.pm	Thu Mar 19 16:19:40 2009 +0000
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+#
+# LJ::Widget::CreateAccountEnterCode
+#
+# This widget contains the form for giving your account creation code.
+#
+# Authors:
+#      Janine Costanzo <janine@netrophic.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+
+package LJ::Widget::CreateAccountEnterCode;
+
+use strict;
+use base qw(LJ::Widget);
+use Carp qw(croak);
+
+sub render_body {
+    my $class = shift;
+    my %opts = @_;
+
+    return "" unless $LJ::USE_ACCT_CODES;
+
+    my $get = $opts{get};
+
+    my $code = $get->{code};
+    my $errors;
+
+    my $error_msg = sub {
+        my ( $key, $pre, $post ) = @_;
+        my $msg = $errors->{$key};
+        return unless $msg;
+        return "$pre $msg $post";
+    };
+
+    # if we're in this widget with a code defined, then it's invalid
+    # rate limit code input; only allow one code every five seconds
+    if ( $code ) {
+        my $ip = LJ::get_remote_ip();
+        if ( LJ::MemCache::get( "invite_code_try_ip:$ip" ) ) {
+            LJ::MemCache::set( "invite_code_try_ip:$ip", 1, 5 );
+            return "<p>" . $class->ml( 'widget.createaccountentercode.error.toofast' ) . "</p>";
+        }
+        LJ::MemCache::set( "invite_code_try_ip:$ip", 1, 5 );
+        $errors->{code} = $class->ml( 'widget.createaccountentercode.error.invalidcode' );
+    }
+
+    my $ret;
+
+    $ret .= "<p>" . $class->ml( 'widget.createaccountentercode.info' ) . "</p>";
+
+    $ret .= "<form method='get' action='$LJ::SITEROOT/create.bml'>";
+    $ret .= "<?standout " . $class->ml( 'widget.createaccountentercode.code' ) . " ";
+    $ret .= LJ::html_text( {
+        name => 'code',
+        value => LJ::ehtml( $code ),
+        size => 21,
+        maxlength => 20,
+    } );
+    $ret .= " " . LJ::html_submit( $class->ml( 'widget.createaccountentercode.btn.proceed' ) );
+    $ret .= $error_msg->( 'code', '<br /><span class="formitemFlag">', '</span>' );
+    $ret .= " standout?>";
+    $ret .= LJ::html_hidden( ssl => $get->{ssl} ) if $get->{ssl};
+    $ret .= "</form>";
+
+    # FIXME: fill in the proper URL for the payment page when we know it
+    $ret .= "<p style='margin-top: 10px;'>" . $class->ml( 'widget.createaccountentercode.pay', { aopts => "href='#'", sitename => $LJ::SITENAMESHORT } ) . "</p>";
+
+    return $ret;
+}
+
+1;
diff -r 6dc682922d77 -r 2e5ff7fd3f07 cgi-bin/LJ/Widget/CreateAccountInviter.pm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/LJ/Widget/CreateAccountInviter.pm	Thu Mar 19 16:19:40 2009 +0000
@@ -0,0 +1,142 @@
+#!/usr/bin/perl
+#
+# LJ::Widget::CreateAccountInviter
+#
+# This widget contains the form for adding watch/trust edges for the person who
+# invited you to the site, as well as join/watch edges for some of their
+# relevant communities.
+#
+# Authors:
+#      Janine Costanzo <janine@netrophic.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+
+package LJ::Widget::CreateAccountInviter;
+
+use strict;
+use base qw(LJ::Widget);
+use Carp qw(croak);
+
+sub render_body {
+    my $class = shift;
+    my %opts = @_;
+
+    my $u = LJ::get_effective_remote();
+    my $post = $opts{post};
+    my $from_post = $opts{from_post};
+    my $errors = $from_post->{errors};
+
+    my $inviter = $u ? $u->who_invited : undef;
+    return "" unless LJ::isu( $inviter );
+
+    my $error_msg = sub {
+        my ( $key, $pre, $post ) = @_;
+        my $msg = $errors->{$key};
+        return unless $msg;
+        return "$pre $msg $post";
+    };
+
+    my $ret;
+    $ret .= "<h2>" . $class->ml( 'widget.createaccountinviter.title' ) . "</h2>";
+
+    $ret .= $class->html_hidden( from => $inviter->user );
+
+    if ( $u->can_trust( $inviter ) ) {
+        my $inviter_trust_name = 'inviter_trust_' . $inviter->id;
+        $ret .= $class->html_check(
+            name     => $inviter_trust_name,
+            value    => 1,
+            selected => defined $post->{$inviter_trust_name} ? $post->{$inviter_trust_name} : 1,
+            id       => $inviter_trust_name,
+        );
+        $ret .= " <label for='$inviter_trust_name'>" . $class->ml( 'widget.createaccountinviter.addinviter.trust', { user => $inviter->ljuser_display } ) . "</label><br />";
+    }
+
+    if ( $u->can_watch( $inviter ) ) {
+        my $inviter_watch_name = 'inviter_watch_' . $inviter->id;
+        $ret .= $class->html_check(
+            name     => $inviter_watch_name,
+            value    => 1,
+            selected => defined $post->{$inviter_watch_name} ? $post->{$inviter_watch_name} : 1,
+            id       => $inviter_watch_name,
+        );
+        $ret .= " <label for='$inviter_watch_name'>" . $class->ml( 'widget.createaccountinviter.addinviter.watch', { user => $inviter->ljuser_display } ) . "</label><br />";
+    }
+
+    my %comms = $inviter->relevant_communities;
+    if ( keys %comms ) {
+        $ret .= "<br />";
+
+        my $i = 0;
+        foreach my $commid ( sort { $comms{$a}->{u}->display_username cmp $comms{$b}->{u}->display_username } keys %comms ) {
+            last if $i >= 20;
+
+            my $commu = $comms{$commid}->{u};
+
+            my $note_mm = $comms{$commid}->{istatus} eq 'mm' ? ' *' : '';
+            my $note_moderated = $commu->is_moderated_membership ? ' **' : ''; # we will only get moderated or open communities
+            my $comm_join_name = "inviter_join_$commid";
+
+            $ret .= $class->html_check(
+                name     => $comm_join_name,
+                value    => 1,
+                selected => defined $post->{$comm_join_name} ? $post->{$comm_join_name} : 0,
+                id       => $comm_join_name,
+            );
+            $ret .= " <label for='$comm_join_name'>";
+            $ret .= $class->ml( 'widget.createaccountinviter.addcomms', { user => $commu->ljuser_display, name => $commu->name_html } );
+            $ret .= "$note_mm$note_moderated</label><br />";
+
+            $i++;
+        }
+
+        $ret .= "<div style='margin: 10px;'>";
+        $ret .= "<?de * " . $class->ml( 'widget.createaccountinviter.addcomms.note.mm', { user => $inviter->ljuser_display } ) . " de?>";
+        $ret .= "<?de ** " . $class->ml( 'widget.createaccountinviter.addcomms.note.moderated' ) . " de?>";
+        $ret .= "</div>";
+    }
+
+    return $ret;
+}
+
+sub handle_post {
+    my $class = shift;
+    my $post = shift;
+    my %opts = @_;
+
+    my $u = LJ::get_effective_remote();
+    my %from_post;
+
+    foreach my $key ( keys %$post ) {
+        if ( $key =~ /^inviter_trust_(\d+)$/ ) {
+            my $trustu = LJ::load_userid( $1 );
+            $u->add_edge( $trustu, trust => {} )
+                if LJ::isu( $trustu );
+        } elsif ( $key =~ /inviter_watch_(\d+)$/ ) {
+            my $watchu = LJ::load_userid( $1 );
+            $u->add_edge( $watchu, watch => {} )
+                if LJ::isu( $watchu );
+        } elsif ( $key =~ /inviter_join_(\d+)$/ ) {
+            my $joinu = LJ::load_userid( $1 );
+            if ( LJ::isu( $joinu ) ) {
+                # try to join the community
+                # if it fails and the community's moderated, send a join request and watch it
+                unless ( LJ::join_community( $u, $joinu, 1 ) ) {
+                    if ( $joinu->is_moderated_membership ) {
+                        LJ::comm_join_request( $joinu, $u );
+                        $u->add_edge( $joinu, watch => {} );
+                    }
+                }
+            }
+        }
+    }
+
+    return %from_post;
+}
+
+1;
diff -r 6dc682922d77 -r 2e5ff7fd3f07 cgi-bin/LJ/Widget/CreateAccountUpgrade.pm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/LJ/Widget/CreateAccountUpgrade.pm	Thu Mar 19 16:19:40 2009 +0000
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+#
+# LJ::Widget::CreateAccountUpgrade
+#
+# This widget contains information about why a user should get a paid account
+# and how they can get one.
+#
+# Authors:
+#      Janine Costanzo <janine@netrophic.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+
+package LJ::Widget::CreateAccountUpgrade;
+
+use strict;
+use base qw(LJ::Widget);
+use Carp qw(croak);
+
+sub render_body {
+    my $class = shift;
+    my %opts = @_;
+
+    my $ret;
+    $ret .= "<h2>" . $class->ml( 'widget.createaccountupgrade.title' ) . "</h2>";
+    $ret .= "<p class='intro'>" . $class->ml( 'widget.createaccountupgrade.text', { sitename => $LJ::SITENAMESHORT, aopts => "href='$LJ::HELPURL{paidaccountinfo}'" } ) . "</p>";
+    $ret .= $class->start_form;
+    $ret .= $class->html_submit( submit => $class->ml( 'widget.createaccountupgrade.btn.purchase' ) );
+    $ret .= $class->end_form;
+    $ret .= "<p style='margin-top: 10px;'><a href='$LJ::SITEROOT/create/confirm.bml'>" . $class->ml( 'widget.createaccountupgrade.nextstep' ) . "</a></p>";
+
+    return $ret;
+}
+
+sub handle_post {
+    my $class = shift;
+    my $post = shift;
+    my %opts = @_;
+
+    # FIXME: fill in the proper URL for the payment page when we know it
+    return BML::redirect( "$LJ::SITEROOT/" );
+}
+
+1;
diff -r 6dc682922d77 -r 2e5ff7fd3f07 htdocs/create/confirm.bml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/create/confirm.bml	Thu Mar 19 16:19:40 2009 +0000
@@ -0,0 +1,47 @@
+<?_c
+#
+# /create/confirm.bml
+#
+# This is the final page in the account creation flow. It confirms that your
+# account is created and gives you some ideas on where to go next.
+#
+# Authors:
+#      Janine Costanzo <janine@netrophic.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+_c?><?page
+body<=
+<?_code
+{
+    use strict;
+    use vars qw(%GET %POST $title $headextra @errors @warnings);
+
+    $title = BML::ml( '/create.bml.title', { sitename => $LJ::SITENAMESHORT } );
+
+    my $remote = LJ::get_remote();
+    return "<?needlogin?>" unless $remote;
+
+    return BML::redirect( "$LJ::SITEROOT/" )
+        unless $remote->is_personal;
+
+    my $ret;
+
+    $ret .= "<div id='create-page'>";
+    $ret .= LJ::Widget::CreateAccountProgressMeter->render( step => 4 );
+    $ret .= LJ::Widget::CreateAccountNextSteps->render;
+    $ret .= "</div>";
+
+    return $ret;
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>
diff -r 6dc682922d77 -r 2e5ff7fd3f07 htdocs/create/index.bml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/create/index.bml	Thu Mar 19 16:19:40 2009 +0000
@@ -0,0 +1,32 @@
+<?_c
+#
+# /create/index.bml
+#
+# This is just a stub page that redirects to /create.bml.
+#
+# Authors:
+#      Janine Costanzo <janine@netrophic.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+_c?><?page
+body<=
+<?_code
+{
+    use strict;
+    use vars qw/ %GET %POST $title $windowtitle $headextra @errors @warnings /;
+
+    return BML::redirect( "$LJ::SITEROOT/create.bml" );
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+windowtitle=><?_code return $windowtitle; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>
diff -r 6dc682922d77 -r 2e5ff7fd3f07 htdocs/create/setup.bml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/create/setup.bml	Thu Mar 19 16:19:40 2009 +0000
@@ -0,0 +1,80 @@
+<?_c
+#
+# /create/setup.bml
+#
+# This is the second page in the account creation flow. It allows you to set
+# some profile information and add the person you invited you (plus some of
+# their communities).
+#
+# Authors:
+#      Janine Costanzo <janine@netrophic.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+_c?><?page
+body<=
+<?_code
+{
+    use strict;
+    use vars qw(%GET %POST $title $headextra @errors @warnings);
+
+    $title = BML::ml( '/create.bml.title', { sitename => $LJ::SITENAMESHORT } );
+
+    my $remote = LJ::get_remote();
+    return "<?needlogin?>" unless $remote;
+
+    return BML::redirect( "$LJ::SITEROOT/" )
+        unless $remote->is_personal;
+
+    my %from_post;
+    if ( LJ::did_post() ) {
+        return "<?h1 $ML{'Error'} h1?><?p $ML{'error.invalidform'} p?>"
+            unless LJ::check_form_auth();
+
+        %from_post = LJ::Widget->handle_post( \%POST, ( qw( CreateAccountProfile Location CreateAccountInviter ) ) );
+
+        # next page unless errors
+        unless ( keys %{ $from_post{errors} } ) {
+            return BML::redirect( "$LJ::SITEROOT/create/confirm.bml" ) if $remote->get_cap( 'paid' );
+            return BML::redirect( "$LJ::SITEROOT/create/upgrade.bml" );
+        }
+    }
+
+    my $ret;
+
+    $ret .= "<div id='create-page'>";
+    $ret .= LJ::Widget::CreateAccountProgressMeter->render( step => 2 );
+
+    $ret .= "<form method='post' action='$LJ::SITEROOT/create/setup.bml'>";
+    $ret .= LJ::form_auth();
+
+    $ret .= LJ::Widget::CreateAccountProfile->render(
+        post => LJ::Widget::CreateAccountProfile->post_fields( \%POST ),
+        from_post => \%from_post,
+    );
+
+    if ( LJ::isu( $remote->who_invited ) ) {
+        $ret .= LJ::Widget::CreateAccountInviter->render(
+            post => LJ::Widget::CreateAccountProfile->post_fields( \%POST ),
+            from_post => \%from_post,
+        );
+    }
+
+    $ret .= LJ::html_submit( $ML{'/create.bml.btn.saveandcontinue'} );
+    $ret .= "</form>";
+
+    $ret .= "</div>";
+
+    return $ret;
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>
diff -r 6dc682922d77 -r 2e5ff7fd3f07 htdocs/create/upgrade.bml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/create/upgrade.bml	Thu Mar 19 16:19:40 2009 +0000
@@ -0,0 +1,52 @@
+<?_c
+#
+# /create/upgrade.bml
+#
+# This is the third page in the account creation flow. It only shows to users
+# who don't have a paid account, and it gives these users information about
+# paid accounts and why they should buy one.
+#
+# Authors:
+#      Janine Costanzo <janine@netrophic.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+_c?><?page
+body<=
+<?_code
+{
+    use strict;
+    use vars qw(%GET %POST $title $headextra @errors @warnings);
+
+    $title = BML::ml( '/create.bml.title', { sitename => $LJ::SITENAMESHORT } );
+
+    my $remote = LJ::get_remote();
+    return "<?needlogin?>" unless $remote;
+
+    return BML::redirect( "$LJ::SITEROOT/" )
+        unless $remote->is_personal && !$remote->get_cap( 'paid' );
+
+    if ( LJ::did_post() ) {
+        LJ::Widget->handle_post( \%POST, ( 'CreateAccountUpgrade' ) );
+    }
+
+    my $ret;
+
+    $ret .= "<div id='create-page'>";
+    $ret .= LJ::Widget::CreateAccountProgressMeter->render( step => 3 );
+    $ret .= LJ::Widget::CreateAccountUpgrade->render;
+    $ret .= "</div>";
+
+    return $ret;
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>
--------------------------------------------------------------------------------