Switch email_notification to the new api handler

master
Daniel Berteaud 10 years ago
parent cf83985a3c
commit 2dc0ed116a
  1. 3
      lib/Vroom/Constants.pm
  2. 18
      public/js/vroom.js
  3. 73
      vroom.pl

@ -164,7 +164,8 @@ use constant API_ACTIONS => {
unlock_room => 1, unlock_room => 1,
set_join_password => 1, set_join_password => 1,
set_owner_password => 1, set_owner_password => 1,
set_ask_for_name => 1 set_ask_for_name => 1,
email_notification => 1
}, },
participant => { participant => {
ping => 1, ping => 1,

@ -98,11 +98,16 @@ function addNotifiedEmail(email){
function removeNotifiedEmail(email){ function removeNotifiedEmail(email){
var id = escapeJqSelector(email.replace(/['"]/, '_').replace('\\\'', '\'')); var id = escapeJqSelector(email.replace(/['"]/, '_').replace('\\\'', '\''));
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
action: 'emailNotification', req: JSON.stringify({
type: 'remove', action: 'email_notification',
param: {
set: 'off',
email: email, email: email,
room: roomName room: roomName
}
})
}, },
error: function() { error: function() {
$.notify(locale.ERROR_OCCURRED, 'error'); $.notify(locale.ERROR_OCCURRED, 'error');
@ -2091,11 +2096,16 @@ function initVroom(room) {
$('#newEmailNotificationForm').submit(function(event){ $('#newEmailNotificationForm').submit(function(event){
event.preventDefault(); event.preventDefault();
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
action: 'emailNotification', req: JSON.stringify({
type: 'add', action: 'email_notification',
param: {
set: 'on',
email: $('#newEmailNotification').val(), email: $('#newEmailNotification').val(),
room: roomName room: roomName
}
})
}, },
error: function() { error: function() {
$.notify(locale.ERROR_OCCURRED, 'error'); $.notify(locale.ERROR_OCCURRED, 'error');

@ -115,6 +115,17 @@ helper valid_id => sub {
return 1; return 1;
}; };
# Check email address
# TODO: replace with Email::Valid
helper valid_email => sub {
my $self = shift;
my ($email) = @_;
if ($email !~ m/^\S+@\S+\.\S+$/){
return 0;
}
return 1;
};
########################## ##########################
# Various helpers # # Various helpers #
########################## ##########################
@ -1409,6 +1420,41 @@ any '/api' => sub {
} }
); );
} }
# Add or remove an email address to the list of email notifications
elsif ($req->{action} eq 'email_notification'){
my $email = $req->{param}->{email};
my $set = $req->{param}->{set};
if (!$self->valid_email($email)){
return $self->render(
json => {
msg => $self->l('ERROR_MAIL_INVALID'),
status => 'error'
}
);
}
elsif ($set eq 'on' && $self->add_notification($room->{name},$email)){
return $self->render(
json => {
status => 'success',
msg => sprintf($self->l('s_WILL_BE_NOTIFIED'), $email)
}
);
}
elsif ($set eq 'off' && $self->remove_notification($room->{name},$email)){
return $self->render(
json => {
status => 'success',
msg => sprintf($self->l('s_WONT_BE_NOTIFIED_ANYMORE'), $email)
}
);
}
return $self->render(
json => {
msg => $self->l('ERROR_OCCURRED'),
status => 'error'
}
);
}
elsif ($req->{action} eq 'authenticate'){ elsif ($req->{action} eq 'authenticate'){
my $pass = $req->{param}->{'password'}; my $pass = $req->{param}->{'password'};
# Auth succeed ? lets promote him to owner of the room # Auth succeed ? lets promote him to owner of the room
@ -1635,33 +1681,6 @@ post '/*jsapi' => { jsapi => [qw(jsapi admin/jsapi)] } => sub {
}, },
); );
} }
# Add a new email for notifications when someone joins
elsif ($action eq 'emailNotification'){
my $email = $self->param('email');
my $type = $self->param('type');
my $status = 'error';
my $msg = $self->l('ERROR_OCCURRED');
if ($prefix ne 'admin' && $self->session($room)->{role} ne 'owner'){
$msg = $self->l('NOT_ALLOWED');
}
elsif ($email !~ m/^\S+@\S+\.\S+$/){
$msg = $self->l('ERROR_MAIL_INVALID');
}
elsif ($type eq 'add' && $self->add_notification($room,$email)){
$status = 'success';
$msg = sprintf($self->l('s_WILL_BE_NOTIFIED'), $email);
}
elsif ($type eq 'remove' && $self->remove_notification($room,$email)){
$status = 'success';
$msg = sprintf($self->l('s_WONT_BE_NOTIFIED_ANYMORE'), $email);
}
return $self->render(
json => {
msg => $msg,
status => $status
}
);
}
# New participant joined the room # New participant joined the room
elsif ($action eq 'join'){ elsif ($action eq 'join'){
my $name = $self->param('name') || ''; my $name = $self->param('name') || '';

Loading…
Cancel
Save