diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..005119ba --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.4.1 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 00f91bb2..543296fe 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,8 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + helper_method :current_user def current_user - + @current_user ||= User.find(session[:user_id]) if session[:user_id] end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index f990b351..e2483d85 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,4 +1,14 @@ class SessionsController < ApplicationController def new end + + def create + user = User.find_by(email: params[:email]) + if user && user.authenticate(params[:password]) + session[:user_id] = user.id + redirect_to user_path(user) + else + render :new + end + end end diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index e69de29b..5ec56da1 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,7 @@ +<%= form_tag login_path do %> + <%= label_tag :email %> + <%= text_field_tag :email %> + <%= label_tag :password %> + <%= password_field_tag :password %> + <%= submit_tag "Log In" %> +<% end %> \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index beb1c899..e8952b2d 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,3 +1,4 @@ +