2 package SGN
::Controller
::User
;
6 BEGIN { extends
'Catalyst::Controller' };
8 sub login
:Path
('/user/login') Args
(0) {
12 $c->stash->{goto_url
} = $c->req->param("goto_url");
14 print STDERR
"GOTOURL=".$c->stash->{goto_url
}."\n";
15 $c->stash->{template
} = '/user/login.mas';
18 sub new_user
:Path
('/user/new') Args
(0) {
22 # Redirect to the login page and display the new user form
23 $c->res->redirect('/user/login?goto_url=/&new_user=1');
27 sub update_account
:Path
('/user/update') Args
(0) {
32 $c->res->redirect('/user/login');
36 $c->stash->{logged_in_username
} = $c->user()->get_username();
37 $c->stash->{private_email
} = $c->user()->get_private_email();
39 $c->stash->{template
} = '/user/change_account.mas';
42 sub confirm_user
:Path
('/user/confirm') Args
(0) {
46 my $confirm_code = $c->req->param('confirm_code');
47 my $username = $c->req->param('username');
49 if ($c->config->{disable_account_confirm
}) {
50 $c->stash->{template
} = '/generic_message.mas';
51 $c->stash->{message
} = 'Account confirmation is disabled on this site. Please contact nm529@cornell.edu to confirm your account.';
55 my $sp = CXGN
::People
::Login
->get_login( $c->dbc()->dbh(), $username );
58 confirm_failure
($c, "Username \"$username\" was not found.");
62 if ( !$sp->get_confirm_code() ) {
63 confirm_failure
($c, "No confirmation is required for user <b>$username</b>. This account has already been confirmed. <p><a href='/user/login'>[Login Page]</a></p>");
67 if ( $sp->get_confirm_code() ne $confirm_code ) {
68 confirm_failure
($c, "Confirmation code is not valid!\n");
72 $sp->set_disabled(undef);
73 $sp->set_confirm_code(undef);
74 $sp->set_private_email( $sp->get_pending_email() );
78 # Send confirmation to user, if manual confirmation is enabled
79 if ( $c->config->{user_registration_admin_confirmation
} && $c->config->{user_registration_admin_confirmation_email
} ) {
80 my $host = $c->config->{main_production_site_url
};
81 my $project_name = $c->config->{project_name
};
82 my $subject="[$project_name] New Account Confirmed";
83 my $body=<<END_HEREDOC;
85 Your new account on $project_name with the username \"$username\" has been confirmed.
87 You can now login using your account credentials:
93 Please do *NOT* reply to this message. If you have any trouble logging into your
94 account or have any other questions, please use the contact form instead:
98 CXGN::Contact::send_email($subject,$body,$sp->get_pending_email());
101 $c->stash->{template} = '/generic_message.mas';
102 $c->stash->{message} = "Confirmation successful for username <b>$username</b>";
105 sub confirm_failure {
109 $c->stash->{template} = '/generic_message.mas';
110 $c->stash->{message} = "Sorry, this confirmation code is invalid. Please check that your complete confirmation URL has been pasted correctly into your browser. ($reason)";
114 sub reset_password_form :Path('/user/reset_password_form') Args(0) {
118 my $token = $c->req->param('reset_password_token');
122 my $person_id = CXGN::People::Login->get_login_by_token($c->dbc->dbh(), $token);
124 $c->stash->{message} = "The provided password reset link is invalid. Please try again with another link.";
125 $c->stash->{template} = '/generic_message.mas';
129 my $person = CXGN::People::Person->new($c->dbc->dbh(), $person_id);
130 $c->stash->{token} = $token;
131 $c->stash->{person_id} = $person_id;
132 $c->stash->{username} = $person->get_username();
133 $c->stash->{template} = '/user/reset_password_form.mas';
136 $c->stash->{message} = "No token provided. Please try again.";
137 $c->stash->{template} = '/generic_message.mas';
142 sub quick_create_account :Path('/user/admin/quick_create_account') {
147 $c->forward('/user/login');
151 $c->stash->{template} = '/user/quick_create_account.mas';