Displaying 20 results from an estimated 20 matches for "find_by_login".
2007 Nov 17
18
Syntax Problem
...ontroller.rb file to see if
crypted_password is blank. If it is, crypt and check the password
against the old md5 version and write it in the new crypted_password
field.
Here is my code add on before the logged_in?:
def create
# if no password use old md5 and fill in with sha2
user = User.find_by_login(params[:login])
if #{user.crypted_password} == nil
#check_md5?
(params[:password],#{user.old_salt},#{user.hashed_password})
@p = Digest::MD5::hexdigest("#{params[:password]}")
@s = Digest::MD5::hexdigest(user.old_salt)
@pw = Digest::MD5.hexdigest(@s+@p)...
2006 Jul 11
1
Problems using the authorization plugin from Bill Katz
...trying to use the excellent authorization plugin from Bill Katz,
Its pretty straight forward to setup and should be to use.
But when i try to give the same permission on two differents users on
the same object i get an error.
(Well , Im kinda new to all this rails stuff)
r = Red.find(1)
u1 = User.find_by_login("ismael")
u2 = User.find_by_login("ismael2")
u1.has_role "proprio", r
u2.has_role "proprio", r
ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry ''5'' for
key 1: INSERT INTO roles_users (`updated_at`, `role_id`, `id`,
`user_id`,...
2005 Dec 23
2
has_many and belongs_to relationship error
...: <h3><%= h(post.posttitle) %></h3>
13: <%= post.posttext %>
The code follows:
class Post < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :posts
end
class BlogController < ApplicationController
def index
@user = User.find_by_login(''bilal'')
@posts = @user.posts
@missions = Mission.find(:all)
end
end
index.rhtml is
<% for mission in @missions %>
<div class="mission">
<h3><%= h(mission.missionname) %></h3>
<%= mission.missiondescription %>
</div>
<...
2010 Aug 18
6
Once I added this HABTM, one of my 'through' relationships, on a non-habtm model, seems to have broke?
...class Subscription < ActiveRecord::Base
belongs_to :user, :foreign_key => "user_id"
belongs_to :meter_group, :foreign_key => "meter_group_id"
has_many :meters, :through => :meter_group
end
test "group1 and group2 belong to rachel" do
user = User.find_by_login("rachel")
subscriptions = Subscription.find_all_by_user_id(user.id)
subscriptions.each do |s|
meters = s.meters
meters.each do |m|
puts "meter = #{p m}"
end
end
end
However now things are not working since I created some HABTM relationshi...
2006 May 08
6
how to make field in model immutable after create
Hello everyone!
I want to have login field in User model which is set only once (on
create), and then it should fail validation if the value is changed.
How can I do this? I dig around for validation and tried
def after_validation_on_update
unless User.find_by_login(:login)
errors.add(:login, "is immutable. You can''t change it")
end
end
in model, but somewhat it doesn''t work. Any hints on how can I make
field immutable after create?
Peace,
olegf
2006 May 22
2
good practice or waste of time?
...ted plugin
I have setup the appropriate pieces and use a before_filter to
require the session to be that of a logged in user. So far, so good.
Here''s where things (finally) get interesting. When my controller
needs to edit an item, I typically do this:
def find_user
@user = User.find_by_login(session[:user])
end
def find_library
find_user
@library = @user.library
end
def edit_item
find_library
@item = @user.library.items.find(params[:id]) <--- necessary?
# other processing
end
It''s that second line in my #edit_item action that I''m curious about....
2006 Feb 09
6
troubleshooting an observe_field
Hi,
I''ve got a live_search field in a partial that is on several different
pages. On all pages, except 1, it works fine. On the page it doesn''t work
on, it seems it never executes it action.
Here''s my observe_field code inside the partial:
<h1><label for="searchtext">Live Search:</label></h1>
<%= text_field_tag :searchtext
2006 May 22
0
logger and ActionWebService - how can I get them to work together?
...erviceController < ApplicationController
wsdl_service_name ''LibraryService''
web_service_api LibraryServiceApi # format is <controller_name>Api
web_service_scaffold :invoke
def new_item(username, type, title, length, size, state, unique_key)
@user = User.find_by_login(username)
logger.fatal(@user)
puts @user
true
end
end
In #new_item I can''t get logger to output anything nor does my #puts
go anywhere that I can find. (BTW, the test passes without errors.)
Scouring the AWDR book and online resources has gotten me nowhere.
Can anyon...
2006 Mar 03
1
Pagination and custom routing
...=> ''per_user''
This works fine and sends them to the correct controller, links, where
the action per_user paginates a list of bookmarks depending on the
username defined by :username in the map.connect above.
The action that generates the pages looks like this -
user = User.find_by_login(@params[:username])
@bookmark_pages, @bookmarks = paginate(:bookmarks, :conditions =>
[''user_id = ?'', user.id])
The first page of results works fine, i can type www.mysite.com/dave for
instance, and i recieve the first page of my bookmarks.
The problem is with the rest of t...
2008 Nov 07
1
Problem autenticating user
...new encrypted password
but always returns nil. The database password was encryted with the same
encrypt method. I dont know what i need to do.
TNKS a lot..
# Authenticates a user by their login name and unencrypted password. Returns
the user or nil.
*
def self*.authenticate(login, password)
u = find_by_login(login) # need to get the salt and user_password
u && u.authenticated?(password) ? u :* nil
end
*
# Encrypts some data with the salt.
*
def self*.encrypt(password, salt)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
*
end
*
# Encrypts the password with the user salt
*...
2007 Sep 20
1
Relationship Proxies?
I''m trying to understand these results in irb, which implies that
there''s some kind of proxy at play:
>> aaron = User.find_by_login ''aaron''
=> #<User:0xb7109cdc
@attributes={"salt"=>"7e3041ebc2fc05a40c60028e2c4901a81035d3cd",
"updated_at"=>nil, "contact_info_id"=>nil,
"crypted_password"=>"00742970dc9e6319f8019fd54864d3ea740f04b1",
&q...
2010 Jul 13
1
NoMethodError in UsersController#show
...t;, :id =>
"login_btn" %> <%= link_to "Sign Up", new_user_path %></p>
<% end %>
</div>
</fieldset>
Here are the relevant controllers and models:
Users_Controller:
def show
#@user = User.find(params[:id])
@user = User.find_by_login(params[:login])
#@feed_items = @user.feed
@feed_items = @user.feed
end
Users Model:
def feed
#Post.all(:conditions => ["user_id = ?", id])
Post.from_users_subscribed_by(self)
end
Post Model (using SQLite3) :
named_scope :from_users_subscribed_by, lambda { |user|
sub...
2006 Jul 02
5
Pretty URLs -> Routes
Hi
I am having issues with getting my pretty urls to work.
routes.rb:
map.connect '':user'' , :controller => ''front'' ,
:action => ''list'' ,
:filter => ''user''
front_controller.rb:
def list
@advert_pages, @adverts = paginate :adverts, :per_page => 10
@user =
2009 May 06
0
Cucumber, Webrat, RSpec and Mechanize for Non-Ruby Apps
...e|
#
# step definition in webrat_steps.rb
#
def path_to(page_name)
case page_name
when /the homepage/
''/''
# Add more mappings here.
# Here is a more fancy example:
#
# when /^(.*)''s profile page$/i
# user_profile_path(User.find_by_login($1))
else
raise "Can''t find mapping from \"#{page_name}\" to a path.\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end
World(NavigationHelpers)[/code]
This is not complete however. If I run rake features at this point, I
get...
2007 Feb 10
5
acts_as_authenticated strangeness
...ust reloads the login
page again.
here`s my action:
def login
return unless request.post?
flash[:notice] = "Incorrent login"
self.current_user = User.authenticate(params[:login],
params[:password])
if logged_in?
session[:username] = params[:login]
user=User.find_by_login(params[:login])
session[:role]=user.organisation
session[:user_id]=user.id
if params[:remember_me] == "1"
self.current_user.remember_me
cookies[:auth_token] = { :value =>
self.current_user.remember_token , :expires =>
self.current_user.remember_to...
2005 Mar 06
3
question about testing
...are passing.
But I just have one question about doing tests in a loop.
In my setup, I''m using the login generator to protect ''sensitive''
actions, while some actions are public. So I''ve got this line in my
setup method:
@request.session["user"] = User.find_by_login "bob"
So now all the tests can successfully test actions that require a log
in. But, for security''s sake, I''d like to test that actions while
logged out, do in fact redirect to the login screen.
I originally wrote the test method like this:
def test_loggedout
@r...
2008 Apr 16
8
Will acts_as_taggable_on_steroids and better_nested_set work together?
I am having this crazy problem where it ONLY shows up in testing.
This is my test code
<code>
def test_should_destroy
task1 = Task.new(:description => "tmp",
:done => false,
:user => User.find_by_login(''admin''))
assert task1.save
assert task1.destroy
end
</code>
This is my task model
<code>
class Task < ActiveRecord::Base
acts_as_taggable
acts_as_nested_set
belongs_to :user
validates_presence_of :user
end
</code>
The result of running th...
2008 Jun 20
15
before_save model callback rspec testing
hi all,
i''m learning rspec and i can''t figure out how to test if a callback is
executed in a model.
my model code is:
class User < ActiveRecord::Base
before_save :encrypt_password
...
def encrypt(password)
self.class.encrypt(password, salt)
end
thanks a lot,
cs.
--
Posted via http://www.ruby-forum.com/.
2006 Jun 16
0
rake spec controller test output hideus.
...t; do
post :signup, :user => { :login => "newbob", :password => "newpassword",
:password_confirmation => "wrong" , :email => "newbob@mcbob.com"}
response.should.be.success
response.session[:user].should.be.nil
User.find_by_login("newbob").should.be.nil
end
And here is the actual error it gives me to "help". I think this
amount should rather be given if I request a rake spec:detailed or
something. If multiple errors occur then I spend a long time just
scrolling around to find the name of the tests tha...
2006 Apr 23
13
post() to other controller in functional test?
In a functional test, I want to call an action in another controller
(a login) before testing things in the current controller. As far as I
can tell from the extremely sparse documentation and the AWDR book,
this seems to be impossible. The post() functions takes an action
argument only, and that''s that. Surely I must be misunderstanding
things?
--
Calle Dybedahl