summaryrefslogtreecommitdiff
path: root/app/controllers/sessions_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/sessions_controller.rb')
-rw-r--r--app/controllers/sessions_controller.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 16d11b5..68cb949 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -1,2 +1,22 @@
class SessionsController < ApplicationController
+
+ def new
+ end
+
+ # find the user and create a new session
+ def create
+ user = User.find_by(email: params[:session][:email].downcase)
+ if user && user.authenticate(params[:session][:password])
+ sign_in user
+ redirect_to root_path
+ else
+ render 'new'
+ end
+ end
+
+ def destroy
+ sign_out
+ redirect_to root_path
+ end
+
end