Class: DbdocEngine::DbDocSessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/dbdoc_engine/db_doc_sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#create ⇒ Object

Authenticates the user and starts a session



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/dbdoc_engine/db_doc_sessions_controller.rb', line 11

def create
  # Find user by username
  user = User.find_by(username: params[:username])

  # Authenticate user with password
  if user&.authenticate(params[:password])
    # Store user ID in session and redirect to admin dashboard
    session[:user_id] = user.id
    redirect_to root_path, notice: 'Logged in successfully!'
  else
    # Redirect back to login with error message
    redirect_to , notice: '❌ Invalid Username or Password'
  end
end

#destroy ⇒ Object

Logs out the user by clearing the session



27
28
29
30
31
# File 'app/controllers/dbdoc_engine/db_doc_sessions_controller.rb', line 27

def destroy
  # Clear session and redirect to home
  session[:user_id] = nil
  redirect_to , notice: 'Logged out!'
end

#new ⇒ Object

Renders the login form



6
7
8
# File 'app/controllers/dbdoc_engine/db_doc_sessions_controller.rb', line 6

def new
  # Login form
end