-
-
Save derencius/394870 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Address | |
include Mongoid::Document | |
belongs_to :user, :inverse_of => :addresses | |
belongs_to :venue, :inverse_of => :venues | |
field :street, :type => String | |
field :city, :type => String | |
field :state, :type => String | |
field :zip, :type => Integer | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'chronic' | |
require 'carrierwave/orm/mongoid' | |
require 'access_address' | |
class Conference | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
include AccessAddress | |
mount_uploader :teaser, TeaserUploader | |
before_save :run_chronic_on_dates | |
belongs_to_related :user | |
has_one :venue | |
field :name, :type => String, :required => true | |
field :homepage, :type => String | |
field :date, :type => String | |
field :days, :type => Integer | |
field :price, :type => Integer | |
field :status, :type => String | |
protected | |
def run_chronic_on_dates | |
self.date = Chronic.parse(self.date) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'chronic' | |
require 'gravtastic' | |
require 'access_address' | |
class User | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
include BCrypt | |
include Gravtastic | |
include AccessAddress | |
is_gravtastic! | |
before_save :run_chronic_on_dates, :encrypt_password | |
has_many_related :conferences | |
has_one :address | |
field :email, :type => String | |
field :homepage, :type => String | |
field :name, :type => String | |
field :birthday, :type => String | |
field :hashed_password, :type => String | |
field :admin, :type => Boolean | |
attr_accessor :password, :password_confirmation | |
def self.authenticated?(email, password) | |
if @user = User.first(:email => email) | |
if Password.new(@user.hashed_password) == password | |
return @user | |
else | |
nil | |
end | |
else | |
return nil | |
end | |
end | |
protected | |
def run_chronic_on_dates | |
self.birthday = Chronic.parse(self.birthday) | |
end | |
def encrypt_password | |
unless self.password.blank? | |
self.hashed_password = Password.create(self.password.to_s) | |
self.password = nil | |
end | |
return true | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Venue | |
include Mongoid::Document | |
belongs_to :conference, :inverse_of => :venues | |
has_one :address, :inverse_of => :addresses | |
field :name, :type => String | |
field :homepage, :type => String | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment