Add logout button for sessions

This commit is contained in:
benji 2015-03-20 04:20:39 +01:00
parent 3ecb2b53d8
commit 67285d8107
3 changed files with 19 additions and 11 deletions

View file

@ -13,11 +13,17 @@ class UserAvatarController < ApplicationController
end
end
def destroy
reset_session
redirect_to root_path
end
private
def authenticate_session_user!
redirect_to root_path unless session[:id]
@user = User.find session[:id]
@user = User.find_by session[:id]
reset_session unless @user
end
def user_params

View file

@ -17,6 +17,8 @@
<div class="form-group">
<% if user_signed_in? %>
<%= button_to "Logout", destroy_user_session_path, class: "btn btn-default form-control", method: :delete %>
<% elsif session[:id] %>
<%= button_to "Logout", user_avatar_path(session[:id]), class: "btn btn-default form-control", method: :delete %>
<% else %>
<%= link_to "Login", new_user_session_path, class: "btn btn-success form-control" %>
<% end %>

View file

@ -37,37 +37,38 @@ end
users = [
{
nickname: 'admin',
uid: 'admin',
avatar: File.new('public/seeds/users/admin.jpg', 'r'),
admin: true
},
{
nickname: 'koelkast',
uid: 'koelkast',
avatar: File.new('public/seeds/users/admin.jpg', 'r'),
koelkast: true
},
{
nickname: 'benji',
uid: 'benji',
avatar: File.new('public/seeds/users/benji.jpg', 'r'),
dagschotel: Product.first
dagschotel: Product.first,
provider: 'zeuswpi'
},
{
nickname: 'don',
uid: 'don',
avatar: File.new('public/seeds/users/don.jpg', 'r')
},
{
nickname: 'silox',
uid: 'silox',
avatar: File.new('public/seeds/users/silox.jpg', 'r')
}
]
users.each do |attr|
User.create(
nickname: attr[:nickname],
uid: attr[:uid],
provider: attr[:provider],
avatar: attr[:avatar],
dagschotel: attr[:dagschotel],
password: DEFAULT_PASSWORD,
password_confirmation: DEFAULT_PASSWORD,
admin: attr[:admin] || false,
koelkast: attr[:koelkast] || false
)
@ -75,9 +76,8 @@ end
50.times do |i|
User.create(
nickname: "testUser#{i}",
uid: "testUser#{i}",
avatar: users[0][:avatar],
password: DEFAULT_PASSWORD,
password_confirmation: DEFAULT_PASSWORD
)
end