Skip to content

Commit

Permalink
Add Success/Error Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
badosu committed Apr 26, 2015
1 parent 977271e commit 8ef447e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions routes/user_sessions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ class Yogurt
r.post do
env['warden'].authenticate!

flash[:success] = "You are logged in"

r.redirect session[:return_to] || '/communities'
end

r.delete do
env['warden'].logout

flash[:success] = "You are logged out"

r.redirect '/user_sessions/new'
end
end
Expand All @@ -22,6 +26,8 @@ class Yogurt
session[:return_to] = env['warden.options'][:attempted_path]
response.status = 403

flash[:danger] = "Could not authenticate"

render '/user_sessions/new'
end
end
Expand Down
6 changes: 6 additions & 0 deletions views/layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
<h3 class="text-muted">Project name</h3>
</div>

<% flash.each do |kind, message| %>
<div class='alert alert-<%= kind %>' role='alert'>
<p> <%= message %> </p>
</div>
<% end %>
<%= yield %>

<footer class="footer">
Expand Down
7 changes: 7 additions & 0 deletions views/user_sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
<div class="container">
<form class="form-signin" action='/user_sessions' method='POST'>
<h2 class="form-signin-heading">Please sign in</h2>

<% flash.each do |kind, message| %>
<div class='alert alert-<%= kind %>' role='alert'>
<p> <%= message %> </p>
</div>
<% end %>

<label for="email" class="sr-only">Email address</label>
<input type="email" name='email' class="form-control" placeholder="Email address" required autofocus>
<label for="password" class="sr-only">Password</label>
Expand Down
1 change: 1 addition & 0 deletions yogurt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Yogurt < Roda
plugin :all_verbs
plugin :symbol_views
plugin :view_options
plugin :flash
plugin :render, ext: 'html.erb', layout: '/layout'
plugin :static, %w[/images /fonts]
plugin :multi_route
Expand Down

0 comments on commit 8ef447e

Please sign in to comment.