Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/MGRAST/cgi/metagenomics.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@ use strict;
use warnings;
no warnings 'once';

use CGI;

use WebApplication;
use WebMenu;
use WebLayout;
use WebConfig;

use Conf;

my $cgi = new CGI();
if ($cgi->url =~ /^https/) {
if (! $cgi->param('action') || (($cgi->param('action') != 'perform_login') && ($cgi->param('action') != 'change_user_details')) ) {
my $url = $cgi->url;
$url =~ s/^https/http/;
print $cgi->redirect(-uri => $url);
}
}

eval {
&main;
};

if ($@)
{
my $cgi = new CGI();

print $cgi->header();
print $cgi->start_html();
Expand Down
40 changes: 33 additions & 7 deletions src/MGRAST/lib/resources/user.pm
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,38 @@ sub instance {
if ($error) {
$self->return_data( {"ERROR" => "could not connect to user database - $error"}, 503 );
}

# check if this is a reset password request
if (scalar(@$rest) == 1 && $rest->[0] eq 'resetpassword') {
# passwords may only be reset with a valid recaptcha
my $ua = $self->{agent};
$ua->env_proxy();
my $resp = $ua->post( 'http://www.google.com/recaptcha/api/verify', { privatekey => '6Lf1FL4SAAAAAIJLRoCYjkEgie7RIvfV9hQGnAOh',
remoteip => $ENV{'REMOTE_ADDR'},
challenge => $self->{cgi}->param('challenge'),
response => $self->{cgi}->param('response') }
);
if ( $resp->is_success ) {
my ( $answer, $message ) = split( /\n/, $resp->content, 2 );
if ( $answer !~ /true/ ) {
$self->return_data( {"ERROR" => "recaptcha failed"}, 400 );
}
} else {
$self->return_data( {"ERROR" => "recaptcha server could not be reached"}, 400 );
}

# if we get here, recaptcha is successful
# now check if the login and email address correspond
my $user = $master->User->get_objects( { login => $self->{cgi}->param('login'), email => $self->{cgi}->param('email') } );
if ($user && scalar(@$user)) {
$user = $user->[0];
&set_password($user, &generate_password(), 1);
$self->return_data( {"OK" => "password reset"}, 200 );

} else {
$self->return_data( {"ERROR" => "login and email do not match or are not registered"}, 400 );
}
}

# check if this is a user creation
if ($self->{method} eq 'POST') {
Expand Down Expand Up @@ -234,15 +266,9 @@ sub instance {
}

# check if this is an action request
my $requests = { 'resetpassword' => 1,
'setpassword' => 1,
my $requests = { 'setpassword' => 1,
'webkey' => 1 };
if (scalar(@$rest) > 1 && $requests->{$rest->[1]}) {
# reset password
if ($rest->[1] eq 'resetpassword') {
&set_password($user, &generate_password(), 1);
$self->return_data( {"OK" => "password reset"}, 200 );
}
# set password
if ($rest->[1] eq 'setpassword') {
if ($self->cgi->param('dwp')) {
Expand Down
14 changes: 13 additions & 1 deletion src/WebApplication/WebApplication.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,19 @@ sub get_user_info {
$info .= "<input type='text' title='Enter your login name here.' name='anonymous_login'>";
$info .= "<input type='submit' value='login' style='width:40px;cursor: pointer;' title='Click here to login!'>\n" .$self->page->end_form();
} elsif ($self->fancy_login) {
$info .= $self->page->start_form('login_form', { page => 'Login', action => 'perform_login' });

my $formstart = undef;
eval {
use Conf;
if ($Conf::secure_url) {
$formstart = "<form method='post' id='login_form' enctype='multipart/form-data' action='".$Conf::secure_url.$self->url()."' style='margin: 0px; padding: 0px;'>\n".$self->cgi->hidden(-name=>'action', -id=>'action', -value=>'perform_login', -override=>1).$self->cgi->hidden(-name=>'page', -id=>'page', -value=>'Login', -override=>1);
}
};
if (! $formstart) {
$formstart = $self->page->start_form('login_form', { action => 'perform_login', 'page' => 'Login' });
}

$info .= $formstart;
$info .= "<div id='login_box'><div id='login_left_txt'>EXISTING USERS &raquo;</div>";
$info .= "<div id='login_input_box'><div id='login_input_header'>LOGIN<a class='forgot' href='?page=Register' style='margin-left:32px;' title='click to register a new account'>REGISTER</a></div><div id='login_input_box'><input type='text' title='Enter your login name here.' name='login'></div></div>";
$info .= "<div id='login_input_box'>";
Expand Down
17 changes: 14 additions & 3 deletions src/WebApplication/WebComponent/Login.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ sub output {
my ($self) = @_;

# start the form
my $content = $self->application->page->start_form('login_form', { page => $self->application->page->name });
my $content = undef;

eval {
use Conf;
if ($Conf::secure_url) {
$content = "<form method='post' id='login_form' enctype='multipart/form-data' action='".$Conf::secure_url.$self->application->url()."' style='margin: 0px; padding: 0px;'>\n".$self->application->cgi->hidden(-name=>'page', -id=>'page', -value=>$self->application->page->name, -override=>1);
}
};
if (! $content) {
$content = $self->application->page->start_form('login_form', { page => $self->application->page->name });
}

# check for small version of login
if ($self->small_login) {
Expand Down Expand Up @@ -154,8 +164,9 @@ sub perform_login {
my $to = $self->{'target_page'}
|| $self->application->session->get_entry(-current => 1)
|| $self->application->default;
$self->application->redirect($to);

use Conf;
if (ref($to) eq 'HASH') { $to = $to->{page} || $self->application->default; }
print $self->application->cgi->redirect(-uri => $Conf::cgi_url."?page=".$to, -cookie => $self->application->session->cookie );
}
else {
$self->application->add_message('warning', "Sorry, you have no access to this web server. <a href='".$self->application->url."?page=Register&tab=existing&login=".$user->login."&email=".$user->email."'>Request access</a>");
Expand Down
14 changes: 13 additions & 1 deletion src/WebApplication/WebPage/AccountManagement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,19 @@ sub output {

# personal user information
$html .= "<h2>Personal Information</h2>";
$html .= $self->start_form('user_form', { action => 'change_user_details' } );

my $formstart = undef;
eval {
use Conf;
if ($Conf::secure_url) {
$formstart = "<form method='post' id='user_form' enctype='multipart/form-data' action='".$Conf::secure_url.$self->application->url()."' style='margin: 0px; padding: 0px;'>\n".$self->application->cgi->hidden(-name=>'action', -id=>'action', -value=>'change_user_details', -override=>1);
}
};
if (! $formstart) {
$formstart = $self->application->page->start_form('user_form', { action => 'change_user_details' });
}

$html .= $formstart;
$html .= "<table>";
$html .= "<tr><th> name</th><td><input type='text' name='firstname' value='" . encode_entities($user->firstname()) . "'></td></tr>";
$html .= "<tr><th>last name</th><td><input type='text' name='lastname' value='" . encode_entities($user->lastname()) . "'></td></tr>";
Expand Down