Add stylesheet selector to account page
This commit is contained in:
parent
4a459a813d
commit
fd9aae65ea
|
@ -15,6 +15,12 @@ plugins:
|
||||||
driver: 'SQLite'
|
driver: 'SQLite'
|
||||||
dbname: 'db.sqlite'
|
dbname: 'db.sqlite'
|
||||||
|
|
||||||
|
stylesheets:
|
||||||
|
default: "cyberpunk"
|
||||||
|
available:
|
||||||
|
- "cyberpunk"
|
||||||
|
- "light"
|
||||||
|
|
||||||
tld: 'cyb'
|
tld: 'cyb'
|
||||||
|
|
||||||
reserved_domains:
|
reserved_domains:
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table user add column stylesheet text;
|
||||||
|
update cyberman set dbrev=5;
|
|
@ -40,21 +40,26 @@ hook 'before' => sub {
|
||||||
my $uid = cookieval("id");
|
my $uid = cookieval("id");
|
||||||
my $token = cookieval("token");
|
my $token = cookieval("token");
|
||||||
my $auth = 0;
|
my $auth = 0;
|
||||||
my $email;
|
my $user;
|
||||||
if ($uid && $token) {
|
if ($uid && $token) {
|
||||||
$auth = get_auth($uid, $token);
|
$auth = get_auth($uid, $token);
|
||||||
$email = database->quick_lookup(
|
$user = database->quick_select(
|
||||||
"user",
|
"user",
|
||||||
{
|
{
|
||||||
"id" => $uid,
|
"id" => $uid,
|
||||||
},
|
},
|
||||||
"email",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var auth => $auth;
|
var auth => $auth;
|
||||||
var email => $email;
|
var email => $user->{"email"};
|
||||||
var config => config();
|
var config => config();
|
||||||
|
|
||||||
|
if (grep {$_ eq $user->{"stylesheet"}} @{ config->{"stylesheets"}->{"available"} }) {
|
||||||
|
var stylesheet => $user->{"stylesheet"};
|
||||||
|
} else {
|
||||||
|
var stylesheet => config->{"stylesheets"}->{"default"};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
get qr{^/(index)?$} => sub {
|
get qr{^/(index)?$} => sub {
|
||||||
|
|
|
@ -17,6 +17,7 @@ get '/account' => sub {
|
||||||
|
|
||||||
template 'account' => {
|
template 'account' => {
|
||||||
"user" => $user,
|
"user" => $user,
|
||||||
|
"updated" => param("updated") ? 1 : 0,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,6 +66,10 @@ post '/account' => sub {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!grep {$_ eq param("stylesheet")} @{ config->{"stylesheets"}->{"available"} }) {
|
||||||
|
$errs{"e_bad_sheet"} = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (scalar(keys %errs) != 0) {
|
if (scalar(keys %errs) != 0) {
|
||||||
return template 'account' => {
|
return template 'account' => {
|
||||||
"user" => $user,
|
"user" => $user,
|
||||||
|
@ -120,17 +125,34 @@ post '/account' => sub {
|
||||||
"redir" => "login?pwchange=1",
|
"redir" => "login?pwchange=1",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
database->quick_update (
|
||||||
|
"user",
|
||||||
|
{
|
||||||
|
"id" => vars->{"auth"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"stylesheet" => param("stylesheet"),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
$user = database->quick_select (
|
my $newuser = database->quick_select (
|
||||||
"user",
|
"user",
|
||||||
{
|
{
|
||||||
"id" => vars->{"auth"},
|
"id" => vars->{"auth"},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Instant stylesheet update
|
||||||
|
if ($user->{"stylesheet"} ne $newuser->{"stylesheet"}) {
|
||||||
|
return template 'redir' => {
|
||||||
|
"redir" => "account?updated=1",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
template 'account' => {
|
template 'account' => {
|
||||||
updated => 1,
|
updated => 1,
|
||||||
user => $user,
|
user => $newuser,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ create table cyberman (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
dbrev integer not null
|
dbrev integer not null
|
||||||
);
|
);
|
||||||
insert into cyberman (dbrev) values (4);
|
insert into cyberman (dbrev) values (5);
|
||||||
|
|
||||||
drop table if exists user;
|
drop table if exists user;
|
||||||
create table user (
|
create table user (
|
||||||
|
@ -14,7 +14,8 @@ create table user (
|
||||||
active integer not null default 0,
|
active integer not null default 0,
|
||||||
conftoken text not null,
|
conftoken text not null,
|
||||||
newemail text,
|
newemail text,
|
||||||
recoverytoken text
|
recoverytoken text,
|
||||||
|
stylesheet text
|
||||||
);
|
);
|
||||||
|
|
||||||
drop table if exists session;
|
drop table if exists session;
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
<% IF e_email_exists %>
|
<% IF e_email_exists %>
|
||||||
<li>There is already an account with that email address.</li>
|
<li>There is already an account with that email address.</li>
|
||||||
<% END %>
|
<% END %>
|
||||||
|
<% IF e_bad_sheet %>
|
||||||
|
<li>The stylesheet selected was invalid.</li>
|
||||||
|
<% END %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -72,6 +75,22 @@
|
||||||
<input type="password" name="npassword2" id="npassword2" />
|
<input type="password" name="npassword2" id="npassword2" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="stylesheet">Stylesheet name:</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select id="stylesheet" name="stylesheet">
|
||||||
|
<% FOREACH sheet IN vars.config.stylesheets.available %>
|
||||||
|
<option name="<% sheet | html_entity %>"
|
||||||
|
<% IF user.stylesheet == sheet %>
|
||||||
|
selected=selected
|
||||||
|
<% END %>
|
||||||
|
><% sheet | html_entity %></option>
|
||||||
|
<% END %>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<br />
|
<br />
|
||||||
[ <button class="textButton" action="submit">update</button> ]
|
[ <button class="textButton" action="submit">update</button> ]
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<meta http-equiv="refresh" content="0;<% redir %>" />
|
<meta http-equiv="refresh" content="0;<% redir %>" />
|
||||||
<% END %>
|
<% END %>
|
||||||
<title>cybNIC</title>
|
<title>cybNIC</title>
|
||||||
<link rel="stylesheet" type="text/css" href="/css/style.css" />
|
<link rel="stylesheet" type="text/css" href="/css/<% vars.stylesheet %>.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
|
|
Loading…
Reference in New Issue