From 134360da46c1f8e5153c1c9eb5180ac990150d93 Mon Sep 17 00:00:00 2001 From: Tomer Kimia Date: Tue, 4 Mar 2014 17:57:15 -0500 Subject: signin gives error if user cannot sign in --- app/controllers/sessions_controller.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index fa5d024..a74cbd3 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -2,9 +2,7 @@ class SessionsController < ApplicationController # GET /sessions/new def new - if @user.nil? - @user = User.new - end + @user = User.new end # POST /sessions @@ -12,12 +10,15 @@ class SessionsController < ApplicationController # find the user... @user = User.find_by(email: params[:session][:email].downcase) # ... and create a new session - if @user && @user.authenticate(params[:session][:password]) - sign_in @user - redirect_to root_path - else - redirect_to new_session_path - end + respond_to do |format| + if @user && @user.authenticate(params[:session][:password]) + sign_in @user + redirect_to root_path + else + format.html { render action: 'new' } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end end # DELETE /sessions/current -- cgit v1.2.3-2-g168b