-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSylSpace
executable file
·94 lines (72 loc) · 2.53 KB
/
SylSpace
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
#!/usr/bin/env perl
use Mojolicious::Lite;
use lib 'lib';
use SylSpace::Model::Utils qw(_getvar);
my $vardir=_getvar();
plugin 'Mojolyst' => {controllers => 'SylSpace::Controller'};
plugin 'RenderFile';
plugin 'browser_detect';
plugin 'SylSpace::URL';
my $configfname= app->home->child("SylSpace-Secrets.conf");
if (app->mode eq 'production') {
die "you need a $configfname config file for production"
unless -e $configfname;
}
################
$ENV{SYLSPACE_siteacolor}='AntiqueWhite'; $ENV{SYLSPACE_jumboacolor}='darkgreen';
$ENV{SYLSPACE_siteicolor}=$ENV{SYLSPACE_sitescolor}='white';
$ENV{SYLSPACE_jumboscolor}='darkblue'; $ENV{SYLSPACE_jumboicolor}='darkred';
my $has_oauth;
helper has_oauth => sub { $has_oauth };
if (-e $configfname) {
app->log
->debug("$0: good: your config is $configfname");
my $credentials= plugin 'Config' => { file => $configfname };
die "could not read config file" unless $credentials;
die 'you must have at least one oauth provider for login'
if app->mode eq 'production' and not keys %{$credentials->{oauth}};
my %scopes = ( google => 'email profile', github => 'user:email',
facebook => 'email');
my %oauth;
for my $provider (qw/google github facebook/) {
if (my $creds = $credentials->{oauth}{$provider}) {
my ($key, $secret) = @$creds;
app->log->debug("[enabling $provider authentication]");
$oauth{$provider} = {
key => $key,
secret => $secret,
scope => $scopes{$provider}
};
}
}
plugin 'OAuth2', \%oauth;
$has_oauth++;
}
use Perl6::Slurp;
my @pwsecret=slurp("$vardir/secrets.txt");
app->secrets( \@pwsecret ); ## the first one encodes, the others are usable; maybe rotate by day
my $users = glob "$vardir/users/*\@*";
die "you need at least one known users in $vardir/users\n"
unless $users;
my $courses = glob "$vardir/courses/*";
die "you need at least one known course in $vardir/courses,\n"
unless $courses;
app->hook(before_server_start => sub {
my $name = app->config->{site_name};
if (app->mode eq 'development') {
$name //= 'lvh.me';
if ($name eq 'localhost' or $name eq '127.0.0.1') {
app->log->debug(<<WARNIT);
you can't use 127.0.0.1 or localhost, switching you to lvh.me for testing
WARNIT
$name = 'lvh.me';
}
} else {
app->log->fatal(
"login can't work unless you define a site_name in the config")
and die "a horrible death\n" unless $name;
}
app->sessions->cookie_domain($name);
app->log->debug("$0: Now starting SylSpace on $name");
});
app->start();