forked from publify/publify
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance user profile: allows users to upload an avatar (issue publify…
…#230). The display_user_avatar() helper displays in that order: * The user's uploaded avatar. * The user's Twitter avatar if the previous one does not exist * Nothing if no avatar is available (maybe a placeholder should be interesting, I'll add an issue for this when I have some network connection). TODO: we need to find out how to test file uploads for both the profile and resources controllers.
- Loading branch information
Frédéric de Villamil
committed
Sep 9, 2013
1 parent
e1ccf8e
commit 353cdbb
Showing
9 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
require 'fog' | ||
|
||
class Admin::ProfilesController < Admin::BaseController | ||
def index | ||
@user = current_user | ||
@profiles = Profile.find(:all, :order => 'id') | ||
@user.attributes = params[:user] | ||
if request.post? and @user.save | ||
current_user = @user | ||
flash[:notice] = _('User was successfully updated.') | ||
if request.post? | ||
avatar = upload_avatar if params[:user][:filename] | ||
@user.avatar = avatar.upload.avatar.url | ||
@user.thumb_avatar = avatar.upload.thumb.url | ||
@user.medium_avatar = avatar.upload.medium.url | ||
@user.large_avatar = avatar.upload.url | ||
|
||
if @user.save | ||
current_user = @user | ||
flash[:notice] = _('User was successfully updated.') | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def upload_avatar | ||
file = params[:user][:filename] | ||
|
||
unless file.content_type | ||
mime = 'text/plain' | ||
else | ||
mime = file.content_type.chomp | ||
end | ||
|
||
Resource.create(:upload => file, :mime => mime, :created_at => Time.now) | ||
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<% @page_heading = _('Your profile') %> | ||
<% @page_heading_class = 'icon-profile' %> | ||
<%= form_tag :action=>"index", :id => @user.id do %> | ||
<%= form_tag({:action => 'index', :id => @user.id}, {:enctype => "multipart/form-data"}) %> | ||
<%= render :partial => "admin/users/form" %> | ||
<% 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
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
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