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
7 changes: 7 additions & 0 deletions src/MGRAST/cgi/metagenomics.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ sub main {
layout => $layout,
default => 'Home',
} );
if ($cgi->param('loginfail')) {
if ($cgi->param('loginfail') eq "password") {
$WebApp->add_message('warning', "Login or Password incorrect. Please try again.");
} else {
$WebApp->add_message('warning', "Sorry, you have no access to this web server.");
}
}
$WebApp->strict_browser(1);
$WebApp->page_title_prefix('MG-RAST - ');
$WebApp->show_login_user_info(1);
Expand Down
83 changes: 72 additions & 11 deletions src/MGRAST/lib/resources/user.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sub new {
"url" => [ 'uri', 'resource location of this object instance' ]
};

$self->{cv} = { verbosity => {'minimal' => 1, 'preferences' => 1, 'rights' => 1, 'scopes' => 1, 'full' => 1},
$self->{cv} = { verbosity => {'minimal' => 1, 'preferences' => 1, 'rights' => 1, 'scopes' => 1, 'full' => 1, 'session' => 1},
direction => {'asc' => 1, 'desc' => 1},
match => {'any' => 1, 'all' => 1}
};
Expand Down Expand Up @@ -403,7 +403,31 @@ sub instance {
$user->{scopes} = [];
@{$user->{scopes}} = map { { name => $_->{name},
description => $_->{description} } } @$scopes;

$user->{session} = {};
my $usession = $master->UserSession->get_objects( { user => $user } );
if (ref($usession) eq 'ARRAY' and scalar(@$usession)) {
$usession = $usession->[0];
$user->{session} = { error_page => $usession->{error_page},
session_id => $usession->{session_id},
error_parameters => $usession->{error_parameters},
current_page => $usession->{current_page},
timestamp => $usession->{timestamp},
previous_page => $usession->{previous_page},
current_parameters => $usession->{current_parameters},
previous_parameters => $usession->{previous_parameters} };
}
$user->{organization} = {};
my $uho = $master->OrganizationUsers->get_objects( { user => $user } );
if (ref($uho) eq 'ARRAY' and scalar(@$uho)) {
my $org = $uho->[0]->organization;
$user->{organization} = { country => $org->{country},
city => $org->{city},
date => $org->{date},
url => $org->{url},
name => $org->{name},
abbreviation => $org->{abbreviation},
location => $org->{location} };
}
}

# prepare data
Expand Down Expand Up @@ -549,17 +573,21 @@ sub query {
push(@$where, $str);
}
}
my $where_string = join(" AND ", @$where);
my $where_string2 = join(" AND ", @$where);
my $where_string = "";
if (scalar(@$where)) {
$where_string = "WHERE ".join(" AND ", @$where);
}

