mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-17 02:52:55 +00:00
Moving to github
This commit is contained in:
24
app/controllers/sessions_controller.rb
Normal file
24
app/controllers/sessions_controller.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class SessionsController < ApplicationController
|
||||
before_action :require_no_authentication, only: [ :new, :create ]
|
||||
before_action :require_authentication, only: [ :destroy ]
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
user = User.find_by(email: params[:email].downcase)
|
||||
|
||||
if user && user.authenticate(params[:password])
|
||||
sign_in(user)
|
||||
redirect_to dashboard_path, notice: "Welcome back, #{user.username}!"
|
||||
else
|
||||
flash.now[:alert] = "Invalid email or password"
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
sign_out
|
||||
redirect_to root_path, notice: "You have been signed out."
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user