Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7051

Ruby with sinatra question

Newsgroups comp.lang.ruby
Date 2014-12-09 03:47 -0800
Message-ID <d8bf6c18-93eb-4bbf-bae0-2bc2cc61c2cc@googlegroups.com> (permalink)
Subject Ruby with sinatra question
From trekr5 <cebirim@gmail.com>

Show all headers | View raw


Hi,

I'm new to ruby programming and have the following question...

I'm trying to prepopulate a form field with data from a connection to an LDAP server.

This is my sinatra app:- (ruby that launches the app)

#app.rb

require 'net/ldap'

USERNAME = ""
  def protected!
    return if authorized?
    headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
    halt 401, "Not authorized\n"
  end

  def authorized?
    @auth ||=  Rack::Auth::Basic::Request.new(request.env)
    @auth.provided? and @auth.basic? and @auth.credentials and is_authenticated_by_ldap(@auth.credentials) 
  end

def is_authenticated_by_ldap(credentials)
  	
         EXTENSION = "xxxxxxxxxx.com"
  	 full_username = credentials[0] + EXTENSION

  	ldap = Net::LDAP.new  :host => "xxxxxxxxx.com", # your LDAP host name or IP goes here,
                       :port => 389, # your LDAP host port goes here,
                      #:encryption => :simple_tls,
                       :base => "xxxxxxxxx", # the base of your AD tree goes here,
                       :auth => 
                      {
                       :method => :simple,
                      	:username => full_username, # a user w/sufficient privileges to read from AD goes here,
      			:password => credentials[1] # the user's password goes here

}
       #credentials[0] is the login name so it would be full_username = credentials[0] + xxxxxxxxxx.com             		
   
is_authorized = ldap.bind
   return is_authorized
 end

class GGInfraUserManager < Sinatra::Base

   get '/' do 
	protected!
	erb :index

   end
end

I'd like to prepoulate a form field for username in my index.erb file  (see below) with the login value (credentials[0])

<div class="form-group">
			<label for="username" class="col-sm-1 control-label">Username</label>
			<div class="col-sm-4">
				<input type="text" class="form-control" name="username" value="<%=  %>">
			</div>
		</div>

what would i use in the form to do this as I'm not using rails?

(Hope this is clear!)

Back to comp.lang.ruby | Previous | Next | Find similar


Thread

Ruby with sinatra question trekr5 <cebirim@gmail.com> - 2014-12-09 03:47 -0800

csiph-web