diff --git a/main.rb b/main.rb index d6bf13e..00f1457 100644 --- a/main.rb +++ b/main.rb @@ -9,12 +9,12 @@ require 'ostruct' Blog = OpenStruct.new( - :title => 'a scanty blog', - :author => 'John Doe', - :url_base => 'http://localhost:4567/', - :admin_password => 'changeme', - :admin_cookie_key => 'scanty_admin', - :admin_cookie_value => '51d6d976913ace58', + :title => 'Mind Dump', + :author => 'Alexander Vanadio', + :url_base => 'http://192.168.111.49:3030/', + :admin_password => 'password', + :admin_cookie_key => 'master_007_retsam', + :admin_cookie_value => '51d6Rplk9VNace58', :disqus_shortname => nil ) end @@ -35,7 +35,7 @@ def admin? end def auth - stop [ 401, 'Not authorized' ] unless admin? + halt [ 401, 'Not authorized' ] unless admin? end end @@ -50,7 +50,7 @@ def auth get '/past/:year/:month/:day/:slug/' do post = Post.filter(:slug => params[:slug]).first - stop [ 404, "Page not found" ] unless post + halt [ 404, "Page not found" ] unless post @title = post.title erb :post, :locals => { :post => post } end @@ -89,7 +89,12 @@ def auth end post '/auth' do - set_cookie(Blog.admin_cookie_key, Blog.admin_cookie_value) if params[:password] == Blog.admin_password + response.set_cookie(Blog.admin_cookie_key, Blog.admin_cookie_value) if params[:password] == Blog.admin_password + redirect '/' +end + +get '/logout' do + response.set_cookie(Blog.admin_cookie_key, "") redirect '/' end @@ -108,18 +113,27 @@ def auth get '/past/:year/:month/:day/:slug/edit' do auth post = Post.filter(:slug => params[:slug]).first - stop [ 404, "Page not found" ] unless post + halt [ 404, "Page not found" ] unless post erb :edit, :locals => { :post => post, :url => post.url } end +get '/past/:year/:month/:day/:slug/delete' do + auth + post = Post.filter(:slug => params[:slug]).first + halt [ 404, "Page not found" ] unless post + STDERR.puts "Seems ok?" + post.delete + redirect '/' +end + + post '/past/:year/:month/:day/:slug/' do auth post = Post.filter(:slug => params[:slug]).first - stop [ 404, "Page not found" ] unless post + halt [ 404, "Page not found" ] unless post post.title = params[:title] post.tags = params[:tags] post.body = params[:body] post.save redirect post.url end - diff --git a/public/main.css b/public/main.css index c9b3be8..45969a6 100644 --- a/public/main.css +++ b/public/main.css @@ -148,7 +148,7 @@ hr { } .post .title a { - color: white; + color: #00CCFF; text-decoration: none; } @@ -174,11 +174,14 @@ hr { } #new_post { - position: absolute; - top: 1em; - right: 1em; } +#login { +} + +#logout { +} + /* Post */ .postzoom { @@ -214,6 +217,13 @@ hr { right: 0; } +.postzoom .delete { + text-align: right; + position: absolute; + top: 30; + right: 0; +} + /* Footer */ #footer { diff --git a/views/index.erb b/views/index.erb index e346170..83b51e3 100644 --- a/views/index.erb +++ b/views/index.erb @@ -42,7 +42,16 @@ <% end %> <% if admin? %> -
+