Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ruby rails - session management
- def self.Authenticate(login, pass)
- user = find_by_user_id(login)
- if user
- user
- else
- return false
- end
- conn = Net::LDAP.new(
- :host => SERVER,
- :port => PORT,
- :base => BASE,
- :auth => {
- :username => "#{login}@#{DOMAIN}",
- :password => pass,
- :method => :simple
- }
- )
- if conn.bind
- return true
- else
- return false
- end
- rescue Net::LDAP::LdapError => e
- return false
- end
- def create
- user = User.Authenticate(params[:user_id], params[:password])
- if user
- session[:user_id] = user.id
- redirect_to theapp_url, :notice => "Logged in!"
- else
- flash.now.alert = "Invalid email or password"
- render "new"
- end
- end
- <%= form_tag sessions_path do %>
- <p>
- <%= label_tag :Username %><br />
- <%= text_field_tag :user_id, params[:user_id] %>
- </p>
- <p>
- <%= label_tag :Password %><br />
- <%= password_field_tag :password %>
- </p>
- <p class="button"><%= submit_tag "Log in" %></p>
- <% end %>
- NoMethodError in SessionsController#create
- undefined method `id' for true:TrueClass
- Rails.root: /myapp
- Application Trace | Framework Trace | Full Trace
- app/controllers/sessions_controller.rb:12:in `create'
- Request
- Parameters:
- {"utf8"=>"✓",
- "authenticity_token"=>"OmzCrLHR1t/xfIXNcEzy2NCGfVpEKSyI4OZfqpPEFNw=",
- "user_id"=>"admin",
- "password"=>"[FILTERED]",
- "commit"=>"Log in"}
Add Comment
Please, Sign In to add comment