[Mojolicious] Re: Event driven based on syslog messages
Well thanks for taking the time to reply, I'll have a look into it. You wrote a long time ago, I was totally absorbed in a project. Best regards, Luc On Thursday, 30 May 2019 14:33:13 UTC-4, Heiko Jansen wrote: > > Sorry, completely missed your follow-up... > > I'd say the synopsis of Mojo::IOLoop mostly shows what to do. Never tried > it myself, but something along these lines should work: > > use Mojo::IOLoop; > > > my $id = Mojo::IOLoop->client({ path => '/tmp/myapp.sock' } => sub { > my ($loop, $err, $stream) = @_; > > $stream->on(read => sub { > my ($stream, $bytes) = @_; > > # Process input > say "Input: $bytes"; > }); > }); > > # Start event loop if necessary > Mojo::IOLoop->start unless Mojo::IOLoop->is_running; > > There may be other ways to achieve what you want, but this seems the > easiest solution to me. > Of course there's no guarantee that your "read" callback is called exactly > once for one complete new syslog entry. You may receive only parts of one > log entry or a whole bunch of log entries at once and you have to parse and > split them yourself, sometimes waiting for the rest of an entry to bee > provided in the next call of your callback... > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/0fbd986d-f88b-4e9e-80f7-893bd2261833%40googlegroups.com.
Re: [Mojolicious] How to send a job in the backend and refresh status in web app ?
I need to restart this debate :) I've been looking into this and found the Multiplex plugin for Mojolicious by Joel Berger. Seems interesting too, but I still need to understand the mechanics of websockets and non-blocking IO and minion jobs ... That's a lot So I thought of something else ... What if my webage would automatically refresh every X seconds and after sending a job in the background, the BD would be updated with the job results so that when the api endpoint is read by the client, the data is refreshed ? I feel lazy proposing it, but the other way around sounds like a nightmare (I'm not a developper) What do you think ? -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/ccf48950-ea7c-4d1a-9da6-1182ed25649c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] How to send a job in the backend and refresh status in web app ?
I'm using Mojo::SQLite to address BD needs. The Mercury websocket broker seems an accurate choice, though. On Thursday, 9 May 2019 17:21:35 UTC-4, Dan Book wrote: > > Pubsub over a db like Pg or Redis might be useful if you are using one of > those. Otherwise the Mercury websocket broker can also act as a pubsub > daemon. > > -Dan > > On Thu, May 9, 2019 at 4:17 PM Luc Larochelle > wrote: > >> Hi, >> >> I've researched this subject and read a lot, but can't come to a >> conclusion. I need help to get things straight ... >> >> In my web app, I simply manage elements in a DB with API endpoints. So >> far, this is awesome. My setup is Mojolicious + AngularJS + Bootstrap. >> >> The way I see this, my question has 2 approaches : >> >> 1) When I add a new element in the table, I'd like to deploy a job, where >> a backend scripts connects to the element and reports a status to the web >> app. >> >> 2) Some daemon is periodically watching an "inventory" API endpoint and >> when a new element is detected, the backend script connects to the element >> and reports a status to the web app. >> >> >> For instance, it could set a status light for connectivity and >> authentication success on each line of my table. >> >> >> In any ways, I thought websockets + minions would be my friends, but the >> more I read about it, the more I get confused. Are Minions suited for this >> task ? >> >> How should I achieve this ? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Mojolicious" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to mojol...@googlegroups.com . >> To post to this group, send email to mojol...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/mojolicious. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/mojolicious/ccfe44d6-38b8-405d-92f6-189f4c377b3a%40googlegroups.com >> >> <https://groups.google.com/d/msgid/mojolicious/ccfe44d6-38b8-405d-92f6-189f4c377b3a%40googlegroups.com?utm_medium=email_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/d5fd277d-ff02-4d22-98d6-6b3f4e96a262%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: How to send a job in the backend and refresh status in web app ?
It was implied that the status update would/could be async. Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/5f3ddf98-7dfa-466e-a007-357985439476%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] How to send a job in the backend and refresh status in web app ?
Hi, I've researched this subject and read a lot, but can't come to a conclusion. I need help to get things straight ... In my web app, I simply manage elements in a DB with API endpoints. So far, this is awesome. My setup is Mojolicious + AngularJS + Bootstrap. The way I see this, my question has 2 approaches : 1) When I add a new element in the table, I'd like to deploy a job, where a backend scripts connects to the element and reports a status to the web app. 2) Some daemon is periodically watching an "inventory" API endpoint and when a new element is detected, the backend script connects to the element and reports a status to the web app. For instance, it could set a status light for connectivity and authentication success on each line of my table. In any ways, I thought websockets + minions would be my friends, but the more I read about it, the more I get confused. Are Minions suited for this task ? How should I achieve this ? -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/ccfe44d6-38b8-405d-92f6-189f4c377b3a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Error handling with Mojo::SQLite
Fantastic. Thank you again On Thursday, 9 May 2019 10:11:40 UTC-4, Dan Book wrote: > > It is so the eval returns true if it succeeds. If an exception is thrown, > eval always returns undef. Thus by this difference you can determine > without fail whether an exception occurred. > > -Dan > > On Thu, May 9, 2019 at 9:49 AM Luc Larochelle > wrote: > >> Hi Dan, >> >> What does the " 1 " stands for in the line : if (eval { ...; *1* }) { ? >> >> I've never used that kind of notation before. I think it could be some >> sort of default *true ?* >> >> >> >> On Wednesday, 8 May 2019 14:10:51 UTC-4, Dan Book wrote: >>> >>> Testing $@ is not the best way to determine an exception occurred. I'd >>> recommend Syntax::Keyword::Try as it handles all the edge cases for you, >>> but otherwise this gets you most of the way: >>> >>> if (eval { ...; 1 }) { >>> # success >>> } else { >>> my $err = $@; >>> } >>> >>> And make sure you log errors and rethrow any exceptions you do not >>> handle. You will want to see the error logging later. >>> >>> -Dan >>> >>> On Wed, May 8, 2019 at 1:18 PM Luc Larochelle >>> wrote: >>> >>>> This works just as expected. In my case I wanted to catch foreign key >>>> constraints. Now I'm prepared for the critics, I'll post my "del" route, >>>> it's from an Lite application serving a web app. I wonder if I'm doing >>>> things the right way. >>>> >>>> I tried to make it idempotent for GET, POST, PUT & DEL but since I have >>>> to deal with little exceptions in the given routes, they all have their >>>> definitions. For instance, :id is *id in the GET route, since its >>>> principal >>>> task is to display the whole table. The helpers though (model ?) are not >>>> dealing with exceptions at all and are used to execute simple tasks to the >>>> db given the params feeded by the routes. >>>> >>>> I'm very opened to discuss all of this, this has to be my most serious >>>> project since I started using Mojolicious and I'm learning frontend coding >>>> on-the-fly ... >>>> >>>> helper insertOne => sub { >>>> my ($c,$table) = @_; >>>> $c->sqlite->db->insert($table, $c->element); >>>> }; >>>> >>>> >>>> helper deleteOne => sub { >>>> >>>> my ($c,$table,$param) = @_; >>>> $c->sqlite->db->delete($table, {$tables->{$table} => $param}); >>>> }; >>>> >>>> >>>> >>>> del '/api/select/:table/:id' => sub { >>>> >>>> my $c = shift; >>>> if ($c->selectOne($c->param('id'))) { >>>> eval { $c->deleteOne($c->param('table'),$c->param('id')) }; >>>> unless($@) { >>>> $c->render(status => 200, json => {message => $c->param('id') . >>>> $messages->{'Del'}}); >>>> } elsif ($@ =~ /FOREIGN KEY constraint failed/) { >>>> $c->render(status => 400, json => {message => $c->param('id') . >>>> $messages->{'FK'}}); >>>> } >>>> } else { >>>> $c->render(status => 404, json => {message => "Not found"}); >>>> } >>>> >>>> }; >>>> >>>> >>>> >>>> On Wednesday, 20 March 2019 11:58:04 UTC-4, Luc Larochelle wrote: >>>>> >>>>> Thanks ! Maybe I read only the sections and bold titles :) >>>>> >>>>> I'll have a second look. >>>>> >>>>> >>>>> On Monday, 18 March 2019 12:35:48 UTC-4, Dan Book wrote: >>>>>> >>>>>> As mentioned in the documentation: "Any database errors will throw >>>>>> an exception as RaiseError is automatically enabled, so use eval or >>>>>> Try::Tiny <https://metacpan.org/pod/Try::Tiny> to catch them. " >>>>>> >>>>>> This is the standard way to handle errors in Perl. >>>>>> Syntax::Keyword::Try is also a nicer interface if you can use keyword >>>>>> plugins (perl 5.14+). >>>>>> >>>>>> -Dan >>>>>> >>>>>> On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle >>>
Re: [Mojolicious] Error handling with Mojo::SQLite
Hi Dan, What does the " 1 " stands for in the line : if (eval { ...; *1* }) { ? I've never used that kind of notation before. I think it could be some sort of default *true ?* On Wednesday, 8 May 2019 14:10:51 UTC-4, Dan Book wrote: > > Testing $@ is not the best way to determine an exception occurred. I'd > recommend Syntax::Keyword::Try as it handles all the edge cases for you, > but otherwise this gets you most of the way: > > if (eval { ...; 1 }) { > # success > } else { > my $err = $@; > } > > And make sure you log errors and rethrow any exceptions you do not handle. > You will want to see the error logging later. > > -Dan > > On Wed, May 8, 2019 at 1:18 PM Luc Larochelle > wrote: > >> This works just as expected. In my case I wanted to catch foreign key >> constraints. Now I'm prepared for the critics, I'll post my "del" route, >> it's from an Lite application serving a web app. I wonder if I'm doing >> things the right way. >> >> I tried to make it idempotent for GET, POST, PUT & DEL but since I have >> to deal with little exceptions in the given routes, they all have their >> definitions. For instance, :id is *id in the GET route, since its principal >> task is to display the whole table. The helpers though (model ?) are not >> dealing with exceptions at all and are used to execute simple tasks to the >> db given the params feeded by the routes. >> >> I'm very opened to discuss all of this, this has to be my most serious >> project since I started using Mojolicious and I'm learning frontend coding >> on-the-fly ... >> >> helper insertOne => sub { >> my ($c,$table) = @_; >> $c->sqlite->db->insert($table, $c->element); >> }; >> >> >> helper deleteOne => sub { >> >> my ($c,$table,$param) = @_; >> $c->sqlite->db->delete($table, {$tables->{$table} => $param}); >> }; >> >> >> >> del '/api/select/:table/:id' => sub { >> >> my $c = shift; >> if ($c->selectOne($c->param('id'))) { >> eval { $c->deleteOne($c->param('table'),$c->param('id')) }; >> unless($@) { >> $c->render(status => 200, json => {message => $c->param('id') . >> $messages->{'Del'}}); >> } elsif ($@ =~ /FOREIGN KEY constraint failed/) { >> $c->render(status => 400, json => {message => $c->param('id') . >> $messages->{'FK'}}); >> } >> } else { >> $c->render(status => 404, json => {message => "Not found"}); >> } >> >> }; >> >> >> >> On Wednesday, 20 March 2019 11:58:04 UTC-4, Luc Larochelle wrote: >>> >>> Thanks ! Maybe I read only the sections and bold titles :) >>> >>> I'll have a second look. >>> >>> >>> On Monday, 18 March 2019 12:35:48 UTC-4, Dan Book wrote: >>>> >>>> As mentioned in the documentation: "Any database errors will throw an >>>> exception as RaiseError is automatically enabled, so use eval or >>>> Try::Tiny <https://metacpan.org/pod/Try::Tiny> to catch them. " >>>> >>>> This is the standard way to handle errors in Perl. Syntax::Keyword::Try >>>> is also a nicer interface if you can use keyword plugins (perl 5.14+). >>>> >>>> -Dan >>>> >>>> On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle >>>> wrote: >>>> >>>>> Hello Veesh, well to me that looks like "eval" , right ? I meant is >>>>> there a way with Mojo::SQLite to check errors ? >>>>> >>>>> On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote: >>>>>> >>>>>> Does Try::Tiny strike your fancy? It'll put the error into $_ in the >>>>>> catch block. >>>>>> >>>>>> Short of that, I'm fairly certain it'll crash your thread if it fails. >>>>>> >>>>>> On Fri, Mar 15, 2019, 10:22 PM Luc Larochelle >>>>>> wrote: >>>>>> >>>>>>> Hello everyone, >>>>>>> >>>>>>> While a 'select' statement can be double checked by the presence of >>>>>>> the returned data, how can I confirm that statements such as 'insert' , >>>>>>> 'update' or 'delete' are successful ? >>>>>>> >>>>>>> For instance, using SQL::Abstract and some helpers >>>>>>> &g
Re: [Mojolicious] Error handling with Mojo::SQLite
This works just as expected. In my case I wanted to catch foreign key constraints. Now I'm prepared for the critics, I'll post my "del" route, it's from an Lite application serving a web app. I wonder if I'm doing things the right way. I tried to make it idempotent for GET, POST, PUT & DEL but since I have to deal with little exceptions in the given routes, they all have their definitions. For instance, :id is *id in the GET route, since its principal task is to display the whole table. The helpers though (model ?) are not dealing with exceptions at all and are used to execute simple tasks to the db given the params feeded by the routes. I'm very opened to discuss all of this, this has to be my most serious project since I started using Mojolicious and I'm learning frontend coding on-the-fly ... helper insertOne => sub { my ($c,$table) = @_; $c->sqlite->db->insert($table, $c->element); }; helper deleteOne => sub { my ($c,$table,$param) = @_; $c->sqlite->db->delete($table, {$tables->{$table} => $param}); }; del '/api/select/:table/:id' => sub { my $c = shift; if ($c->selectOne($c->param('id'))) { eval { $c->deleteOne($c->param('table'),$c->param('id')) }; unless($@) { $c->render(status => 200, json => {message => $c->param('id') . $messages->{'Del'}}); } elsif ($@ =~ /FOREIGN KEY constraint failed/) { $c->render(status => 400, json => {message => $c->param('id') . $messages->{'FK'}}); } } else { $c->render(status => 404, json => {message => "Not found"}); } }; On Wednesday, 20 March 2019 11:58:04 UTC-4, Luc Larochelle wrote: > > Thanks ! Maybe I read only the sections and bold titles :) > > I'll have a second look. > > > On Monday, 18 March 2019 12:35:48 UTC-4, Dan Book wrote: >> >> As mentioned in the documentation: "Any database errors will throw an >> exception as RaiseError is automatically enabled, so use eval or >> Try::Tiny <https://metacpan.org/pod/Try::Tiny> to catch them. " >> >> This is the standard way to handle errors in Perl. Syntax::Keyword::Try >> is also a nicer interface if you can use keyword plugins (perl 5.14+). >> >> -Dan >> >> On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle >> wrote: >> >>> Hello Veesh, well to me that looks like "eval" , right ? I meant is >>> there a way with Mojo::SQLite to check errors ? >>> >>> On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote: >>>> >>>> Does Try::Tiny strike your fancy? It'll put the error into $_ in the >>>> catch block. >>>> >>>> Short of that, I'm fairly certain it'll crash your thread if it fails. >>>> >>>> On Fri, Mar 15, 2019, 10:22 PM Luc Larochelle >>>> wrote: >>>> >>>>> Hello everyone, >>>>> >>>>> While a 'select' statement can be double checked by the presence of >>>>> the returned data, how can I confirm that statements such as 'insert' , >>>>> 'update' or 'delete' are successful ? >>>>> >>>>> For instance, using SQL::Abstract and some helpers >>>>> >>>>> helper insertOne => sub { >>>>> my ($c,$table) = @_; >>>>> $c->sqlite->db->insert($table, $c->element); >>>>> }; >>>>> >>>>> >>>>> >>>>> I've seen in the documentation that one could *eval* and look into $@ >>>>> , but is there a more "inline" way to do this ? >>>>> >>>>> Cheers ! >>>>> >>>>> Luc >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Mojolicious" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to mojolicious...@googlegroups.com. >>>>> To post to this group, send email to mojol...@googlegroups.com. >>>>> Visit this group at https://groups.google.com/group/mojolicious. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Mojolicious" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to mojolicious...@googlegroups.com. >>> To post to this group, send email to mojol...@googlegroups.com. >>> Visit this group at https://groups.google.com/group/mojolicious. >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/e3480fbb-d830-461f-b644-33f3de62db18%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Mojo::SQLite && foreign keys support ?
Hello Dan, thank you so much. Now I guess I'll have to deal with error management but you already showed me the way in that other post :) https://groups.google.com/forum/#!topic/mojolicious/Tfv8RK2UkrI Cheers ! On Wednesday, 8 May 2019 10:55:14 UTC-4, Dan Book wrote: > > This is the correct way to set the pragma for each connection. However > your helper is not set up right. You are creating a new Mojo::SQLite object > each time it is called and so the on-connection handler is no longer > applied. You need to declare 'my $sqlite;' outside and only set it in the > helper if it's not defined yet. > > my $sqlite; > helper sqlite => sub { $sqlite //= Mojo::SQLite->new... }; > > Alternatively you can use 'state $sqlite = ' inside the helper but this > approach breaks the ability to run multiple separate apps in the same > process, because it will make one $sqlite per whole process. > > -Dan > > On Wed, May 8, 2019 at 10:47 AM Luc Larochelle > wrote: > >> Hello everyone, >> >> I've been struggling with this one for a while, so I decided to post here. >> >> I built a crud web application to manage hosts configuration for a >> backend backup application. >> >> There is a parent table (Devices) , which relates to child tables by name >> (authName , promptName ...). I defined foreign keys constraint where delete >> of a child is restricted (if the child is used in the parent table). >> >> Problem is, foreign keys do not seem to be effective from the web app. If >> I open a connection to the db from the cli and enable PRAGMA foreign_keys = >> ON; before attempting a delete, I received the appropriate response >> >> sqlite> delete from Auths where authName = "myAuth"; >> Error: foreign key constraint failed >> >> Even if it's being defined in my schema, it's not working. >> >> So I searched the forums for an answer. One good solution was to have the >> PRAGMA defined in ~/.sqliterc, but this is working only for the user. >> >> Finally someone said it had to be applied at each connection, so I added >> the call " on connection " to send the command every time, still no luck. >> >> Below is the relevant piece of code for discussion, can someone please >> point out what's wrong with my approach ? >> >> >> >> >> helper sqlite => sub {my $sql = Mojo::SQLite->new('sqlite:mynewdb2.db')}; >> >> >> app->sqlite->on(connection => sub { >> my ($sql, $dbh) = @_; >> $dbh->do('PRAGMA foreign_keys = ON'); >> }); >> >> >> >> app->sqlite->auto_migrate(1)->migrations->name('ConfigMgt')->from_string(<> -- 1 up >> PRAGMA foreign_keys = ON; >> >> create table if not exists Devices >> ( >> hostname text , >> ipaddress text , >> groupName text , >> authName text , >> connectionName text , >> promptName text , >> ignoreStatus int default 0, >> dateAdd datetime , >> dateMod datetime , >> primary key (hostname, ipaddress), >> constraint deviceAuth foreign key (authName)references Auths(authName) >> on delete restrict on update no action , >> constraint deviceScript foreign key (groupName)references >> Scripts(scriptName) on delete restrict on update no action , >> constraint devicePrompt foreign key (promptName)references >> Prompts(promptName) on delete restrict on update no action , >> constraint deviceConnection foreign key (connectionName)references >> Connections(connectionName) on delete restrict on update no action >> ); >> >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Mojolicious" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to mojol...@googlegroups.com . >> To post to this group, send email to mojol...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/mojolicious. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/mojolicious/f8d536f2-4ea7-4447-9b8e-04cc639bb287%40googlegroups.com >> >> <https://groups.google.com/d/msgid/mojolicious/f8d536f2-4ea7-4447-9b8e-04cc639bb287%40googlegroups.com?utm_medium=email_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/4255e2b4-1e39-4242-8bb7-0e7836ccc8d6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Is there any way to send back result via websocket without waiting all done
I'm thinking about building the same type of system. To be very honest, I thought about websockets but wouldn't know where to start. In a homemade config backup system, I decided to migrate the configuration file to a nice CRUD frontend built with Mojolicious + AngularJS + Bootstrap. As a nice-to-have feature, I thought that each time a user adds a new element to the configuration (e.g.: a new host to backup) , it could deploy a backend job to test a simple command such as "show version" on the node and that the result could be sent to a websocket so that a status light indicator could be displayed on the node's line. (in a table). Anyways, I'm very interested in that project, please share your success ! Cheers, Luc On Friday, 18 January 2019 00:30:07 UTC-5, Peter L wrote: > > Hi, > > I have a network equipment which is similar to the Cisco L3 switch. I use > mojo to setup a web server on a Linux PC. The browser can send some CLI > commands via websocket to web server. The web server can run these commands > on network equipment and send all the results back to the browser via > websocket. It works. But, It need to take some time to wait for all results > done. In this case, if I have many CLI commands, it will take a long time > to wait all results done. I want to send the result back to the browser if > one command is executed without waiting for the other commands executing. > Is there any way to do it via websocket? > > > > websocket "/runcmd" => sub { > > $c->shift; > > ... > > $c->on(message => sub { > my ($c, @commands) = @_; > > foreach ( @commands) { > > # back-end to run commands via ssh/telnet session > my $ret = backend( $_); > > $c->send( encode_json { result => $ret}); > } > > }); > > ... > } > > Thanks, > Peter > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/ee3ce022-bd32-48e7-8419-44803c5a08cb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Event driven based on syslog messages
Hello Heiko, this seems absolutely right after reading a bit about it. Since I've never used Unix sockets nor Mojo::IOLoop, I'd like to double check my comprehension with you :) So rsyslogd sends output to a Unix Socket (in occurence, a file ?) and Mojo::IOLoop::Client reads its content in real time ? Or is this some sort of queue ? IOLoop::Client would be used as an extension to feed some core function in IOLoop ? If you could explain the interactions that would be give me an edge ... and help kickstart my lab :) In the meanwhile I'll keep reading. Cheers, Luc On Friday, 26 April 2019 09:09:13 UTC-4, Heiko Jansen wrote: > > Bit late to the party, but anyhow > If you tell rsyslogd to send output to a socket (using omuxsock), you can > then use Mojo::IOLoop::Client to connect() to a socket via the "path" > argument. > Afterwards you can make use of the IOLoop to process events for reading > from the socket. > That's what you want? > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Event driven based on syslog messages
Hi there, I'm not so sure this is the right forum to discuss these matters, but I'm curious and I know there are some fine folks around here who might have various interests so here we go :) I'd like to build an event driven API based engine to work with, but not exclusively, syslog messages as actuators. That would be a first experience with Mojo::IOLoop for me, but it seems appropriate for this project. The part I'm wondering about is how to capture relevant syslog messages. I have rsyslogd on the server already listening and configured with filters for message forwarding. Would that be the correct way to achieve this ? Messages should be forwarded to a socket that could parse them (Sys::Syslog or such?) and act upon ? Or are there modules in the framework I could use for that purpose ? I need guidance on this, any relevant comment would be highly appreciated. Cheers, Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Legacy ? CRUD on an XML file within a webpage
Hi Stefan, it's similar but I don't even have to create views or join. The given XML is called by a backend script already equipped with functions to deal with the XML data. Actually it is really straight forward :) So in short, the development can become complicated ? On Friday, 22 March 2019 11:42:56 UTC-4, Stefan Adams wrote: > > > > On Fri, Mar 22, 2019 at 10:16 AM Luc Larochelle > wrote: > >> I've been thinking a lot about this lately. In a very simple and light >> application, the database is an XML file , around 1000 entries and very low >> IO. >> >> I haven't been orienting my work on XML, but I was wondering if it would >> be easier to CRUD on the XML directly instead of creating a web app + >> migrate the data to a db, etc ... >> > > It sounds like the problem that I have is similar to yours. I'm dealing > with a SOAP-based web API that delivers 500 records at a time. I'm trying > hard -- probably too hard, but I'm stubborn -- to avoid converting the XML > results into a database. The schema necessary to map this web service is > 300 pages long, so no thanks. Like you, I'm dealing with low IO and prefer > to handle my processing in-memory with Perl rather than crafting SQL > queries. So, as I indicated in the thread you linked, I deserialize the > SOAP response into a complex Perl data structure and then I further shove > that into a Mojo::Collection so I can very easily chain methods for grep, > sort, map, each, etc. I can also modify the data and then send it back to > the web service via SOAP. > > I'm getting very close to releasing Mojo::Autotask > <https://github.com/Keystone-Technologies/mojo-autotask/blob/development/lib/Mojo/Autotask.pm> > to > CPAN, but there's the development branch to review if you like. This also > uses Mojo::Redis for memoizing results. The included > Mojo::Collection::Role::Autotask expand method is the equivalent of an SQL > 'join'. > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Legacy ? CRUD on an XML file within a webpage
well after posting I found this where Dan Book talks about it a little bit : https://groups.google.com/forum/#!topic/mojolicious/sRAk6YhrvK0 On Friday, 22 March 2019 11:16:52 UTC-4, Luc Larochelle wrote: > > Hello everyone, > > I've been thinking a lot about this lately. In a very simple and light > application, the database is an XML file , around 1000 entries and very low > IO. > > I haven't been orienting my work on XML, but I was wondering if it would > be easier to CRUD on the XML directly instead of creating a web app + > migrate the data to a db, etc ... > > I wouldn't know where to start though, any hints ? > > Cheers ! > > Luc > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Legacy ? CRUD on an XML file within a webpage
Hello everyone, I've been thinking a lot about this lately. In a very simple and light application, the database is an XML file , around 1000 entries and very low IO. I haven't been orienting my work on XML, but I was wondering if it would be easier to CRUD on the XML directly instead of creating a web app + migrate the data to a db, etc ... I wouldn't know where to start though, any hints ? Cheers ! Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Error handling with Mojo::SQLite
Thanks ! Maybe I read only the sections and bold titles :) I'll have a second look. On Monday, 18 March 2019 12:35:48 UTC-4, Dan Book wrote: > > As mentioned in the documentation: "Any database errors will throw an > exception as RaiseError is automatically enabled, so use eval or Try::Tiny > <https://metacpan.org/pod/Try::Tiny> to catch them. " > > This is the standard way to handle errors in Perl. Syntax::Keyword::Try is > also a nicer interface if you can use keyword plugins (perl 5.14+). > > -Dan > > On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle > wrote: > >> Hello Veesh, well to me that looks like "eval" , right ? I meant is there >> a way with Mojo::SQLite to check errors ? >> >> On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote: >>> >>> Does Try::Tiny strike your fancy? It'll put the error into $_ in the >>> catch block. >>> >>> Short of that, I'm fairly certain it'll crash your thread if it fails. >>> >>> On Fri, Mar 15, 2019, 10:22 PM Luc Larochelle >>> wrote: >>> >>>> Hello everyone, >>>> >>>> While a 'select' statement can be double checked by the presence of the >>>> returned data, how can I confirm that statements such as 'insert' , >>>> 'update' or 'delete' are successful ? >>>> >>>> For instance, using SQL::Abstract and some helpers >>>> >>>> helper insertOne => sub { >>>> my ($c,$table) = @_; >>>> $c->sqlite->db->insert($table, $c->element); >>>> }; >>>> >>>> >>>> >>>> I've seen in the documentation that one could *eval* and look into $@ >>>> , but is there a more "inline" way to do this ? >>>> >>>> Cheers ! >>>> >>>> Luc >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Mojolicious" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to mojolicious...@googlegroups.com. >>>> To post to this group, send email to mojol...@googlegroups.com. >>>> Visit this group at https://groups.google.com/group/mojolicious. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Mojolicious" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to mojolicious...@googlegroups.com . >> To post to this group, send email to mojol...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/mojolicious. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Error handling with Mojo::SQLite
Hello Veesh, well to me that looks like "eval" , right ? I meant is there a way with Mojo::SQLite to check errors ? On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote: > > Does Try::Tiny strike your fancy? It'll put the error into $_ in the catch > block. > > Short of that, I'm fairly certain it'll crash your thread if it fails. > > On Fri, Mar 15, 2019, 10:22 PM Luc Larochelle > wrote: > >> Hello everyone, >> >> While a 'select' statement can be double checked by the presence of the >> returned data, how can I confirm that statements such as 'insert' , >> 'update' or 'delete' are successful ? >> >> For instance, using SQL::Abstract and some helpers >> >> helper insertOne => sub { >> my ($c,$table) = @_; >> $c->sqlite->db->insert($table, $c->element); >> }; >> >> >> >> I've seen in the documentation that one could *eval* and look into $@ , >> but is there a more "inline" way to do this ? >> >> Cheers ! >> >> Luc >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Mojolicious" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to mojolicious...@googlegroups.com . >> To post to this group, send email to mojol...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/mojolicious. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Error handling with Mojo::SQLite
Hello everyone, While a 'select' statement can be double checked by the presence of the returned data, how can I confirm that statements such as 'insert' , 'update' or 'delete' are successful ? For instance, using SQL::Abstract and some helpers helper insertOne => sub { my ($c,$table) = @_; $c->sqlite->db->insert($table, $c->element); }; I've seen in the documentation that one could *eval* and look into $@ , but is there a more "inline" way to do this ? Cheers ! Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Executing tasks in the backend ?
Thanks for replying. So it's the never ending story of permissions, facl, groups, security concepts ... I prefer coding ! I'm using group permissions to have the WebApp user execute a program from another user. So far so good, but not perfect. I even tried to play with the visudo config, but this got complicated ... Luc On Wednesday, 7 November 2018 22:20:02 UTC-5, Stefan Adams wrote: > > > > On Wed, Nov 7, 2018 at 1:18 PM Luc Larochelle > wrote: > >> Hi Everyone, >> >> Given that application X is owned by it's generic user (userX) and that a >> Webapp is owned by another generic user(Y), what's the best way to share >> permissions between the users so that application X can be called by a a >> request to the WebApp ? >> > > Is the primary question about the best way to handle permissions between > two users? IMO, either put both users in the same group, or use extended > ACLs <https://wiki.archlinux.org/index.php/Access_Control_Lists>. I used > to use them quite a bit when I managed file servers with Samba and it was > great! > > >> Also, is it a good thing to separate applications from the Webapp in >> distinct users , or should it all be part of a whole ? >> > > I think the general rule of thumb is separations are good, but of course > you need something in place to allow exchange of information. ACLs work. > Other things could work, too. But ACLs proly easiest. Best answer proly > depends on a lot... > > The objective to what you're asking, of course, is if one of your systems > gets hacked, the other shouldn't be affected. If the system A gets hacked > with user A, system B with user B will be "protected". Is system A and > system B both use user C, a breach of system A *or* system B would effect > the other. > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Executing tasks in the backend ?
Hi Everyone, Given that application X is owned by it's generic user (userX) and that a Webapp is owned by another generic user(Y), what's the best way to share permissions between the users so that application X can be called by a a request to the WebApp ? Also, is it a good thing to separate applications from the Webapp in distinct users , or should it all be part of a whole ? Your advice and comments will be very appreciated. Cheers, Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Mojo and Angular
Hi Duncan, I just finished my first AngularJS web app with Mojolicious as the backend. The result is impressive, slick and highly responsive. I had looked into the openAPI plugin before, but wouldn't really understand what it is and how to use it before doing my dev. In fact, I implemented json schema validation in another project (purely backend interaction) and I think it has to be the way to go (openAPI). Lesson learned, though : I've been rendering the app with the get ' / ' route, I think I might look into an alternative to serve the front end in a completely different environment than the backend. But still very happy with the result. Hope this helps. Luc On Saturday, 28 July 2018 07:00:10 UTC-4, Duncan Ferguson wrote: > > Hi, > > I am considering diving into writing my own webapp but I am still trying > to work out how I might want to do it - this is more of a project so I can > learn new technologies rather than for any other reason. > > I have used Mojo before for a few small projects and I am currently > wondering if I can use Mojo as the backend and Angular as the frontend in > my new one, but before I go this route I am looking to see how many other > people have done this previously (rather than using node.js, which I have > never looked at before). I'd prefer to try and not take on too much to > learn in one go, hence using Mojo, which at least I have a vague idea about > :) > > I have seen there are a couple of Angular modules on metacpan, but they > all appear to be 3+ years ago - are they still useful if I do end up going > this route? > > Thanks > > Duncs > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Access to stash from hooks ? (before_routes)
hey Brad nice to hear from you again ! I think I'll have a look @ under , but in the meanwhile I realized that the difference between our code ia that I assign the value to the stash inside the if condition. Maybe it is not met after all ? I'll do more testing :) In fact I need to protect access to get / only as it is the only rendered template ( an angularjs app ). The other routes are only used as a the backend and I made sure they can only be called locally.( thanks to Joel Berger's advent calendar). -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Access to stash from hooks ? (before_routes)
Hi, I'm using the excellent " basic auth plus " plugin to authenticate against an LDAP server. It is being called from the hook "before_routes". Question : is it possible to insert a value into the stash from this hook ? I tried with $self->stash(user => $username) but it's not recognized by the template at rendering time from the main route ( get '/ ' ) *Global symbol "$user" requires explicit package name (did you forget to declare "my $user"?) at template index.html.ep from DATA section line 5.* *Template* __DATA__ @@index.html.ep <%= $user %> ... *Sample code is below : * app->hook(before_routes => sub { my $self = shift; my ($hash_ref, $auth_ok) = $self->basic_auth( "LDAP" => { [insert ldap config here] } ); if ($hash_ref->{ldap}) { my $ldap = $hash_ref; my $username = $hash_ref->{username}; $self->stash(user => $username); [ ... ] } return 0 unless $auth_ok; }); -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Render http status code + json ?
thank u so much for the confirmation. Btw I tried to replicate as per your example in the meanwhile and it works perfectly for me. Best, Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Render http status code + json ?
What I mean is, how can I pass both types to the renderer ? $c->render(status => 404, json => {message => 'error'}); Is that the proper way ? On Tuesday, 28 August 2018 09:29:03 UTC-4, Luc Larochelle wrote: > > well that's interesting for sure , but actually I'm using Mojolicious::Lite -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Render http status code + json ?
well that's interesting for sure , but actually I'm using Mojolicious::Lite -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Render http status code + json ?
Hi, what's the proper way to render a status code and a json message at the same time ? I use Mojolicious Lite. Best, Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Mojo::JWT - error handling
Hi Scott, Sorry about this. I reviewed the doc on "eval" and it's working now. eval {my $status = $jwt->decode($token);}; return 0 if $@; return $status; On Wednesday, 23 May 2018 13:23:54 UTC-4, Luc Larochelle wrote: > > Hi Scott, > > I tried this and it would still die. Can you provide a snippet ? I've used > eval only once, based on code example I was working on. > > On Friday, 18 May 2018 16:58:02 UTC-4, Scott Wiersdorf wrote: >> >> Mojo::JWT::decode can die, so you'll want to wrap that in an eval() and >> trap the exception. >> >> Scott >> >> On Friday, May 18, 2018 at 1:57:11 PM UTC-6, Luc Larochelle wrote: >>> >>> I'm using Mojo::JWT to produde a token and verify authorization on >>> routes (using the given token, with the same secret) >>> >>> Thing is , when the token is invalid, an error is being thrown and the >>> application crashes. I'd like to contain the error and deal with it. >>> >>> What am I missing ? Here's the sample code >>> >>> >>> >>> use Mojo::JWT; >>> use Mojolicious::Lite; >>> use Data::Dumper; >>> >>> helper check_token => sub { >>> >>> my $self = shift; >>> my $token = $self->req->headers->authorization; >>> my $jwt = Mojo::JWT->new(secret => 'mytest'); >>> return $jwt->decode($token); >>> >>> }; >>> >>> any '/auth' => sub { >>> my $c = shift; >>> my $claims = $c->check_token; >>> >>> if (!($claims)) { >>> $c->render(json => {status => "error", data => { message >>> => "Please authenticate" }}); >>> } else { >>> $c->render(json => $claims); >>> } >>> >>> }; >>> >> -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Mojo::JWT - error handling
Hi Scott, I tried this and it would still die. Can you provide a snippet ? I've used eval only once, based on code example I was working on. On Friday, 18 May 2018 16:58:02 UTC-4, Scott Wiersdorf wrote: > > Mojo::JWT::decode can die, so you'll want to wrap that in an eval() and > trap the exception. > > Scott > > On Friday, May 18, 2018 at 1:57:11 PM UTC-6, Luc Larochelle wrote: >> >> I'm using Mojo::JWT to produde a token and verify authorization on routes >> (using the given token, with the same secret) >> >> Thing is , when the token is invalid, an error is being thrown and the >> application crashes. I'd like to contain the error and deal with it. >> >> What am I missing ? Here's the sample code >> >> >> >> use Mojo::JWT; >> use Mojolicious::Lite; >> use Data::Dumper; >> >> helper check_token => sub { >> >> my $self = shift; >> my $token = $self->req->headers->authorization; >> my $jwt = Mojo::JWT->new(secret => 'mytest'); >> return $jwt->decode($token); >> >> }; >> >> any '/auth' => sub { >> my $c = shift; >> my $claims = $c->check_token; >> >> if (!($claims)) { >> $c->render(json => {status => "error", data => { message >> => "Please authenticate" }}); >> } else { >> $c->render(json => $claims); >> } >> >> }; >> > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Mojo::JWT - error handling
Sorry here's the error ... [Fri May 18 15:48:37 2018] [debug] POST "/auth" [Fri May 18 15:48:37 2018] [debug] Routing to a callback [Fri May 18 15:48:37 2018] [error] Failed HS validation at /srv/ccdapi/temp/jwt.pl line 18. [Fri May 18 15:48:37 2018] [debug] Template "exception.development.html.ep" not found [Fri May 18 15:48:37 2018] [debug] Template "exception.html.ep" not found [Fri May 18 15:48:37 2018] [debug] Rendering template "mojo/debug.html.ep" [Fri May 18 15:48:37 2018] [debug] Rendering template "mojo/menubar.html.ep" [Fri May 18 15:48:37 2018] [debug] Your secret passphrase needs to be changed [Fri May 18 15:48:37 2018] [debug] 500 Internal Server Error (0.064189s, 15.579/s) On Friday, 18 May 2018 15:57:11 UTC-4, Luc Larochelle wrote: > > I'm using Mojo::JWT to produde a token and verify authorization on routes > (using the given token, with the same secret) > > Thing is , when the token is invalid, an error is being thrown and the > application crashes. I'd like to contain the error and deal with it. > > What am I missing ? Here's the sample code > > > > use Mojo::JWT; > use Mojolicious::Lite; > use Data::Dumper; > > helper check_token => sub { > > my $self = shift; > my $token = $self->req->headers->authorization; > my $jwt = Mojo::JWT->new(secret => 'mytest'); > return $jwt->decode($token); > > }; > > any '/auth' => sub { > my $c = shift; > my $claims = $c->check_token; > > if (!($claims)) { > $c->render(json => {status => "error", data => { message > => "Please authenticate" }}); > } else { > $c->render(json => $claims); > } > > }; > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Mojo::JWT - error handling
I'm using Mojo::JWT to produde a token and verify authorization on routes (using the given token, with the same secret) Thing is , when the token is invalid, an error is being thrown and the application crashes. I'd like to contain the error and deal with it. What am I missing ? Here's the sample code use Mojo::JWT; use Mojolicious::Lite; use Data::Dumper; helper check_token => sub { my $self = shift; my $token = $self->req->headers->authorization; my $jwt = Mojo::JWT->new(secret => 'mytest'); return $jwt->decode($token); }; any '/auth' => sub { my $c = shift; my $claims = $c->check_token; if (!($claims)) { $c->render(json => {status => "error", data => { message => "Please authenticate" }}); } else { $c->render(json => $claims); } }; -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Re: Mojolicious::Lite how to refresh table only
Hi everyone, thanks for taking the time to respond. I'm off for 5 weeks, but I'll look into this and reply to this thread later in May. Thanks for the suggestions / explanations. Best, Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Mojolicious::Lite how to refresh table only
Wow my reply has been deleted ? On Wednesday, 21 March 2018 11:59:45 UTC-4, Dan Book wrote: > > Refreshing the page and refreshing the table are two different things. The > latter you would need to do in javascript, ideally with a framework like > vue or react that can handle the ugly details. If you refresh the page, you > only need to have the route provide the subset of the data instead of the > full set when it receives the search term. > > -Dan > > On Wed, Mar 21, 2018 at 11:43 AM, Luc Larochelle <llaro...@gmail.com > > wrote: > >> Hi everyone, >> >> I built a single page application to display content in a table with >> Mojolicious Lite. This works fine, the first time the data is rendered. >> >> I pass the values through the stash and in my template, I use a for loop >> to go through the structure and display in the web page. >> >> The problem is selecting a subset of the data (a search box for example). >> I don't understand how to pass the values to the stash and refresh the page. >> >> The stash changes with the desired data after a call to a get sub (for >> example get '/search/:expr' ) but it will never render. As if it gets >> rendered twice, since the final result is the whole table being displayed. >> >> What would be the best way to achieve this ? >> >> Please help ... >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Mojolicious" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to mojolicious...@googlegroups.com . >> To post to this group, send email to mojol...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/mojolicious. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Mojolicious::Lite how to refresh table only
Hi Dan, thank you very much for taking the time to help me on this. Here's my related jquery function. This is not enough to achieve what I'm trying to do ? $("#searchForm").on('submit', function (e) { e.preventDefault(); var text = $("#searchBox").val(); $.get('/mysearch/' + text, function () { window.location.reload(); }); }); Here's the route, where " search" is actually a template containing only the table itself (see below) as part of the layout. What am I doing wrong ? :/ get '/mysearch/:expr' => sub { my $c = shift; my $hosts; my @list = grep { $_->{'hostname'} =~ /$c->param('expr')/ } @{$c->devices}; $c->redirect_to('/') unless (@list); foreach (@list) { $hosts->{$_->{hostname}} = $_; } $c->stash->{hosts} = $hosts; return $c->render('search'); }; @@search.html.ep % layout 'mylayout'; Hostname IP Groupe Auth Protocol % my $nodes = stash 'hosts'; % foreach my $host ( sort keys %$nodes ) { % my $class = "hoverDiv"; % $class = "bg-danger" if ($nodes->{$host}->{incomplete}); >{$host}->{hostname} %> data-toggle="modal" data-target="#EditModal" class="ls-modal"><%= $nodes->{$host}->{hostname} %><%= $nodes->{$host}->{ip}%><%= $nodes->{$host}->{groupe}%><%= $nodes->{$host}->{auth}%><%= $nodes->{$host}->{protocol}%> % } Best regards, Luc On Wednesday, 21 March 2018 11:59:45 UTC-4, Dan Book wrote: > > Refreshing the page and refreshing the table are two different things. The > latter you would need to do in javascript, ideally with a framework like > vue or react that can handle the ugly details. If you refresh the page, you > only need to have the route provide the subset of the data instead of the > full set when it receives the search term. > > -Dan > > On Wed, Mar 21, 2018 at 11:43 AM, Luc Larochelle <llaro...@gmail.com > > wrote: > >> Hi everyone, >> >> I built a single page application to display content in a table with >> Mojolicious Lite. This works fine, the first time the data is rendered. >> >> I pass the values through the stash and in my template, I use a for loop >> to go through the structure and display in the web page. >> >> The problem is selecting a subset of the data (a search box for example). >> I don't understand how to pass the values to the stash and refresh the page. >> >> The stash changes with the desired data after a call to a get sub (for >> example get '/search/:expr' ) but it will never render. As if it gets >> rendered twice, since the final result is the whole table being displayed. >> >> What would be the best way to achieve this ? >> >> Please help ... >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Mojolicious" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to mojolicious...@googlegroups.com . >> To post to this group, send email to mojol...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/mojolicious. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Mojolicious::Lite how to refresh table only
Hi everyone, I built a single page application to display content in a table with Mojolicious Lite. This works fine, the first time the data is rendered. I pass the values through the stash and in my template, I use a for loop to go through the structure and display in the web page. The problem is selecting a subset of the data (a search box for example). I don't understand how to pass the values to the stash and refresh the page. The stash changes with the desired data after a call to a get sub (for example get '/search/:expr' ) but it will never render. As if it gets rendered twice, since the final result is the whole table being displayed. What would be the best way to achieve this ? Please help ... -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Content blocks in template
I was wondering if content tags can be used without a template ? For instance, I have a single page app built with Mojolicious::Lite and I would like to call different routes (buttons pressed or link clicked) to refresh the table. My problem is, I'm using the stash to pass the data structure to the template but the table won't refresh ... I use jquery get method to call my main route with optional placeholders to do so. -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Templates : how to pass data to other context
Finally I found out an approach to this problem. Using the jquery api included with bootstrap it gets easy to pass the minimum params and then use $.get or $.post to work with my routes and render. -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Templates : how to pass data to other context
Still working on this, I can get on a route/:id but the object returned in the stash is undef. The modal is part of the same template as the list, though. On Thursday, 1 March 2018 10:38:47 UTC-5, Luc Larochelle wrote: > > I thought about this, maybe if I post/get on click and render a modal > template this could do the trick ... > > I'm not exactly sure how to achieve this, I'll try and see and keep you > posted. If anyone has an idea ... > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Templates : how to pass data to other context
I thought about this, maybe if I post/get on click and render a modal template this could do the trick ... I'm not exactly sure how to achieve this, I'll try and see and keep you posted. If anyone has an idea ... -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Templates : how to pass data to other context
Is there a way, using the templates, to pass data from context to context ? For instance, if I open a modal for CRUD operation where I want to populate the content of a form for edit purpose, can I pass the whole hashref to fill the form ? How would one do this ? I've seen how to use javascript to pass some text, which could be re-used to request the same route again and then use the data to populate the form in the modal, but is there a more elegant way to do this with Mojolicious ? -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Yancy first attempts
Hi everyone, I took the Yancy app example from the Mojolicious Advent calendar and made some minor modifications to use an SQLite backend instead of Postgres. Thing is, the page won't render at all , but there is no error message. >From my understanding of the purpose of this plugin, it should render blank at least ? (no posts, for instance) Any idea what I'm doing wrong ? Below is the full code. Best regards, use Mojolicious::Lite; use Mojo::SQLite; my $sql = Mojo::SQLite->new('sqlite:config.db'); # Use migrations to create a table $sql->migrations->name('my_config_app')->from_string(<migrate; -- 1 up create table hosts (id integer primary key autoincrement,title varchar not null,created datetime default current_timestamp,markdown text not null,html text not null); -- 1 down drop table hosts; EOF $sql->migrations->migrate(0)->migrate; plugin Yancy => { backend => 'sqlite:config.db', collections => { hosts => { required => [ 'title', 'markdown', 'html' ], properties => { id => { type => 'integer', readOnly => 1, }, title => { type => 'string', }, markdown => { type => 'string', format => 'markdown', 'x-html-field' => 'html', }, html => { type => 'string', }, }, }, }, }; get '/' => sub { my ( $c ) = @_; return $c->render( 'index', posts => [ $c->yancy->list( 'hosts', ) ], ); }; app->start; __DATA__ @@ index.html.ep Hello, world! https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css; integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous"> % for my $post ( @{ stash 'posts' } ) { <%== $post->{html} %> % } https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"> https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"> https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"> -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Re: Basic HTTP auth and plugin "Directory"
Hey Brad, how are you ? Did my example help ? -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Re: Basic HTTP auth and plugin "Directory"
Hey Brad, This is not neat, but attached you'll find some code that can do the job in a full Mojolicious app. Should be .pm though. I did use it to login successfully through ldap as discussed. On Monday, 19 February 2018 14:29:09 UTC-5, Brad Robertson wrote: > > On Sun, Feb 18, 2018 at 05:48:08PM -0800, Luc Larochelle wrote: > > Hey Brad this is looking good ! If you need me to share what I've done > with net::ldaps + certificates let me know. > > > > Would be terrific if the session object was returned in some way so the > that the AD entries are accessible. > > > > -- > > You received this message because you are subscribed to the Google > Groups "Mojolicious" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to mojolicious...@googlegroups.com . > > To post to this group, send email to mojol...@googlegroups.com > . > > Visit this group at https://groups.google.com/group/mojolicious. > > For more options, visit https://groups.google.com/d/optout. > > Sure, if you want to share, that would be great, thanks. I'll keep in > mind your request for the LDAP session object to be returned. :-) > > Regards, > > -- > Brad Robertson > <bradrob...@gmail.com > > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout. package Auth; use Mojo::Base 'Mojolicious::Controller'; use Net::LDAPS; use Data::Dumper; my $SSLMODE = 1; my $SSLCAFILE = 'mycert.ca'; my $SSLVERIFYCA = 0; sub connectToLdap($) { my $url = shift; my $ldap; my $verifyca = 'none'; if($SSLMODE) { if($SSLVERIFYCA) {$verifyca = 'require';} eval {$ldap = Net::LDAPS->new($url, verify => $verifyca, cafile => $SSLCAFILE)}; if ($@) { logger(0, $@); } } else { $ldap = Net::LDAP->new($url); } return $ldap; } sub auth_netLDAP { my $self = shift; my $username = $self->param('username'); my $password = $self->param('password'); my $BINDUSER='CN=user,OU=unitDC=my,DC=domain,DC=com'; my $BINDPASS='xxx'; my $LDAPBASE="OU=unit,DC=my,DC=domain,DC=com"; my $LDAPUID = "samaccountname"; my $LDAPSERVERURL="ldaps://dapserver.domain.com"; my $LDAPError = 0; # Need to have $username and $password before calling my $ldap = connectToLdap($LDAPSERVERURL); my $mesg = $ldap->bind($BINDUSER, password => $BINDPASS); return unless $mesg; if ($mesg->code) { say "Error #" . $mesg->code . " binding to LDAP server."; return; } $mesg = $ldap->search(base => $LDAPBASE, filter => "($LDAPUID=$username)"); if ($mesg->code) { say "Error #" . $mesg->code . " searching LDAP server for $username."; $ldap->unbind; return; } my $entry = $mesg->entry(0); $self->session->{givenName} = $entry->get_value("givenName"); $self->session->{displayName} = $entry->get_value("displayName"); if(!defined($entry)) { say "User $username not found in LDAP."; $ldap->unbind; return; } else { my $dn = $entry->dn; my $result = $ldap->bind(dn => $dn, password => $password); } $ldap->unbind; return $self; } sub login { use Net::LDAPS; my $c = shift; my $username = $c->param('username'); my $password = $c->param('password'); if ($c->auth_netLDAP) { $c->session->{username} = $username; print Dumper($c->stash); my $user = { username => $username, password => '', name => $c->session->{givenName}, }; #$c->stash->(givenName => $c->session->{givenName}); print Dumper($user); $c->model->add_user($user); } $c->redirect_to('/'); } sub logout { my $c = shift; $c->session(expires => 1); $c->redirect_to('/'); } 1;
Re: [Mojolicious] Re: Basic HTTP auth and plugin "Directory"
Hey Brad this is looking good ! If you need me to share what I've done with net::ldaps + certificates let me know. Would be terrific if the session object was returned in some way so the that the AD entries are accessible. -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Re: Basic HTTP auth and plugin "Directory"
If your offer is still on the table I think it would make things much easier to handle from a plugin. Let me know if you decide to work on it ? Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Re: Basic HTTP auth and plugin "Directory"
indeed. it works as expected. I just realized you wrote the basic auth plus module :) -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Re: Basic HTTP auth and plugin "Directory"
Hey Brad, this does make a lot of sense. I didn't get the idea of hooks I guess, but now I'll go have a second read. Thank you so much for the explanations and for taking the time. About ldap(s) well I've got a package of my own using Net::ldaps and I can use certificates to bind with the server. It's all good for me but it would make sense that the Mojolicious plugin could use that level of sophistication since its such a great framework. Best, Luc -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Re: Basic HTTP auth and plugin "Directory"
Thank you Ilya. Well I want this to be part of something bigger. So if I can achieve it within a web application it would be cleaner and easier to maintain. I discarded check_auth since it could not do ldaps + certificate. I thought it was an overkill method for my need and wanted to manage the ldap part with my net::ldaps. -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Basic HTTP auth and plugin "Directory"
I realized maybe I didn't express my need : I want users to access the files from the webpage a-la Apache. So the files and directories have to be displayed. On Thursday, 15 February 2018 13:53:37 UTC-5, Luc Larochelle wrote: > > Hi, > > I've been working with the plugin 'Directory' to serve files on a given > path. This works as expected and is pretty straight forward. > > However, I would like to limit access to the ressource with Basic HTTP > Authentication dialog from the web browser. I can render text "OK" if > basic_auth meets the desired criterias but can't seem to control the > behavior of the plugin > > > > I tried creating a auth helper and use it with the under directive as > shown below (among many other experiments, but this code seems the most > logic to me). Still, the plugin would render without asking for > authentication before. > > Can you please help me achieve this ? > > > use Mojolicious::Lite; > plugin 'basic_auth_plus'; > > helper auth => sub { > my $self = shift; > return 1 if > $self->basic_auth( >"Realm Name" => { > username => 'username', > password => 'password' >} > ) > }; > > > under sub { > my $self = shift; > return 1 if $self->auth; > > $self->render(text => 'denied'); > return; > }; > > > get '/' { > >plugin ('Directory', root=>"/my/path")->start; > > } > > > > > > > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Basic HTTP auth and plugin "Directory"
wow I just found this http://blogs.perl.org/users/joel_berger/2013/01/a-quick-static-file-webserver.html I'll give it a try but this looks promising ! -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Basic HTTP auth and plugin "Directory"
Hi, I've been working with the plugin 'Directory' to serve files on a given path. This works as expected and is pretty straight forward. However, I would like to limit access to the ressource with Basic HTTP Authentication dialog from the web browser. I can render text "OK" if basic_auth meets the desired criterias but can't seem to control the behavior of the plugin I tried creating a auth helper and use it with the under directive as shown below (among many other experiments, but this code seems the most logic to me). Still, the plugin would render without asking for authentication before. Can you please help me achieve this ? use Mojolicious::Lite; plugin 'basic_auth_plus'; helper auth => sub { my $self = shift; return 1 if $self->basic_auth( "Realm Name" => { username => 'username', password => 'password' } ) }; under sub { my $self = shift; return 1 if $self->auth; $self->render(text => 'denied'); return; }; get '/' { plugin ('Directory', root=>"/my/path")->start; } -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.