main
1class SessionsController < ApplicationController
2 skip_before_action :authorize!, only: [:new, :create]
3
4 def new
5 @user = User.new
6 end
7
8 def create
9 user = User.find_by(username: params[:username])
10 if user && user.authenticate(params[:password])
11 session[:x] = user.id
12 redirect_to agents_path
13 else
14 redirect_to new_session_path
15 end
16 end
17
18 def destroy
19 reset_session
20 redirect_to new_session_path
21 end
22end