summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/sessions_controller.rb19
-rw-r--r--app/views/sessions/new.html.erb4
-rw-r--r--config/routes.rb2
3 files changed, 13 insertions, 12 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
diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb
index a820b2f..550a54d 100644
--- a/app/views/sessions/new.html.erb
+++ b/app/views/sessions/new.html.erb
@@ -1,6 +1,6 @@
<h1>Sign in</h1>
-<% if @fail %>
- <p class="error">Email and password combination not found</p>
+<% if @user.nil? %>
+ <p class="errors"> The username or password is incorrect. Verify that CAPS LOCK is not on, and then retype the current username and password. </p>
<% end %>
<div class="row">
<div class="span6 offset3">
diff --git a/config/routes.rb b/config/routes.rb
index 85f063e..a4badf9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -3,7 +3,7 @@ Leaguer::Application.routes.draw do
#creates sessions as a resource but limits it to these actions
match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get'
- match '/signout', to: 'sessions#destroy', via: 'get'
+ match '/signout', to: 'sessions#destroy', via: 'delete'
resources :sessions, only: [:new, :create, :destroy]