From 1eb8b4f9db8a8f7f3f1ef2bacfcc58c475f2386b Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sun, 18 Jan 2015 18:35:51 +0100 Subject: [PATCH] Switch authenticate to the new API handler --- public/js/vroom.js | 9 +++++--- vroom.pl | 67 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/public/js/vroom.js b/public/js/vroom.js index f758468..cff8097 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -1869,10 +1869,13 @@ function initVroom(room) { event.preventDefault(); var pass = $('#authPass').val(); $.ajax({ + url: rootUrl + 'api', data: { - action: 'authenticate', - password: pass, - room: roomName + req: JSON.stringify({ + action: 'authenticate', + password: pass, + room: roomName + }) }, error: function(data) { $.notify(locale.ERROR_OCCURRED, 'error'); diff --git a/vroom.pl b/vroom.pl index 79cb86e..9ec7716 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1370,7 +1370,41 @@ any '/api' => sub { status => 'error' } ); - } + } + elsif ($req->{action} eq 'authenticate'){ + my $pass = $req->{param}->{'password'}; + # Auth succeed ? lets promote him to owner of the room + if ($room->{owner_password} && Crypt::SaltedHash->validate($room->{owner_password}, $pass)){ + $self->session($room, {role => 'owner'}); + $self->associate_key_to_room( + room => $room, + key => $self->session('key'), + role => 'owner' + ); + return $self->render( + json => { + status => 'success', + msg => $self->l('AUTH_SUCCESS') + } + ); + } + # Oner password is set, but auth failed + elsif ($room->{owner_password}){ + return $self->render( + json => { + status => 'success', + msg => $self->l('WRONG_PASSWORD') + } + ); + } + # There's no owner password, so you cannot auth + return $self->render( + json => { + msg => 'NOT_ALLOWED', + status => 'error' + } + ); + } }; # Catch all route: if nothing else match, it's the name of a room @@ -1532,37 +1566,6 @@ post '/*jsapi' => { jsapi => [qw(jsapi admin/jsapi)] } => sub { } ); } - # A participant is trying to auth as an owner, lets check that - elsif ($action eq 'authenticate'){ - my $pass = $self->param('password'); - my $res = undef; - my $msg = $self->l('ERROR_OCCURRED'); - my $status = 'error'; - # Auth succeed ? lets promote him to owner of the room - if ($data->{owner_password} && Crypt::SaltedHash->validate($data->{owner_password}, $pass)){ - $self->session($room, {role => 'owner'}); - $self->associate_key_to_room( - room => $room, - key => $self->session('key'), - role => 'owner' - ); - $msg = $self->l('AUTH_SUCCESS'); - $status = 'success'; - } - elsif ($data->{owner_password}){ - $msg = $self->l('WRONG_PASSWORD'); - } - # There's no owner password, so you cannot auth - else{ - $msg = $self->l('NOT_ALLOWED'); - } - return $self->render( - json => { - msg => $msg, - status => $status - } - ); - } # Return your role and various info about the room elsif ($action eq 'getRoomInfo'){ my $id = $self->param('id');