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
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == ENV['BASIC_AUTH_USERNAME'] && password == ENV['BASIC_AUTH_PASSWORD']
end
end
end
2 changes: 2 additions & 0 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ArticlesController < ApplicationController
before_filter :authenticate, :except => [:index, :show]

def index
@articles = Article.all.order("created_at DESC")
end
Expand Down
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
module ApplicationHelper
def logged_in?
not request.authorization.nil?
end
end
8 changes: 4 additions & 4 deletions app/views/articles/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<ul>
<% @articles.each_with_index do |article, i| %>
<li>
<a href="<%= article_path(article) %>"><%= article.title %> <span><%= article.created_at.strftime('%B %e, %Y') %></span></a>
(<%= link_to 'Edit', edit_article_path(article) %> or <%= link_to 'Destroy', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %>)
<a href="<%= article_path(article) %>">
<%= article.title %>
<span><%= article.created_at.strftime('%B %e, %Y') %></span>
</a>
</li>
<% end %>
</ul>
Expand Down
8 changes: 8 additions & 0 deletions app/views/articles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
</article>
</div>
</main>
<% if logged_in? %>
<div class="Container Container--mainColumn">
<div class="Container-inner">
<%= link_to 'Edit', edit_article_path(@article) %>
<%= link_to 'Destroy', article_path(@article), method: :delete, data: { confirm: 'Are you sure?' } %>
</div>
</div>
<% end %>
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<div class="Masthead-navigation">
<nav class="Navigation" role="navigation">
<ul class="Navigation-list">
<% if logged_in? %>
<li class="Navigation-listItem"><%= link_to 'New', new_article_path, class: "Navigation-listItemLink" %></li>
<% end %>
<li class="Navigation-listItem"><a href="<%= articles_path -%>" class="Navigation-listItemLink">Writing</a></li>
<li class="Navigation-listItem"><a href="#" class="Navigation-listItemLink">About</a></li>
</ul>
Expand Down