フロントエンドプレイアブル
This commit is contained in:
22
app/controllers/sessions_controller.rb
Normal file
22
app/controllers/sessions_controller.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class SessionsController < ApplicationController
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
user = User.find_by(email: params[:email]&.downcase)
|
||||
if user&.authenticate(params[:password])
|
||||
session[:user_id] = user.id
|
||||
flash[:notice] = "ログインしました"
|
||||
redirect_to root_path
|
||||
else
|
||||
flash.now[:alert] = "メールアドレスまたはパスワードが正しくありません"
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
session[:user_id] = nil
|
||||
flash[:notice] = "ログアウトしました"
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user