Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ A Redis hash named `user:<user id>` with the following fields:
apisecret -> api POST requests secret code, to prevent CSRF attacks.
flags -> flags used to mark users as admins and so forth
karma_incr_time -> last time karma was incremented
new_window -> (1/0) Open news links in a new window?

Additionally the user has an additional key:

Expand Down
26 changes: 21 additions & 5 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,16 @@
H.li {H.b {"posted comments "}+posted_comments.to_s}
}
}+if $user and $user['id'].to_i == user['id'].to_i
H.br+H.form(:name=>"f") {
H.form(:name=>"f") {
H.label(:for => "new_window") {
"Open links in new window?"
}+if $user['new_window'] == '1'
H.checkbox(:name => "new_window",
:value => "1", :checked => "1")
else
H.checkbox(:name => "new_window", :value => 1)
end +
H.br +
H.label(:for => "email") {
"email (not visible, used for gravatar)"
}+H.br+
Expand Down Expand Up @@ -482,12 +491,13 @@

post '/api/updateprofile' do
return {:status => "err", :error => "Not authenticated."}.to_json if !$user
if !check_params(:about, :email)
if !check_params(:about, :email, :new_window)
return {:status => "err", :error => "Missing parameters."}.to_json
end
$r.hmset("user:#{$user['id']}",
"about", params[:about][0..4095],
"email", params[:email][0..255])
"email", params[:email][0..255],
"new_window", (params[:new_window] == "1" ? "1" : "0"))
return {:status => "ok"}.to_json
end

Expand Down Expand Up @@ -945,9 +955,15 @@ def news_to_html(news)
"&#9650;"
}+" "+
H.h2 {
H.a(:href=>news["url"]) {
H.entities news["title"]
if $user['new_window'] == '1'
H.a(:href=>news['url'], :target=>'_blank') {
H.entities news['title']
}
else
H.a(:href=>news["url"]) {
H.entities news["title"]
}
end
}+" "+
H.address {
if domain
Expand Down
7 changes: 6 additions & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ function submit() {
}

function update_profile() {
var checked = "0";
if($("input[name=new_window]").is(":checked")) {
checked = "1";
}
var data = {
email: $("input[name=email]").val(),
about: $("textarea[name=about]").val(),
about: $("textarea[name=about]").val(),
new_window: checked,
apisecret: apisecret
};
$.ajax({
Expand Down