Account settings
This commit is contained in:
parent
26b1afff08
commit
4a6186f523
@ -33,8 +33,11 @@ class SessionsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def store_sensitive_user_data_in_session
|
def store_sensitive_user_data_in_session
|
||||||
session[:provider] = @user.provider
|
session[:new_user] = {
|
||||||
session[:uid] = @user.uid
|
:provider => @user.provider,
|
||||||
|
:uid => @user.uid,
|
||||||
|
:avatar_url => @user.avatar_url
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
PER_PAGE = 20
|
PER_PAGE = 20
|
||||||
|
|
||||||
|
before_filter :ensure_authenticated!, :only => [:edit, :update]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user = User.find_by_nickname(params[:nickname])
|
@user = User.find_by_nickname(params[:nickname])
|
||||||
collection = @user.asciicasts.
|
collection = @user.asciicasts.
|
||||||
@ -23,15 +25,25 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def load_sensitive_user_data_from_session
|
def load_sensitive_user_data_from_session
|
||||||
@user.provider = session[:provider]
|
@user.provider = session[:new_user][:provider]
|
||||||
@user.uid = session[:uid]
|
@user.uid = session[:new_user][:uid]
|
||||||
|
@user.avatar_url = session[:new_user][:avatar_url]
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_sensitive_session_user_data
|
def clear_sensitive_session_user_data
|
||||||
session[:provider] = nil
|
session.delete(:new_user)
|
||||||
session[:uid] = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,6 +12,8 @@ class User < ActiveRecord::Base
|
|||||||
has_many :asciicasts, :dependent => :destroy
|
has_many :asciicasts, :dependent => :destroy
|
||||||
has_many :comments, :dependent => :destroy
|
has_many :comments, :dependent => :destroy
|
||||||
|
|
||||||
|
attr_accessible :nickname, :email, :name
|
||||||
|
|
||||||
def self.create_with_omniauth(auth)
|
def self.create_with_omniauth(auth)
|
||||||
user = new
|
user = new
|
||||||
user.provider = auth["provider"]
|
user.provider = auth["provider"]
|
||||||
|
31
app/views/users/edit.html.erb
Normal file
31
app/views/users/edit.html.erb
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<%= form_for @user, :html => { :class => 'form-horizontal' } do |f| %>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Account settings</legend>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label :nickname, :class => 'control-label' %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.text_field :nickname, :class => 'text_field' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label :name, 'Real name', :class => 'control-label' %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.text_field :name, :class => 'text_field' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label :email, :class => 'control-label' %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.text_field :email, :class => 'text_field' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<%= f.submit 'Save', :class => 'btn btn-primary' %>
|
||||||
|
<%= link_to 'Cancel', profile_path(@user), :class => 'btn' %>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<% end %>
|
@ -1,8 +1,31 @@
|
|||||||
<%= simple_form_for @user do |f| %>
|
<%= form_for @user, :url => '/user', :html => { :class => 'form-horizontal' } do |f| %>
|
||||||
<%= f.input :nickname, :input_html => { :class => 'special' } %>
|
<fieldset>
|
||||||
|
<legend>Your new account</legend>
|
||||||
|
|
||||||
<%= f.input :name, :as => :hidden %>
|
<div class="control-group <%= 'error' if @user.errors[:nickname].present? %>">
|
||||||
<%= f.input :avatar_url, :as => :hidden %>
|
<%= f.label :nickname, :class => 'control-label' %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.text_field :nickname, :class => 'text_field' %>
|
||||||
|
<span class="help-inline"><%= @user.errors[:nickname].first %></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<%= f.button :submit %>
|
<div class="control-group">
|
||||||
|
<%= f.label :name, 'Real name', :class => 'control-label' %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.text_field :name, :class => 'text_field' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label :email, :class => 'control-label' %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.text_field :email, :class => 'text_field' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<%= f.submit 'Create', :class => 'btn btn-primary' %>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
<p class="meta">
|
<p class="meta">
|
||||||
<%= @user.asciicasts.count %> asciicasts
|
<%= @user.asciicasts.count %> asciicasts
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<% if current_user %>
|
||||||
|
<p><%= link_to 'Settings', edit_user_path %></p>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="asciicasts">
|
<ul class="asciicasts">
|
||||||
|
@ -16,7 +16,7 @@ AsciiIo::Application.routes.draw do
|
|||||||
|
|
||||||
match "/connect/:user_token" => "user_tokens#create"
|
match "/connect/:user_token" => "user_tokens#create"
|
||||||
|
|
||||||
resource :users, :only => [:create]
|
resource :user, :only => [:create, :edit, :update]
|
||||||
|
|
||||||
namespace :api do
|
namespace :api do
|
||||||
resources :comments
|
resources :comments
|
||||||
|
Loading…
Reference in New Issue
Block a user