Skip to content
Merged
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
15 changes: 13 additions & 2 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ class OrdersController < ApplicationController
# GET /orders.json
def index
# filtering information according to current user
@user = User.find(current_user.id)
@orders = @user.orders.all

@user = User.find(current_user.id)

if @user.admin?

@orders = Order.all

else

@orders = @user.orders.all

end

#@orders = Order.all
end

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def login
flash[:notice] = "you are logged in"
redirect_to :controller => :items
#session[:cart] = nil

current_user.update_attribute :admin, true
end
def logout
#in case things go crazy and impossible to understand uncomment the line below and logout /login
Expand Down
23 changes: 16 additions & 7 deletions app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

<div class="footer-buttons">

<% if session[:login] == 1 %>
<%= link_to 'New Item', new_item_path,:class =>"button", :role=>"button" %>
<%= link_to 'New Genre', new_genre_path,:class =>"button", :role=>"button" %>
<%= link_to 'New Console', new_console_path,:class =>"button", :role=>"button" %>
<% if user_signed_in? %>

<% end %>

<% if current_user.admin? %>


<%= link_to 'New Item', new_item_path,:class =>"button", :role=>"button" %>
<%= link_to 'New Genre', new_genre_path,:class =>"button", :role=>"button" %>
<%= link_to 'New Console', new_console_path,:class =>"button", :role=>"button" %>

<%= link_to 'View orders', orders_path, :class => 'button', :role => 'button' %>

<% else %>

<li>other</li>

<% end %>

<% if user_signed_in? %>
<%= link_to 'View orders', orders_path, :class => 'button', :role => 'button' %>
<% end %>
</div>
<hr>
Expand Down
20 changes: 15 additions & 5 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,26 @@
<% if user_signed_in? %>
<li><%= link_to 'Edit Profile', edit_user_registration_path %></li>
<li><%= link_to 'Sign Out', destroy_user_session_path, :method =>:delete %></li>

<% if current_user.admin? %>
<li class = "isAdminLi">Admin</li>
<% else %>
<li class = "isAdminLi">User</li>
<% end %>
<% else %>
<li><%= link_to 'Register', new_user_registration_path %></li>
<li><%= link_to 'Sign In', new_user_session_path %></li>
<% end %>

<% if session[:login] == 1 %>
<li><%= link_to "Admin Logout", logout_path %></li>
<% else %>
<li><%= link_to "Admin Login", login_path %></li>



<% end %>









Expand Down
2 changes: 1 addition & 1 deletion app/views/static_pages/about.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<title>GameLand | About</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
Expand Down
2 changes: 1 addition & 1 deletion app/views/static_pages/help.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<title>GameLand | Help</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.
5 changes: 5 additions & 0 deletions db/migrate/20180421092309_add_admin_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAdminToUsers < ActiveRecord::Migration[5.1]
def change
add_column :users, :admin, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180418113405) do
ActiveRecord::Schema.define(version: 20180421092309) do

create_table "brands", force: :cascade do |t|
t.string "title"
Expand Down Expand Up @@ -82,6 +82,7 @@
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "admin", default: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Expand Down
6 changes: 6 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)




User.create(email: "info@gameland.com", admin:"true", password: "1234567", password_confirmation: "1234567")