Browse Source

allin - a small example with most osmo funcs

themage
Marco Neves 7 years ago
parent
commit
82045ad7b7

+ 8 - 0
examples/config/allin.ini

@ -0,0 +1,8 @@
1
[email]
2
email_from = osmo-allin@example.com
3
4
[database]
5
dsn = database=osmo_test
6
username  = root
7
password  = 
8

+ 74 - 0
examples/lib/oSMo/Examples/AllIn.pm

@ -0,0 +1,74 @@
1
package oSMo::Examples::AllIn;
2
3
use oSMo::Base qw(oSMo);
4
5
sub startup {
6
	my $self = shift;
7
8
	$self->log->level('all');
9
10
	$self->activate('config', {file=>'allin.ini'});
11
	$self->activate( qw(auth localize messages menus snippets) );
12
	
13
	$self->plugins->register_plugin('Auth::Email', $self);
14
15
	$self->defaults->{sitename} = 'oSMo AllIn Example';
16
	$self->defaults->{title}		= '';
17
	$self->defaults->{theme}		= 'all_in';
18
19
	# routes for both anonymous and authed users
20
	my $r = $self->auth->common_routes;
21
	$r->route('/')->to('pages#index');
22
	$r->route('/info')->to('pages#info');
23
	$r->route('/sayhi')->to(cb => \&_say_hi );
24
25
	my $ur = $self->auth->authed_routes;
26
	$ur->route('/more')->to('pages#more_authed');
27
28
	my $ar = $self->auth->anonymous_routes;
29
	$ar->route('/more')->to('pages#more_anonym');
30
31
	$self->_init_menus;
32
	$self->_init_snippets;
33
}
34
35
sub _init_menus {
36
	my $self = shift;
37
38
	my $menus = $self->menus;
39
40
	$menus->add_to_menu('top_main',
41
		{ label	=> 'Info', url => '/info' },
42
		{ label	=> 'More Info', url => '/more' },
43
		{ label => 'Say Hi', url => '/sayhi' },
44
	);
45
}
46
47
sub _init_snippets {
48
	my $self = shift;
49
50
	my $snips = $self->snippets;
51
52
	$snips->add_snippet(
53
			'all_headers',
54
			sub { $_[0]->authed },
55
			'css' => '/css/admin.css'
56
		);
57
}
58
59
sub _say_hi {
60
	my $c = shift;
61
62
	my $uname = $c->session->{user}
63
		? $c->session->{user}->name 
64
		: 'Anonymous user';
65
66
	$c->add_message({
67
			type=>'info',
68
			message=>"Just called to say hi to you, $uname!"
69
		});
70
	$c->redirect_to('/');
71
}
72
73
1;
74
__END__

+ 17 - 0
examples/templates/pages/index.html.ep

@ -0,0 +1,17 @@
1
% layout 'basics';
2
3
<div class="hero-unit">
4
	<h1>oSMo - All In</h1>
5
	<p>oSMo is a kickstarter for websites -
6
		<a href="http://mojolicio.us">Mojolicious</a> and 
7
		<a href="http://twitter.github.io/bootstrap/index.html">Bootstrap</a>
8
		are just the two most important tools over which oSMo was writen.
9
	</p>
10
	<p>See bellow the full list of features:</p>
11
</div>
12
<div class="row-fluid">
13
	<div class="span4">
14
		<h2>Authentication</h2>
15
		
16
	</div>
17
</div>

+ 8 - 0
examples/templates/pages/info.html.ep

@ -0,0 +1,8 @@
1
% layout 'basics';
2
3
<div>
4
<h1>Some Info</h1>
5
6
<p>Here there will be some info for most users.</p>
7
8
</div>

+ 8 - 0
examples/templates/pages/more_anonym.html.ep

@ -0,0 +1,8 @@
1
% layout 'basics';
2
3
<div>
4
<h1>More Info for Anonymous users</h1>
5
6
<p>Here there will be some info for anonymous users.</p>
7
8
</div>

+ 8 - 0
examples/templates/pages/more_authed.html.ep

@ -0,0 +1,8 @@
1
% layout 'basics';
2
3
<div>
4
<h1>More Info for Authenticated users</h1>
5
6
<p>Here there will be some info for authenticated users.</p>
7
8
</div>

+ 19 - 0
examples/wbin/allin.pl

@ -0,0 +1,19 @@
1
#!/usr/bin/env perl
2
3
use strict;
4
use warnings;
5
6
use lib qw(../lib ../../lib);
7
use oSMo::Examples::AllIn;
8
9
print STDERR <<EoI;
10
11
****** INFO *********
12
This example needs a database to be fully functional.
13
Please use the file database/tables.sql to create the needed tables
14
and set the config in examples/config/allin.ini for this to work
15
16
EoI
17
18
oSMo::Examples::AllIn->new->start;
19