This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Coocook.pm
220 lines (174 loc) Β· 6.73 KB
/
Coocook.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package Coocook;
# ABSTRACT: Web application for collecting recipes and making food plans
# VERSION
use Moose;
use MooseX::MarkAsMethods autoclean => 1;
use utf8;
use Catalyst::Runtime 5.80;
# Set flags and add plugins for the application.
#
# Note that ORDERING IS IMPORTANT here as plugins are initialized in order,
# therefore you almost certainly want to keep ConfigLoader at the head of the
# list if you're using it.
#
# -Debug: activates the debug mode for very useful log messages
# ConfigLoader: will load the configuration from a Config::General file in the
# application's home directory
# Static::Simple: will serve static files from the application's root
# directory
## no critic (BuiltinFunctions::ProhibitStringyEval Subroutines::ProhibitSubroutinePrototypes)
# too bad Perl doesn't offer to check if a module is available
# other code (that passes perlcritic) for testing this is much more verbose
sub mod_installed ($) {
my ($module) = @_;
local $@;
return eval("require $module; 1") ? $module : ();
}
## use critic
use Catalyst (
qw<
ConfigLoader
+Coocook::Plugin::StrictTransportSecurity
+Coocook::Plugin::UriForStatic
Session
Session::Store::DBIC
Session::State::Cookie
Authentication
Static::Simple
>,
( mod_installed 'Catalyst::Plugin::StackTrace' ? 'StackTrace' : () ),
);
extends 'Catalyst';
with 'Coocook::Helpers';
if ( $ENV{CATALYST_DEBUG} ) { # Coocook->debug() doesn't work here, always returns false
if ( mod_installed 'CatalystX::LeakChecker' ) {
with 'CatalystX::LeakChecker';
}
# print emails on STDOUT in debugging mode
$ENV{EMAIL_SENDER_TRANSPORT} //= 'Print';
}
# Configure the application.
#
# Note that settings in coocook.conf (or other external
# configuration file that you set up manually) take precedence
# over this when using ConfigLoader. Thus configuration
# details given here can function as a default configuration,
# with an external configuration file acting as an override for
# local deployment.
### DEFAULT/FACTORY SETTINGS ###
__PACKAGE__->config( name => 'Coocook' ); # referenced in next block
__PACKAGE__->config(
# reasoning: if tab title bar in browser is short,
# display most important information first
date_format_short => '%a, %{day} %b', # Mon, 31 Dec
# based on
# https://en.wikipedia.org/w/index.php?title=Calendar_date&oldid=799176855
date_format_long => '%A, %{day} %B %Y', # Monday, 31 December 2001
datetime_format_short => '%{day} %b %Y %H:%M:%S', # 31 Dec 2001 12:34:56
datetime_format_long => '%A, %{day} %B %Y %H:%M:%S', # Monday, 31 December 2001 12:34:56
new_user_default_roles => [
'private_projects', # disable to prohibit new users creating private projects
],
about_page_title => "About",
# TODO move to local config of Coocook.org once 3rd party instances exist
help_links => [
{
title => "Mailing list",
url => 'https://lists.coocook.org/mailman/listinfo/coocook',
},
{
title => "Report issues",
url => 'https://github.com/dboehmer/coocook/issues',
},
],
# enable registration as self service, defaults to false
enable_user_registration => 0,
captcha => {
form_min_time_secs => undef, # minimum time between GET and POST /register
form_max_time_secs => undef, # maximum time between GET and POST /register
use_hidden_input => 0, # lure bots into filling <input> hidden by CSS
},
registration_example_username => 'daniel_boehmer42',
email_from_address => do {
my $username = # see https://stackoverflow.com/a/3526587/498634
( $^O ne 'riscos' && $^O ne 'MSWin32' ? getpwuid($<) : undef )
|| ( $^O ne 'riscos' ? getlogin() : undef )
|| $ENV{USER}
|| 'coocook';
my $hostname = do {
if ( mod_installed 'Sys::Hostname::FQDN' ) {
Sys::Hostname::FQDN::fqdn();
}
elsif ( my $fqdn = `hostname --fqdn` ) {
chomp $fqdn;
$fqdn;
}
else { 'localhost' }
};
$username . '@' . $hostname;
},
email_sender_name => __PACKAGE__->config->{name},
email_signature => sub {
my $c = shift;
return $c->config->{name} . " " . $c->uri_for_action('/index');
},
# send emails to site_owners about new users registered
notify_site_owners_about_registrations => 1,
# Disable deprecated behavior needed by old applications
disable_component_resolution_regex_fallback => 1,
enable_catalyst_header => 1, # Send X-Catalyst header
use_hash_multivalue_in_request => 1, # safer return value for $c->req->params()
request_class_traits => [
'DisableParam', # disable old, unsafe interface to request params
],
'Model::DB' => {
connect_info => {
dsn => 'development', # referrs to dbic.yaml
},
},
'Plugin::Authentication' => {
default => {
credential => {
class => 'Password',
password_field => 'password_hash',
password_type => 'self_check',
},
store => {
class => 'DBIx::Class',
user_model => 'DB::User',
role_relation => 'roles_users',
role_field => 'role',
store_user_class => 'Coocook::Authentication::Store::DBIx::Class::User', # custom implementation
},
}
},
'Plugin::StrictTransportSecurity' => {
enabled => 1,
},
'Plugin::Session' => {
dbic_class => 'DB::Session',
expires => 24 * 60 * 60, # 24h
cookie_secure => 2, # deliver and accept only via HTTPS
cookie_httponly => 1, # make browser send cookie only via HTTP(S), not to JavaScript code
},
default_view => 'HTML',
'View::Email::TT' => {
INCLUDE_PATH => [
__PACKAGE__->path_to(qw< root email_templates >),
__PACKAGE__->path_to(qw< root common_templates >),
],
},
'View::HTML' => {
INCLUDE_PATH => [
__PACKAGE__->path_to(qw< root custom_templates >), # allow overriding with custom files
__PACKAGE__->path_to(qw< root templates >),
__PACKAGE__->path_to(qw< root common_templates >),
],
},
);
# Start the application
__PACKAGE__->setup();
=head1 SEE ALSO
L<Coocook::Controller::Root>, L<Catalyst>
=cut
1;