diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index fa014dc..91de7ea 100755 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -7,13 +7,20 @@ class SessionsController < ApplicationController end def create - user = User.authenticate(params[:email], params[:password]) + + begin + user = User.authenticate(params[:email], params[:password]) + rescue Exception => e + end + if user session[:id] = user.id if User.where(:id => user.id).exists? redirect_to home_dashboard_index_path else + flash[:error] = e.message render "new" end + end def destroy diff --git a/app/models/user.rb b/app/models/user.rb index 7178fa8..43c9a75 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,8 +13,14 @@ class User < ActiveRecord::Base 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 + if user + if user.password == password + auth = user + else + raise "Incorrect Password!" + end + else + raise "#{email} doesn't exist!" end return auth end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 366c7b5..c5fc8bb 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -26,6 +26,7 @@ <% end %>