working login, signup, and logout
This commit is contained in:
@@ -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
|
||||
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
class DashboardController < ApplicationController
|
||||
|
||||
def home
|
||||
end
|
||||
|
||||
end
|
||||
@@ -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
|
||||
|
||||
Regular → Executable
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user