Replace set_join_pass and set_owner_pass with the generic modify_room

master
Daniel Berteaud 10 years ago
parent 944f153d21
commit c9d8730b47
  1. 65
      vroom.pl

@ -570,57 +570,6 @@ helper get_url => sub {
return $url; return $url;
}; };
# Password protect a room
# Takes two args: room name and password
# If password is undef: remove the password
# Password is hashed and salted before being stored
helper set_join_pass => sub {
my $self = shift;
my ($room,$pass) = @_;
return undef unless ( $self->get_room_by_name($room) );
my $sth = eval {
$self->db->prepare('UPDATE `rooms`
SET `join_password`=?
WHERE `name`=?');
};
$pass = ($pass) ? Crypt::SaltedHash->new(algorithm => 'SHA-256')->add($pass)->generate : undef;
$sth->execute($pass,$room);
if ($pass){
$self->app->log->debug($self->session('name') . " has set a password on room $room");
}
else{
$self->app->log->debug($self->session('name') . " has removed password on room $room");
}
return 1;
};
# Set owner password. Not needed to join a room
# but needed to prove you're the owner, and access the configuration menu
helper set_owner_pass => sub {
my $self = shift;
my ($room,$pass) = @_;
return undef unless ( $self->get_room_by_name($room) );
if ($pass){
my $sth = eval {
$self->db->prepare('UPDATE `rooms`
SET `owner_password`=?
WHERE `name`=?');
} || return undef;
my $pass = Crypt::SaltedHash->new(algorithm => 'SHA-256')->add($pass)->generate;
$sth->execute($pass,$room) || return undef;
$self->app->log->debug($self->session('name') . " has set an owner password on room $room");
}
else{
my $sth = eval {
$self->db->prepare('UPDATE `rooms`
SET `owner_password`=?
WHERE `name`=?');
} || return undef;
$sth->execute(undef,$room) || return undef;
$self->app->log->debug($self->session('name') . " has removed the owner password on room $room");
}
};
# Make the room persistent # Make the room persistent
helper set_persistent => sub { helper set_persistent => sub {
my $self = shift; my $self = shift;
@ -1179,7 +1128,7 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
my $self = shift; my $self = shift;
my $action = $self->param('action'); my $action = $self->param('action');
my $prefix = ($self->stash('action') eq 'admin/action') ? 'admin':'room'; my $prefix = ($self->stash('action') eq 'admin/action') ? 'admin':'room';
my $room = $self->param('room') || ""; my $room = $self->param('room') || '';
if ($action eq 'langSwitch'){ if ($action eq 'langSwitch'){
my $new_lang = $self->param('lang') || 'en'; my $new_lang = $self->param('lang') || 'en';
$self->app->log->debug("switching to lang $new_lang"); $self->app->log->debug("switching to lang $new_lang");
@ -1345,27 +1294,31 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
my $pass = $self->param('password'); my $pass = $self->param('password');
my $type = $self->param('type') || 'join'; my $type = $self->param('type') || 'join';
# Empty password is equivalent to no password at all # Empty password is equivalent to no password at all
$pass = undef if ($pass && $pass eq ''); $pass = ($pass && $pass ne '') ?
my $res = undef; Crypt::SaltedHash->new(algorithm => 'SHA-256')->add($pass)->generate : undef;
my $msg = $self->l('ERROR_OCCURRED'); my $msg = $self->l('ERROR_OCCURRED');
my $status = 'error'; my $status = 'error';
# Once again, only the owner can do this # Once again, only the owner can do this
if ($prefix eq 'admin' || $self->session($room)->{role} eq 'owner'){ if ($prefix eq 'admin' || $self->session($room)->{role} eq 'owner'){
if ($type eq 'owner'){ if ($type eq 'owner'){
$data->{owner_password} = $pass;
# Forbid a few common room names to be reserved # Forbid a few common room names to be reserved
if (grep { $room eq $_ } (split /[,;]/, $config->{'rooms.common_names'})){ if (grep { $room eq $_ } (split /[,;]/, $config->{'rooms.common_names'})){
$msg = $self->l('ERROR_COMMON_ROOM_NAME'); $msg = $self->l('ERROR_COMMON_ROOM_NAME');
} }
elsif ($self->set_owner_pass($room,$pass)){ elsif ($self->modify_room($data)){
$msg = ($pass) ? $self->l('ROOM_NOW_RESERVED') : $self->l('ROOM_NO_MORE_RESERVED'); $msg = ($pass) ? $self->l('ROOM_NOW_RESERVED') : $self->l('ROOM_NO_MORE_RESERVED');
$status = 'success'; $status = 'success';
} }
} }
elsif ($type eq 'join' && $self->set_join_pass($room,$pass)){ elsif ($type eq 'join'){
$data->{join_password} = $pass;
if ($self->modify_room($data)){
$msg = ($pass) ? $self->l('PASSWORD_PROTECT_SET') : $self->l('PASSWORD_PROTECT_UNSET'); $msg = ($pass) ? $self->l('PASSWORD_PROTECT_SET') : $self->l('PASSWORD_PROTECT_UNSET');
$status = 'success'; $status = 'success';
} }
} }
}
# Simple participants will get an error # Simple participants will get an error
else{ else{
$msg = $self->l('NOT_ALLOWED'); $msg = $self->l('NOT_ALLOWED');

Loading…
Cancel
Save