diff --git a/.rubocop.yml b/.rubocop.yml index 22aafe2..40e70b0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -31,7 +31,7 @@ Metrics/BlockLength: - config/environments/development.rb Layout/IndentationConsistency: - EnforcedStyle: indented_internal_methods + EnforcedStyle: normal Layout/MultilineMethodCallIndentation: EnforcedStyle: indented diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c5f1264..bd7cdcc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,16 @@ class ApplicationController < ActionController::Base skip_before_action :verify_authenticity_token + + before_action :ensure_authentication + + protected + + def ensure_authentication + redirect_to login_path if current_user.blank? + end + + def current_user + @current_user ||= User.find_by(id: session[:current_user_id]) + end end diff --git a/app/controllers/authenticate_controller.rb b/app/controllers/authenticate_controller.rb deleted file mode 100644 index b1a7e18..0000000 --- a/app/controllers/authenticate_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class AuthenticateController < ApplicationController - def create - # Enable authentication here - end -end diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb new file mode 100644 index 0000000..75c1322 --- /dev/null +++ b/app/controllers/conversations_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ConversationsController < ApplicationController + def index; end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..88e11a4 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class SessionsController < ApplicationController + skip_before_action :ensure_authentication + + def new; end + + def create + user = User.find_or_initialize_by(email: params[:email]) + if user.authenticate(params[:password]) + session[:current_user_id] = user.id + redirect_to root_path + else + render :new, status: :unauthorized + end + end + + def destroy + session[:current_user_id] = nil + redirect_to login_path + end +end diff --git a/app/views/conversations/index.html.erb b/app/views/conversations/index.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/conversations/show.html.erb b/app/views/conversations/show.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..87e4635 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,19 @@ + + +
+ +