Skip to content

Instantly share code, notes, and snippets.

@d2kagw
Created May 25, 2011 23:53
Show Gist options
  • Save d2kagw/992255 to your computer and use it in GitHub Desktop.
Save d2kagw/992255 to your computer and use it in GitHub Desktop.
view and model

Edit.html.haml

-# Captures for parent templates
- content_for :page_title, t("accounts.forgotten_password.page_title")

= resource
= resource.email

User.rb

class User < ActiveRecord::Base
  
  # Devise Authentication Properties
  devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable
  
  # User properties
  attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :sign_in_count, :timezone, :gmtoffset
  
  # always treat emails as lowercase fields
  before_save do
    self.email.downcase! if self.email
  end
  
  # Exportable properties
  def as_json(options={})
    {:user => self.serializable_hash(:only => [:id, :first_name, :last_name, :email, :last_sign_in_at, :timezone, :gmtoffset])}
  end
  
  def send_welcome_message!(client, user)
    generate_reset_password_token!
    ::Devise.mailer.welcome_instructions(self, client, user).deliver
  end
  
  def self.find_for_authentication(conditions)
    conditions[:email].downcase!
    super(conditions)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment