diff options
author | Tomer Kimia <tkimia@purdue.edu> | 2014-03-04 17:57:15 -0500 |
---|---|---|
committer | Tomer Kimia <tkimia@purdue.edu> | 2014-03-04 17:57:15 -0500 |
commit | 134360da46c1f8e5153c1c9eb5180ac990150d93 (patch) | |
tree | 4709fec28870b98cc66376b527f493d119b0269d /app/controllers/sessions_controller.rb | |
parent | 8e005f8d325a43e378f21a1042df6a4baf79c12f (diff) |
signin gives error if user cannot sign in
Diffstat (limited to 'app/controllers/sessions_controller.rb')
-rw-r--r-- | app/controllers/sessions_controller.rb | 19 |
1 files changed, 10 insertions, 9 deletions
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 |