Skip to content

Commit

Permalink
add birthdate, gender, nickname
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien Gruhier committed May 17, 2012
1 parent f867c40 commit dc7aee7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ h1,h2,h3,h4,h5 {font-family: 'Convergence', sans-serif;}

.form-horizontal .help-block {
font-style: italic;
margin-top: -5px;
margin-top: 0px;
color: #888;
}

Expand Down
26 changes: 23 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,39 @@ class User
## Token authenticatable
field :authentication_token, :type => String

field :admin, :type => Boolean
field :admin, :type => Boolean
field :nickname, :type => String
field :birthdate, :type => Date
field :gender, :type => String

has_many :prescriptions

attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :email, :password, :password_confirmation, :remember_me, :birthdate, :nickname, :gender

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token.extra.raw_info
logger.warn data.inspect
if data.birthday
m, d, y = data.birthday.split("/")
birthday = data.birthday ? Date.parse("#{y}-#{m}-#{d}") : nil
else
birthday = nil
end
username = data.username ? data.username : nil
gender = data.gender ? data.gender : nil
logger.warn data.username
logger.warn username

if user = User.where(:email => data.email).first
# Update user info if need be
user.nickname ||= username if username
user.birthdate ||= birthday if birthday
user.gender ||= data.gender if gender
user.save
user
else # Create a user with a stub password.
password = Devise.friendly_token[0,20]
User.create!(:email => data.email, :password => password, :password_confirmation => password)
User.create!(:email => data.email, :password => password, :password_confirmation => password, :gender => gender, :nickname => username, :birthdate => birthday)
end
end
end
9 changes: 6 additions & 3 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :class => 'form-horizontal'} ) do |f| %>
<%= f.input :email, :required => true, :autofocus => true %>
<%= f.input :password, :autocomplete => "off", :hint => t('devise.registrations.leave_blank'), :required => false %>
<%= f.input :password_confirmation, :required => false %>
<%= f.input :current_password, :hint => t('devise.registrations.current_password_label'), :required => true %>
<%= f.input :nickname, :input_html => {:autocomplete => :off} %>
<%#= f.input :birthdate, :as => :date %>
<%= f.input :gender, :as => :radio_buttons, :collection => {"#{t :male}" => "male", "#{t :female}" => "female"} %>
<%= f.input :password, :input_html => {:autocomplete => :off}, :hint => t('devise.registrations.leave_blank'), :required => false %>
<%= f.input :password_confirmation, :required => false , :input_html => {:autocomplete => :off} %>
<%= f.input :current_password, :hint => t('devise.registrations.current_password_label'), :required => true , :input_html => {:autocomplete => :off}%>

<div class="control-group">
<div class="controls">
Expand Down
2 changes: 1 addition & 1 deletion app/views/medications/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<% if admin? %>
<% @prescriptions.each do |prescription| %>
<div class="row well">
<%= prescription.user.email %>
<%= prescription.user.nickname.blank? ? t(:anonymous) : prescription.user.nickname %>
<% prescription.secondary_effects_array.each do |tag| %>
<span class="label label-info"><%= tag %></span>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "omniauth-facebook"
Rails.application.config.middleware.use OmniAuth::Builder do
if Rails.env.development?
provider :facebook, '362807127093790', 'a3d57d6c1bd18e65c01b0e6fe2900332', :setup => true
provider :facebook, '362807127093790', 'a3d57d6c1bd18e65c01b0e6fe2900332', :setup => true, scope: "user_birthday,user_about_me"
elsif Rails.env.production?
provider :facebook, '334294033301652', '8606d936d9557b892a5c42c605e83aa2', :setup => true
provider :facebook, '334294033301652', '8606d936d9557b892a5c42c605e83aa2', :setup => true, scope: "user_birthday,user_about_me"
end
end
OmniAuth.config.logger = Rails.logger
3 changes: 3 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ fr:
add: Ajouter
from: Du
to: Au
male: Homme
female: Femme
anonymous: Anonyme
devise:
remember_me: Rester connecté
sign_in: Se connecter
Expand Down

0 comments on commit dc7aee7

Please sign in to comment.