working login, signup, and logout

This commit is contained in:
Ken Johnson
2013-04-25 00:19:00 -04:00
parent 0154fecb0a
commit 47ce08bb20
20 changed files with 74 additions and 17 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base
private
def current_user
@current_user ||= User.find_by_user_id(session[:user_id].to_s)
@current_user ||= User.find_by_id(session[:id].to_s)
end
def authenticated
+6
View File
@@ -0,0 +1,6 @@
class DashboardController < ApplicationController
def home
end
end
+13
View File
@@ -3,9 +3,22 @@ class SessionsController < ApplicationController
skip_before_filter :authenticated, :only => [:new, :create]
def new
redirect_to dashboard_home_path(:dashboard_id => current_user.id) if current_user && current_user.id
end
def create
user = User.authenticate(params[:email], params[:password])
if user
session[:id] = user.id if User.where(:id => user.id).exists?
redirect_to dashboard_home_path(:dashboard_id => user.id)
else
render "new"
end
end
def destroy
reset_session
redirect_to root_path
end
end
View File
+9
View File
@@ -3,9 +3,18 @@ class UsersController < ApplicationController
skip_before_filter :authenticated, :only => [:new, :create]
def new
@user = User.new
end
def create
user = User.new(params[:user])
if user.save
session[:id] = user.id
redirect_to dashboard_home_path(:dashboard_id => user.id)
else
@user = User.new
render :new
end
end
end
+2
View File
@@ -0,0 +1,2 @@
module DashboardHelper
end
Regular → Executable
View File
+16 -1
View File
@@ -1,3 +1,18 @@
class User < ActiveRecord::Base
attr_accessible :email, :password, :user_id, :admin
attr_accessible :email, :password, :user_id, :admin, :password_confirmation
validates_confirmation_of :password, :password_confirmation
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
def self.authenticate(email, password)
auth = nil
user = find_by_email(email)
# I heard something about hashing, dunno, why bother really. Nobody will get access to my stuff!
if user && user.password == password
auth = user
end
return auth
end
end
View File
+3 -4
View File
@@ -4,7 +4,8 @@
</a>
<div class="user-profile">
<a data-toggle="dropdown" class="dropdown-toggle">
<img src="../assets/profile_color.jpg" alt="profile">
<img src=" <%= image_path('profile_color.jpg')%>" alt="profile">
</a>
<span class="caret"></span>
<ul class="dropdown-menu pull-right">
@@ -19,9 +20,7 @@
</a>
</li>
<li>
<a href="#">
Logout
</a>
<%= link_to "logout", logout_path %>
</li>
</ul>
</div>
View File
View File
+8 -8
View File
@@ -5,7 +5,7 @@
<div class="row-fluid">
<div class="span4 offset4">
<div class="signup">
<%= form_tag "users", :class=> "signup-wrapper" do %>
<%= form_for @user, :html => {:class=> "signup-wrapper"} do |f| %>
<div class="header">
<h2>Sign Up</h2>
@@ -13,18 +13,18 @@
</div>
<div class="content">
<%= label_tag "Email Address" %>
<%= text_field_tag :email, params[:email], {:class => "input input-block-level"} %>
<%= f.label "Email Address" %>
<%= f.text_field :email, {:class => "input input-block-level"} %>
<%= label_tag :password, nil %>
<%= password_field_tag :password, nil, {:class => "input input-block-level"}%>
<%= f.label :password, nil %>
<%= f.password_field :password, {:class => "input input-block-level"}%>
<%= label_tag :confirm_password, nil %>
<%= password_field_tag :password_confirmation, nil, {:class => "input input-block-level"}%>
<%= f.label :confirm_password %>
<%= f.password_field :password_confirmation, {:class => "input input-block-level"}%>
</div>
<div class="actions">
<%= submit_tag "Submit", {:class => "btn btn-info btn-large pull-right"} %>
<%= f.submit "Submit", {:class => "btn btn-info btn-large pull-right"} %>
</div>
<div class="clearfix"></div>
<% end %>
+5 -2
View File
@@ -1,9 +1,8 @@
Railsgoat::Application.routes.draw do
get "users/new"
get "login" => "sessions#new"
get "signup" => "users#new"
get "logout" => "sessions#destroy"
resources :sessions do
@@ -17,6 +16,10 @@ resources :tutorials do
end
resources :dashboard do
get "home" => "dashboard#home"
end
root :to => "sessions#new"
end
@@ -3,7 +3,6 @@ class CreateUsers < ActiveRecord::Migration
create_table :users do |t|
t.string :email
t.string :password
t.string :user_id
t.boolean :admin
t.timestamps
Regular → Executable
View File
+7
View File
@@ -0,0 +1,7 @@
require 'test_helper'
class DashboardControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
View File
+4
View File
@@ -0,0 +1,4 @@
require 'test_helper'
class DashboardHelperTest < ActionView::TestCase
end
View File