Skip to content

Commit

Permalink
User agent on user record, small improvements to user viewe
Browse files Browse the repository at this point in the history
  • Loading branch information
francispotter committed Mar 16, 2011
1 parent dd2ffdc commit 16e79fd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rails/app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create
session[:token] = auth["credentials"]["token"]
end
session[:provider] = auth["provider"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth, request.env['HTTP_USER_AGENT'])
puts "----- LOGIN: " + user.name + "(" + user.id.to_s + ") via " + request.env['HTTP_USER_AGENT']
session[:user_id] = user.id
user_agent = request.env['HTTP_USER_AGENT']
Expand Down
2 changes: 2 additions & 0 deletions rails/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def edit
# POST /users.xml
def create
@user = User.new(params[:user])

@user.user_agent_at_creation = request.env["HTTP_USER_AGENT"]

respond_to do |format|
if @user.save
Expand Down
3 changes: 2 additions & 1 deletion rails/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ def initialize(params = nil)
self.role ||= DEFAULT_ROLE
end

def self.create_with_omniauth(auth)
def self.create_with_omniauth(auth, user_agent)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["user_info"]["name"]
user.email = auth["extra"]["user_hash"]["email"] rescue "-"
user.user_agent_at_creation = user_agent
end
end

Expand Down
5 changes: 5 additions & 0 deletions rails/app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<%= f.text_field :uid %>
</div>

<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>

<div class="field">
<%= f.label :role %><br />
<%= f.select(:role, User::ROLES.invert) %>
Expand Down
10 changes: 9 additions & 1 deletion rails/app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@
<%=time_since(@user.created_at)%>
</p>

<p>
<b>User Agent (browser) at Creation</b>
<%= @user.user_agent_at_creation%>
</p>

<%if @user.provider = 'facebook'%>
<p>
<b><%= link_to "Facebook Profile", "http://www.facebook.com/profile.php?id=" + @user.uid%>
</p>
<%end%>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddUserAgentAtCreationToUsers < ActiveRecord::Migration
def self.up
add_column :users, :user_agent_at_creation, :string
end

def self.down
remove_column :users, :user_agent_at_creation
end
end
3 changes: 2 additions & 1 deletion rails/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110302164427) do
ActiveRecord::Schema.define(:version => 20110316032158) do

create_table "assignments", :force => true do |t|
t.integer "observation_range_id"
Expand Down Expand Up @@ -85,6 +85,7 @@
t.string "name"
t.string "role"
t.string "email"
t.string "user_agent_at_creation"
end

end

0 comments on commit 16e79fd

Please sign in to comment.