my $data = [];
my $total = $master->backend->get_rows('User', ["COUNT(*)"], $where_string, {})->[0]->[0];
my $total = $master->backend->get_rows('User', ["COUNT(*)"], $where_string2, {})->[0]->[0];
# get only basic data
if ($verb eq 'minimal') {
$data = $master->backend->get_rows('User', [], $where_string, { "sort_by" => [ "$order $dir LIMIT $limit OFFSET $offset" ], "row_as_hash" => 1 });
$data = $master->backend->get_rows('User', [], $where_string2, { "sort_by" => [ "$order $dir LIMIT $limit OFFSET $offset" ], "row_as_hash" => 1 });
}
# get the user preferences
elsif ($verb eq 'preferences') {
my $rows = $master->backend->get_rows( "(SELECT * FROM User WHERE $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN Preferences ON t1._id=Preferences.user ORDER BY t1.$order ".uc($dir), [], undef, {});
my $rows = $master->backend->get_rows( "(SELECT * FROM User $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN Preferences ON t1._id=Preferences.user ORDER BY t1.$order ".uc($dir), [], undef, {});
my $uhash = {};
my $order_array = [];
foreach my $row (@$rows) {
Expand All @@ -584,7 +612,7 @@ sub query {
}
# get the users rights
elsif ($verb eq 'rights') {
my $rows = $master->backend->get_rows( "(SELECT * FROM User WHERE $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN UserHasScope ON t1._id=UserHasScope.user JOIN Scope on Scope._id=UserHasScope.scope JOIN Rights ON Scope._id=Rights.scope ORDER BY t1.$order ".uc($dir), [], undef, {});
my $rows = $master->backend->get_rows( "(SELECT * FROM User $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN UserHasScope ON t1._id=UserHasScope.user JOIN Scope on Scope._id=UserHasScope.scope JOIN Rights ON Scope._id=Rights.scope ORDER BY t1.$order ".uc($dir), [], undef, {});
my $uhash = {};
my $order_array = [];
foreach my $row (@$rows) {
Expand Down Expand Up @@ -613,7 +641,7 @@ sub query {
}
# get the users scopes
elsif ($verb eq 'scopes') {
my $rows = $master->backend->get_rows( "(SELECT * FROM User WHERE $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN UserHasScope ON t1._id=UserHasScope.user JOIN Scope on Scope._id=UserHasScope.scope ORDER BY $order ".uc($dir), [], undef, {});
my $rows = $master->backend->get_rows( "(SELECT * FROM User $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN UserHasScope ON t1._id=UserHasScope.user JOIN Scope on Scope._id=UserHasScope.scope ORDER BY $order ".uc($dir), [], undef, {});
my $uhash = {};
my $order_array = [];
foreach my $row (@$rows) {
Expand All @@ -635,11 +663,15 @@ sub query {
foreach my $key (@$order_array) {
push(@$data, $uhash->{$key});
}
}
# get session statistics
elsif ($verb eq 'session') {

}
# get everything
else {
# _id 0 firstname 1 email 2 password 3 comment 4 entry_date 5 active 6 lastname 7 login 8 _id 9 user 10 _user_db 11 scope 12 _scope_db 13 granted 14 _id 15 application 16 _application_db 17 name 18 description 19 _id 20 granted 21 delegated 22 data_id 23 data_type 24 application 25 _application_db 26 name 27 scope 28 _scope_db 29
my $rows = $master->backend->get_rows( "(SELECT * FROM User WHERE $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN UserHasScope ON t1._id=UserHasScope.user JOIN Scope on Scope._id=UserHasScope.scope JOIN Rights ON Scope._id=Rights.scope ORDER BY $order ".uc($dir), [], undef, {});
my $rows = $master->backend->get_rows( "(SELECT * FROM User $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN UserHasScope ON t1._id=UserHasScope.user JOIN Scope on Scope._id=UserHasScope.scope JOIN Rights ON Scope._id=Rights.scope ORDER BY $order ".uc($dir), [], undef, {});
my $uhash = {};
my $order_array = [];
foreach my $row (@$rows) {
Expand All @@ -655,7 +687,9 @@ sub query {
comment => $row->[4],
rights => [],
scopes => {},
preferences => [] };
preferences => [],
organization => {},
session => {} };
}
push(@{$uhash->{$row->[8]}->{rights}}, { name => $row->[27],
data_type => $row->[24],
Expand All @@ -664,12 +698,37 @@ sub query {
delegated => $row->[22] });
$uhash->{$row->[8]}->{scopes}->{$row->[12]} = { name => $row->[18], description => $row->[19] };
}
$rows = $master->backend->get_rows( "(SELECT * FROM User WHERE $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN Preferences ON t1._id=Preferences.user ORDER BY t1.$order ".uc($dir), [], undef, {});
$rows = $master->backend->get_rows( "(SELECT * FROM User $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN Preferences ON t1._id=Preferences.user ORDER BY t1.$order ".uc($dir), [], undef, {});
foreach my $row (@$rows) {
# _id 0 firstname 1 email 2 password 3 comment 4 entry_date 5 active 6 lastname 7 login 8 _id 9 value 10 user 11 _user_db 12 application 13 _application_db 14 name 15

push(@{$uhash->{$row->[8]}->{preferences}}, { name => $row->[15], value => $row->[10] });
}
$rows = $master->backend->get_rows( "(SELECT * FROM User $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN UserSession ON t1._id=UserSession.user ORDER BY t1.$order ".uc($dir), [], undef, {});
foreach my $row (@$rows) {
# _id 0 firstname 1 email 2 password 3 comment 4 entry_date 5 active 6 lastname 7 login 8 _id 9 error_page 10 session_id 11 error_parameters 12 current_page 13 timestamp 14 previous_page 15 user 16 _user_db 17 current_parameters 18 previous_parameters 19

$uhash->{$row->[8]}->{session} = { error_page => $row->[10],
session_id => $row->[11],
error_parameters => $row->[12],
current_page => $row->[13],
timestamp => $row->[14],
previous_page => $row->[15],
current_parameters => $row->[18],
previous_parameters => $row->[19] };
}
$rows = $master->backend->get_rows( "(SELECT * FROM User $where_string ORDER BY $order ".uc($dir)." LIMIT $limit OFFSET $offset) AS t1 JOIN OrganizationUsers ON t1._id=OrganizationUsers.user JOIN Organization ON OrganizationUsers.organization=Organization._id ORDER BY t1.$order ".uc($dir), [], undef, {});
foreach my $row (@$rows) {
# _id 0 firstname 1 email 2 password 3 comment 4 entry_date 5 active 6 lastname 7 login 8 _id 9 user 10 _user_db 11 organization 12 _organization_db 13 _id 14 country 15 city 16 date 17 url 18 name 19 abbreviation 20 scope 21 _scope_db 22 loaction 23

$uhash->{$row->[8]}->{organization} = { country => $row->[15],
city => $row->[16],
date => $row->[17],
url => $row->[18],
name => $row->[19],
abbreviation => $row->[20],
location => $row->[23] };
}
foreach my $key (@$order_array) {
my $s = [];
foreach my $sc (keys(%{$uhash->{$key}->{scopes}})) {
Expand Down Expand Up @@ -717,6 +776,8 @@ sub prepare_data {
if (defined $u->{preferences}) { $obj->{preferences} = $u->{preferences} };
if (defined $u->{rights}) { $obj->{rights} = $u->{rights} };
if (defined $u->{scopes}) { $obj->{scopes} = $u->{scopes} };
if (defined $u->{session}) { $obj->{session} = $u->{session} };
if (defined $u->{organization}) { $obj->{organization} = $u->{organization} };

push(@$result, $obj);
}
Expand Down
45 changes: 21 additions & 24 deletions src/WebApplication/WebComponent/Login.pm
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,24 @@ sub perform_login {
return 1;
}

use Conf;
my $to = $self->{'target_page'} || $self->application->session->get_entry(-current => 1) || $self->application->default;
if (ref($to) eq 'HASH') { $to = $to->{page} || $self->application->default; }


# try to initialize user
my $user = $self->application->dbmaster->User->init( { login => $login } );
if (ref $user and crypt($password, $user->password) eq $user->password) {

# check for login dependencies that were created after the user got the account
if (ref $WebConfig::LOGIN_DEPENDENCIES) {

foreach my $d (@{$WebConfig::LOGIN_DEPENDENCIES->{$self->application->backend->name}}) {

# get the backend
my $d_backend = $self->application->dbmaster->Backend->init({ name => $d });
if (ref $d_backend) {

# create and grant the login right
my $back_app = WebApplication->new( $d_backend );
{
Expand All @@ -155,28 +160,20 @@ sub perform_login {
}
}
}
}

if ($user->active and ($user->has_right($self->application, 'login') || $Conf::open_gates)) {

$self->application->session->user($user);

my $to = $self->{'target_page'}
|| $self->application->session->get_entry(-current => 1)
|| $self->application->default;
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>");
return 0;
}
}
else {
$self->application->add_message('warning', 'Login or Password incorrect. Please try again.');
return 0;
}

if ($user->active and ($user->has_right($self->application, 'login') || $Conf::open_gates)) {

$self->application->session->user($user);
print $self->application->cgi->redirect(-uri => $Conf::cgi_url."?page=".$to, -cookie => $self->application->session->cookie );
} else {
print $self->application->cgi->redirect(-uri => $Conf::cgi_url."?page=".$to."&loginfail=access");
return 0;
}
} else {
print $self->application->cgi->redirect(-uri => $Conf::cgi_url."?page=".$to."&loginfail=password");
return 0;
}

return 1;
}
Expand Down