diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 75ca452..531a660 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -33,8 +33,11 @@ class SessionsController < ApplicationController end def store_sensitive_user_data_in_session - session[:provider] = @user.provider - session[:uid] = @user.uid + session[:new_user] = { + :provider => @user.provider, + :uid => @user.uid, + :avatar_url => @user.avatar_url + } end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index abd5d15..ef357fb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,8 @@ class UsersController < ApplicationController PER_PAGE = 20 + before_filter :ensure_authenticated!, :only => [:edit, :update] + def show @user = User.find_by_nickname(params[:nickname]) collection = @user.asciicasts. @@ -23,15 +25,25 @@ class UsersController < ApplicationController end end + def edit + @user = current_user + end + + def update + current_user.update_attributes(params[:user]) + redirect_to profile_path(current_user), + :notice => 'Account settings saved.' + end + private def load_sensitive_user_data_from_session - @user.provider = session[:provider] - @user.uid = session[:uid] + @user.provider = session[:new_user][:provider] + @user.uid = session[:new_user][:uid] + @user.avatar_url = session[:new_user][:avatar_url] end def clear_sensitive_session_user_data - session[:provider] = nil - session[:uid] = nil + session.delete(:new_user) end end diff --git a/app/models/user.rb b/app/models/user.rb index 5093588..d02ef88 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,8 @@ class User < ActiveRecord::Base has_many :asciicasts, :dependent => :destroy has_many :comments, :dependent => :destroy + attr_accessible :nickname, :email, :name + def self.create_with_omniauth(auth) user = new user.provider = auth["provider"] diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 0000000..8f07ffd --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,31 @@ +<%= form_for @user, :html => { :class => 'form-horizontal' } do |f| %> +
+<% end %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 4525e3a..4a8303f 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,8 +1,31 @@ -<%= simple_form_for @user do |f| %> - <%= f.input :nickname, :input_html => { :class => 'special' } %> +<%= form_for @user, :url => '/user', :html => { :class => 'form-horizontal' } do |f| %> + <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index a079b05..3434108 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -7,6 +7,10 @@ + + <% if current_user %> +<%= link_to 'Settings', edit_user_path %>
+ <% end %>