Top Level Namespace

Defined Under Namespace

Modules: Authentication, Authlogic, I0n Classes: CreateUsers, User, UserSession, UserSessionsController, UserSessionsControllerTest, UserTest, UsersController, UsersControllerTest

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



1
2
3
# File 'lib/generators/i0n/authentication/templates/app/models/_user.rb', line 1

def password
  @password
end

Class Method Details

.authenticate(email, password) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/generators/i0n/authentication/templates/app/models/_user.rb', line 11

def self.authenticate(email, password)
  user = find(:first, :conditions => {:email => email})
  if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
    user
  else
    nil
  end
end

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
# File 'lib/generators/i0n/authentication/templates/app/controllers/_users_controller.rb', line 13

def create
  @user = User.new(params[:user])
  if @user.save
    flash[:notice] = "User #{@user.email} created."
    redirect_to users_url
  else
    render 'new'
  end
end

#destroyObject



38
39
40
41
42
# File 'lib/generators/i0n/authentication/templates/app/controllers/_users_controller.rb', line 38

def destroy
  @user = User.find(params[:id])
  @user.destroy
  redirect_to users_url  
end

#editObject



23
24
25
# File 'lib/generators/i0n/authentication/templates/app/controllers/_users_controller.rb', line 23

def edit
  @user = User.find(params[:id])
end

#encrypt_passwordObject



20
21
22
23
24
25
# File 'lib/generators/i0n/authentication/templates/app/models/_user.rb', line 20

def encrypt_password
  if password.present?
    self.password_salt = BCrypt::Engine.generate_salt
    self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
  end
end

#indexObject



4
5
6
# File 'lib/generators/i0n/authentication/templates/app/controllers/_users_controller.rb', line 4

def index
  @users = User.all
end

#newObject



9
10
11
# File 'lib/generators/i0n/authentication/templates/app/controllers/_users_controller.rb', line 9

def new
  @user = User.new
end

#updateObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/i0n/authentication/templates/app/controllers/_users_controller.rb', line 27

def update
  @user = User.find(params[:id])
  respond_to do |format|
    if @user.update_attributes(params[:user])
      redirect_to root_path, :notice => 'User information updated.'
    else
      render "edit"
    end
  end
end