# 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(: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] redirect '/account/view' else # Authentication failure erb :'auth/login', locals: { title: 'Login to your account', fail: true, } end end end end