34 lines
691 B
Ruby
34 lines
691 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'net/ldap'
|
|
|
|
class Webdap
|
|
# Handles /auth routes
|
|
class AuthController
|
|
|
|
get '/login' do
|
|
erb :'auth/login', locals: {
|
|
title: 'Login to your account',
|
|
}
|
|
end
|
|
|
|
post '/login' do
|
|
ldap = Net::LDAP.new
|
|
ldap.host = cnf['ldap']['server_url']
|
|
ldap.port = 389
|
|
ldap.auth(params[:login_username], params[:login_password])
|
|
if ldap.bind()
|
|
session['ldap_uid'] = params[:username]
|
|
redirect '/account/view'
|
|
else
|
|
# Authentication failure
|
|
erb :'auth/login', locals: {
|
|
title: 'Login to your account',
|
|
fail: true,
|
|
}
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|