error message return if image processing fails
[sgn.git] / cgi-bin / solpeople / login.pl
blob01fcd25e520ee4420e349aa46c07e347aed43d74
1 use strict;
2 use warnings;
4 use CXGN::DB::Connection;
5 use CXGN::Page;
6 use CXGN::Login;
7 use SGN::Context;
9 my $page = CXGN::Page->new( "Login", "john" );
10 my $dbh = CXGN::DB::Connection->new();
11 my $context = SGN::Context->new;
12 my $login_controller = CXGN::Login->new($dbh);
14 if ( $context->get_conf('is_mirror') ) {
15 $page->message_page(
16 "Sorry, but you cannot log in to this site.",
17 "This site is a mirror of <a href=\"http://sgn.cornell.edu\">sgn.cornell.edu</a>. To log in to SGN, go to <a href=\"http://sgn.cornell.edu/solpeople/login.pl\">SGN's login page</a>."
21 if ( !$login_controller->login_allowed() ) {
22 $page->message_page(
23 "Sorry, but logins are disabled while our server undergoes maintenance.",
24 "Logins should be available again within 24 hours. Should this condition persist, please contact <a href=\"mailto:sgn-feedback\@sgn.cornell.edu\">sgn-feedback\@sgn.cornell.edu</a>."
28 my ( $username, $password, $goto_url, $logout ) =
29 $page->get_arguments( "username", "pd", "goto_url", "logout" );
31 my $message = "Already have an account? Please log in using the form below.";
33 my $referer = $ENV{HTTP_REFERER} || '';
34 if ( $referer =~ m|http://[^/]+/index.pl| ) {
36 # if they were on the front page, send them to "My SGN"
37 $goto_url ||= "/solpeople/top-level.pl";
39 elsif ( $referer =~ m|account-confirm.pl| ) {
41 # if they just confirmed their account, send them to "My SGN"
42 $goto_url = "/solpeople/top-level.pl";
44 else {
46 # if they were anywhere else, send them to the referring page
47 $goto_url ||= $referer;
51 if ( $logout && $logout eq "yes" ) #if we are in the process of logging out
53 $login_controller->logout_user();
58 if ( $username && $password ) #else if we are in the process of logging in
60 my $login_info = $login_controller->login_user( $username, $password );
62 #print STDERR "loggin in: $username\n";
63 my $person_id = $login_info->{person_id};
65 #print STDERR "sp_person_id: $person_id\n";
66 my $account_disabled = $login_info->{account_disabled};
67 my $logins_disabled = $login_info->{logins_disabled};
68 my $incorrect_password = $login_info->{incorrect_password};
69 my $duplicate_cookie = $login_info->{duplicate_cookie_string};
70 if ($logins_disabled) #if the whole system is disabled, print a message
72 $page->message_page("Sorry, but this login system is disabled.");
74 elsif ($account_disabled) #if their account is disabled, print a message
76 $page->message_page(
77 "Account for user $username is disabled for reason '$account_disabled'.",
78 "If your account has not been confirmed, check your email for a confirmation from SGN."
81 elsif ($incorrect_password) #if their password is wrong, print a message
83 $page->message_page( "Incorrect username or password.",
84 "<a href=\"send-password.pl\">[Lost password]</a>" );
86 elsif ($duplicate_cookie) #if we couldn't generate a unique cookie string
88 $page->error_page(
89 "Sorry but the login system failed.",
90 "Please try again.",
91 "failed to generate new cookie string",
92 "Our random login cookie generator generated a duplicate value!"
95 elsif ($person_id) #if their username and password matched
97 if ($goto_url
98 ) #if they came from trying to work somewhere else, send them back
101 #if we logged in from having just logged out,
102 #make sure we don't get sent back to the logout page:
103 if ( $goto_url =~ /login\.pl/ ) {
104 $goto_url = "/solpeople/top-level.pl";
107 $page->client_redirect($goto_url);
109 else #else they are just getting started, so send them to the menu page
111 $page->client_redirect("top-level.pl");
115 else #else we not trying to log in yet
117 if ( $login_controller->has_session()
118 ) #if there's no good reason for them to be here, send them to the menu page
120 $page->client_redirect("top-level.pl");
125 $page->header( 'Sol Genomics Network', 'Login' );
126 print <<END_HTML;
127 <div align="center">$message</div>
128 <div align="center">Your browser must accept cookies for this interface to work correctly.</div><br/>
130 <div class="container-fluid">
131 <div class="row">
132 <div class="col-sm-2 col-md-3 col-lg-3">
133 </div>
134 <div class="col-sm-8 col-md-6 col-lg-6" align="center">
135 <form class="form-horizontal" role="form" name="login" method="post" action="/solpeople/login.pl">
136 <div class="form-group">
137 <label class="col-sm-3 control-label">Username: </label>
138 <div class="col-sm-9">
139 <input class="form-control" id="unamefield" type="text" name="username" value="" />
140 </div>
141 </div>
142 <div class="form-group">
143 <label class="col-sm-3 control-label">Password: </label>
144 <div class="col-sm-9">
145 <input class="form-control" type="password" name="pd" value="" /><input type="hidden" name="goto_url" value="$goto_url" />
146 </div>
147 </div>
148 <button class="btn btn-primary" type="submit" name="login" value="Login" >Login</button>
149 </form>
150 </div>
151 <div class="col-sm-2 col-md-3 col-lg-3">
152 </div>
153 </div>
154 </div>
155 <br/>
157 <!--
158 <form name="login" method="post" action="/solpeople/login.pl">
159 <table style="padding: 2em" summary="" cellpadding="2" cellspacing="0" border="0" align="center">
160 <tr><td>Username</td><td><input class="form-control" id="unamefield" type="text" name="username" size="30" value="" /></td></tr>
161 <tr><td colspan="2"></td></tr>
162 <tr><td>Password</td><td><input class="form-control" type="password" name="pd" size="30" value="" /></td></tr>
163 <tr><td colspan="2" align="center"><br /><button class="btn btn-primary" type="submit" name="login" value="Login" >Login</button></td></tr>
164 </table>
165 <input type="hidden" name="goto_url" value="$goto_url" />
166 </form>
169 <div align="center">New user? <a href="/solpeople/new-account.pl">Sign up for an account</a>.<br />
170 Forgot your password? <a href="/solpeople/send-password.pl">Get it here</a>.</div>
171 <script language="JavaScript" type="text/javascript">
172 <!--
173 document.getElementById("unamefield").focus(1);
175 </script>
176 END_HTML
177 $page->footer();