parent
0f95034e8e
commit
c64550785e
15 changed files with 84 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
|||
class SessionsController < ApplicationController
|
||||
require_unregistered_user only: %i[new create]
|
||||
# GET /sessions/new
|
||||
def new
|
||||
@session = Session.new
|
||||
|
@ -11,9 +12,8 @@ class SessionsController < ApplicationController
|
|||
respond_to do |format|
|
||||
if @session.save
|
||||
session[:current_user_id] = @session.user_id
|
||||
Rails.logger.info("ID: #{@session.user_id}")
|
||||
|
||||
format.html { redirect_to root_url, notice: "Session was successfully created." }
|
||||
format.html { redirect_to redirect_url, notice: "Session was successfully created." }
|
||||
format.json { render :show, status: :created, location: @session }
|
||||
else
|
||||
format.html { render :new, status: :unprocessable_entity, alert: @session.errors }
|
||||
|
@ -27,12 +27,16 @@ class SessionsController < ApplicationController
|
|||
session[:current_user_id] = nil
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to root_url, notice: "Session was successfully destroyed." }
|
||||
format.html { redirect_to new_session_url, notice: "Session was successfully destroyed." }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def redirect_url
|
||||
session.delete(:return_url) || root_url
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def session_params
|
||||
params.require(:session).permit(:email, :password)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue