Merge pull request #5205 from solgenomics/topic/generic_trial_upload
[sgn.git] / lib / SGN / Controller / User.pm
blobb307ae669ad4ceb55886a262ca5095b08ba8090f
2 package SGN::Controller::User;
4 use Moose;
6 BEGIN { extends 'Catalyst::Controller' };
8 sub login :Path('/user/login') Args(0) {
9 my $self = shift;
10 my $c = shift;
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) {
19 my $self = shift;
20 my $c = shift;
22 # Redirect to the login page and display the new user form
23 $c->res->redirect('/user/login?goto_url=/&new_user=1');
24 $c->detach();
27 sub update_account :Path('/user/update') Args(0) {
28 my $self = shift;
29 my $c = shift;
31 if (! $c->user()) {
32 $c->res->redirect('/user/login');
33 return;
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) {
43 my $self = shift;
44 my $c = shift;
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.';
52 return;
55 my $sp = CXGN::People::Login->get_login( $c->dbc()->dbh(), $username );
57 if ( !$sp ) {
58 confirm_failure($c, "Username \"$username\" was not found.");
59 return;
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>");
64 return;
67 if ( $sp->get_confirm_code() ne $confirm_code ) {
68 confirm_failure($c, "Confirmation code is not valid!\n");
69 return;
72 $sp->set_disabled(undef);
73 $sp->set_confirm_code(undef);
74 $sp->set_private_email( $sp->get_pending_email() );
76 $sp->store();
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:
88 $host
90 Thank you,
91 $project_name Team
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:
95 $host/contact/form
97 END_HEREDOC
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 {
106 my $c = shift;
107 my $reason = shift;
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) {
115 my $self = shift;
116 my $c = shift;
118 my $token = $c->req->param('reset_password_token');
120 my $person_id;
121 if ($token) {
122 my $person_id = CXGN::People::Login->get_login_by_token($c->dbc->dbh(), $token);
123 if (!$person_id) {
124 $c->stash->{message} = "The provided password reset link is invalid. Please try again with another link.";
125 $c->stash->{template} = '/generic_message.mas';
126 return;
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';
135 else {
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') {
143 my $self = shift;
144 my $c = shift;
146 if (!$c->user()) {
147 $c->forward('/user/login');
148 return;
151 $c->stash->{template} = '/user/quick_create_account.mas';