Class: Customer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Customer
- Defined in:
- app/models/customer.rb
Overview
The Customer model handles customers.
Class Method Summary (collapse)
-
+ (Object) find_by_auth_token(authentication_token)
Get the customer object via the authentication token.
-
+ (Object) from_facebook(auth_token, user_data)
Authenticate the user via facebook.
-
+ (Object) from_omniauth(auth, current_customer)
Authenticate the user via omni auth.
-
+ (Object) new_with_session(params, session)
Create a new session.
Instance Method Summary (collapse)
-
- (Object) ensure_authentication_token
Generate a new authentication token for the customer.
-
- (Object) get_customer_name
Get the full customer name.
-
- (Object) get_devise_auth_token
Get the authentication token for the customer.
-
- (Object) remove_devise_auth_token(authentication_token)
Remove the authentication token for the customer.
Class Method Details
+ (Object) find_by_auth_token(authentication_token)
Get the customer object via the authentication token.
68 69 70 71 72 73 74 75 76 |
# File 'app/models/customer.rb', line 68 def self.find_by_auth_token(authentication_token) = Authorization.where(:provider => 'devise', :token => authentication_token).first unless .blank? unless .customer.blank? .customer end end end |
+ (Object) from_facebook(auth_token, user_data)
Authenticate the user via facebook.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/models/customer.rb', line 123 def self.from_facebook(auth_token, user_data) = Authorization.where(:provider => 'facebook', :uid => user_data['id'].to_s, :token => auth_token).first_or_initialize if .customer.blank? customer = Customer.where('email = ?', user_data['email']).first if customer.blank? customer = Customer.new customer.password = Devise.friendly_token customer.first_name = user_data['first_name'] customer.last_name = user_data['last_name'] customer.email = user_data['email'] customer.save end .username = user_data['username'] .customer_id = customer.id .save end .customer end |
+ (Object) from_omniauth(auth, current_customer)
Authenticate the user via omni auth.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/customer.rb', line 99 def self.from_omniauth(auth, current_customer) = Authorization.where(:provider => auth.provider, :uid => auth.uid.to_s, :token => auth.credentials.token, :secret => auth.credentials.secret).first_or_initialize if .customer.blank? customer = current_customer.nil? ? Customer.where('email = ?', auth['info']['email']).first : current_customer if customer.blank? customer = Customer.new customer.password = Devise.friendly_token customer.first_name = auth['info']['first_name'] customer.last_name = auth['info']['last_name'] customer.email = auth.info.email auth.provider == 'twitter' ? customer.save(:validate => false) : customer.save end .username = auth.info.nickname .customer_id = customer.id .save end .customer end |
+ (Object) new_with_session(params, session)
Create a new session.
83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/customer.rb', line 83 def self.new_with_session(params, session) if session['devise.user_attributes'] new(session['devise.user_attributes'], without_protection: true) do |customer| customer.attributes = params customer.valid? end else super end end |
Instance Method Details
- (Object) ensure_authentication_token
Generate a new authentication token for the customer.
27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/customer.rb', line 27 def ensure_authentication_token = Authorization.where(:provider => 'devise', :customer_id => id.to_s).first_or_initialize if .token.blank? #generate new token .token = Devise.friendly_token end .save end |
- (Object) get_customer_name
Get the full customer name
21 22 23 |
# File 'app/models/customer.rb', line 21 def get_customer_name first_name + ' ' + last_name end |
- (Object) get_devise_auth_token
Get the authentication token for the customer.
40 41 42 43 44 45 46 |
# File 'app/models/customer.rb', line 40 def get_devise_auth_token = Authorization.where(:provider => 'devise', :customer_id => id.to_s).first unless .blank? .token end end |
- (Object) remove_devise_auth_token(authentication_token)
Remove the authentication token for the customer.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/customer.rb', line 52 def remove_devise_auth_token(authentication_token) = Authorization.where(:provider => 'devise', :token => authentication_token).first unless .blank? if .destroy return true end end return false end |