2023-03-31 11:52:37 -04:00
|
|
|
# frozen_string_literal: true
|
2022-12-10 01:59:30 -05:00
|
|
|
|
2023-03-31 11:52:37 -04:00
|
|
|
require 'net/ldap'
|
|
|
|
|
|
|
|
class Webdap
|
|
|
|
# Handles /auth routes
|
|
|
|
class AuthController
|
2022-12-10 01:59:30 -05:00
|
|
|
|
2023-03-31 11:52:37 -04:00
|
|
|
get '/login' do
|
|
|
|
erb :'auth/login', locals: {
|
|
|
|
title: 'Login to your account',
|
2022-12-10 18:55:58 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-03-31 11:52:37 -04:00
|
|
|
post '/login' do
|
2023-03-31 12:12:48 -04:00
|
|
|
ldap = Net::LDAP.new(:host => $conf.get('ldap.server_url'), :port => 389)
|
|
|
|
ldap_bind_dn = "#{$conf.get('ldap.user_uid_attr')}=#{params[:auth_username]},#{$conf.get('ldap.user_ou')}"
|
|
|
|
|
|
|
|
if ldap.bind(:method => :simple, :username => ldap_bind_dn, :password => params[:auth_password])
|
|
|
|
session['ldap_uid'] = params[:auth_username]
|
2023-03-31 11:52:37 -04:00
|
|
|
redirect '/account/view'
|
|
|
|
else
|
|
|
|
# Authentication failure
|
|
|
|
erb :'auth/login', locals: {
|
|
|
|
title: 'Login to your account',
|
|
|
|
fail: true,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2022-12-10 01:59:30 -05:00
|
|
|
end
|