Skip to content

Commit

Permalink
added monban functionality and edited routes
Browse files Browse the repository at this point in the history
*add dashboards controller and show page
* shout out to rob
  • Loading branch information
ChrisCPO committed Oct 20, 2014
1 parent a2bcea9 commit 46a6410
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 57 deletions.
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
bcrypt (3.1.7)
builder (3.2.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
Expand All @@ -52,6 +53,12 @@ GEM
treetop (~> 1.4.8)
mime-types (1.25.1)
minitest (5.4.2)
monban (0.1.1)
bcrypt
rails
warden
monban-generators (0.0.4)
monban (>= 0.0.12)
multi_json (1.10.1)
pg (0.17.1)
polyglot (0.3.5)
Expand Down Expand Up @@ -107,6 +114,8 @@ GEM
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
warden (1.2.3)
rack (>= 1.0)

PLATFORMS
ruby
Expand All @@ -115,6 +124,8 @@ DEPENDENCIES
coffee-rails (~> 4.0.0)
jbuilder (~> 2.0)
jquery-rails
monban
monban-generators
pg
rails (= 4.1.4)
sass-rails (~> 4.0.3)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
include Monban::ControllerHelpers

protect_from_forgery with: :exception
end
7 changes: 7 additions & 0 deletions app/controllers/dashboards_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class DashboardsController < ApplicationController
def show


end

end
28 changes: 28 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class SessionsController < ApplicationController
skip_before_action :require_login, only: [:new, :create]

def new
end

def create
user = authenticate_session(session_params)

if sign_in(user)
redirect_to root_path
else
render :new
end
end

def destroy
sign_out
redirect_to root_path
end

private

def session_params
params.require(:session).permit(:email, :password)
end
end

25 changes: 25 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class UsersController < ApplicationController
skip_before_action :require_login, only: [:new, :create]

def new
@user = User.new
end

def create
@user = sign_up(user_params)

if @user.valid?
sign_in(@user)
redirect_to root_path
else
render :new
end
end

private

def user_params
params.require(:user).permit(:email, :password)
end
end

4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class User < ActiveRecord::Base
validates :email, presence: true, uniqueness: true
validates :password_digest, presence: true
end
3 changes: 3 additions & 0 deletions app/views/dashboards/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>FUCKER</h1>

<h2>FUCKING STEELERS FANS</h2>
14 changes: 10 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Shoutr</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<title>Shoutr</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

<% if signed_in? %>
<%= link_to "Sign out", session_path, method: :delete %>
<% else %>
<%= link_to "Sign in", new_session_path %>
<%= link_to "Sign up", new_user_path %>
<% end %>
<%= yield %>

</body>
Expand Down
13 changes: 13 additions & 0 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= form_for :session, url: session_path do |form| %>
<div>
<%= form.label :email %>
<%= form.email_field :email %>
</div>
<div>
<%= form.label :password %>
<%= form.password_field :password %>
</div>
<div>
<%= form.submit "Sign in" %>
</div>
<% end %>
23 changes: 23 additions & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<%= form_for @user do |form| %>

<% if @user.errors.any? %>
<%= pluralize(@user.errors.count, "error") %> prevented your account from being created:
<ul>
<% @user.errors.full_messages.each do |error_message| %>
<li><%= error_message %></li>
<% end %>
</ul>
<% end %>

<div>
<%= form.label :email %>
<%= form.email_field :email %>
</div>
<div>
<%= form.label :password %>
<%= form.password_field :password %>
</div>
<div>
<%= form.submit "Sign up" %>
</div>
<% end %>
5 changes: 5 additions & 0 deletions config/locales/monban.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
en:
activerecord:
attributes:
user:
password_digest: "Password"
64 changes: 13 additions & 51 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,18 @@
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

# You can have the root of your site routed with "root"
# root 'welcome#index'

# Example of regular route:
# get 'products/:id' => 'catalog#view'

# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
require "monban/constraints/signed_in"
require "monban/constraints/signed_out"

# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
Rails.application.routes.draw do
constraints Monban::Constraints::SignedIn.new do
root "dashboards#show", as: :dashboard
end

# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
constraints Monban::Constraints::SignedOut.new do
root "sessions#new"
end

# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
resource :session, only: [:new, :create, :destroy]
resources :users, only: [:new, :create]

# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
get "sign_up" => "users#new"
get "sign_in" => "sessions#new"
end
12 changes: 12 additions & 0 deletions db/migrate/20141020202903_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :email, null: false
t.string :password_digest, null: false

t.timestamps null: false
end

add_index :users, :email, unique: true
end
end
28 changes: 28 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20141020202903) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "users", force: true do |t|
t.string "email", null: false
t.string "password_digest", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree

end

0 comments on commit 46a6410

Please sign in to comment.