From 4a1a6e813c55de08170432caee0c4017c79b74b3 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Mon, 16 Jun 2014 17:37:59 +0200 Subject: [PATCH] Use a helper to create etherpad sessions --- public/vroom.pl | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/public/vroom.pl b/public/vroom.pl index ae0d8cc..9d0cd03 100755 --- a/public/vroom.pl +++ b/public/vroom.pl @@ -625,6 +625,24 @@ helper create_pad => sub { return 1; }; +# Create an etherpad session for a user +helper create_etherpad_session => sub { + my $self = shift; + my ($room) = @_; + return undef unless ($ec); + my $data = $self->get_room($room); + return undef unless ($data && $data->{etherpad_group}); + my $id = $ec->create_author_if_not_exists_for($self->session('name')); + $self->session($room)->{etherpadAuthorId} = $id; + my $etherpadSession = $ec->create_session($data->{etherpad_group}, $id, time + 86400); + $self->session($room)->{etherpadSessionId} = $etherpadSession; + my $etherpadCookieParam = {}; + if ($config->{etherpadBaseDomain} && $config->{etherpadBaseDomain} ne ''){ + $etherpadCookieParam->{domain} = $config->{etherpadBaseDomain}; + } + $self->cookie(sessionID => $etherpadSession, $etherpadCookieParam); +}; + # Route / to the index page any '/' => sub { my $self = shift; @@ -878,15 +896,7 @@ get '/(*room)' => sub { if (!$data->{etherpad_group}){ $self->create_pad($room); } - my $id = $ec->create_author_if_not_exists_for($self->session('name')); - $self->session($room)->{etherpadAuthorId} = $id; - my $etherpadSession = $ec->create_session($data->{etherpad_group}, $id, time + 86400); - $self->session($room)->{etherpadSessionId} = $etherpadSession; - my $etherpadCookieParam = {}; - if ($config->{etherpadBaseDomain} && $config->{etherpadBaseDomain} ne ''){ - $etherpadCookieParam->{domain} = $config->{etherpadBaseDomain}; - } - $self->cookie(sessionID => $etherpadSession, $etherpadCookieParam); + $self->create_etherpad_session($room); } # Short life cookie to negociate a session with the signaling server $self->cookie(vroomsession => encode_base64($self->session('name') . ':' . $data->{name} . ':' . $data->{token}, ''), {expires => time + 60, path => '/'});