Skip to content

Commit

Permalink
Added user image to edit profile
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Apr 23, 2010
1 parent f9edf75 commit 832b183
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
8 changes: 5 additions & 3 deletions app/controllers/editor/auth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Editor::AuthController < ParagraphController #:nodoc:all

editor_for :user_edit_account, :name => 'User Edit Account', :feature => 'user_edit_account', :triggers => [ ['Edit Account','action' ]]

editor_for :edit_account, :name => 'Edit Account', :triggers => [ ['Edit Profile','action' ]]
# editor_for :edit_account, :name => 'Edit Account', :triggers => [ ['Edit Profile','action' ]]


editor_for :missing_password, :name => 'Missing Password', :triggers => [ ['Sent Email','action']], :features => ['missing_password']
Expand Down Expand Up @@ -73,7 +73,8 @@ def available_field_list
:gender => ['Gender'.t, :radio_buttons, :gender, { :options => [ ['Male'.t,'m'],['Female'.t,'f' ] ] } ],
:introduction => ['Introduction'.t, :radio_buttons, :introduction, { :options => [ ['Mr.'.t,'Mr.'],['Mrs.'.t,'Mrs.' ], ['Ms.'.t, 'Ms.'] ] } ],
:username => [ 'Username'.t,:text_field, :username ],
:salutation => [ 'Salutation'.t,:text_field, :salutation ]
:salutation => [ 'Salutation'.t,:text_field, :salutation ],
:image => [ 'Profile Image'.t,:file_upload, :domain_file_id ]
}
end

Expand Down Expand Up @@ -226,7 +227,8 @@ def available_field_list
:gender => ['Gender'.t, :radio_buttons, :gender, { :options => [ ['Male'.t,'m'],['Female'.t,'f' ] ] } ],
:introduction => ['Introduction'.t, :radio_buttons, :introduction, { :options => [ ['Mr.'.t,'Mr.'],['Mrs.'.t,'Mrs.' ], ['Ms.'.t, 'Ms.'] ] } ],
:username => [ 'Username'.t,:text_field, :username ],
:salutation => [ 'Salutation'.t,:text_field, :salutation ]
:salutation => [ 'Salutation'.t,:text_field, :salutation ],
:domain_file_id => [ 'Upload Profile Image'.t,:file_field, :domain_file_id ]
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/editor/auth_feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def user_register_feature(data)

def user_edit_account_feature(data)
webiva_custom_feature(:user_edit_account,data) do |c|
c.form_for_tag('edit',:user) { |t| data[:usr] ? data[:usr] : nil }
c.form_for_tag('edit',:user,:html => { :enctype => 'multipart/form-data' }) { |t| data[:usr] ? data[:usr] : nil }

c.expansion_tag('edit:errors') { |t| data[:failed] }
c.expansion_tag('edit:updated') { |t| data[:updated] }
Expand Down
76 changes: 39 additions & 37 deletions app/controllers/editor/auth_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,19 @@ def user_edit_account
@business = @usr.work_address || @usr.build_work_address(:address_name => 'Business Address'.t, :country => @options.country )

if @options.publication
field = @options.content_publication_user_field
model_class = @options.publication.content_model.model_class
field = @options.content_publication_user_field
model_class = @options.publication.content_model.model_class
@model = model_class.find(:first, :conditions => {field.to_sym => myself.id}) || model_class.new(field.to_sym => myself.id)
end
end

if request.post? && params[:user] && !editor? && myself.id


handle_image_upload(params[:user],:domain_file_id)
# Assign a slice of params to the user
@usr.attributes = params[:user].slice(*(@options.required_fields + @options.optional_fields + @options.always_required_fields).uniq)
unless @usr.editor?
@usr.user_class_id = @options.user_class_id if @usr.user_class_id.blank? || @options.modify_profile == 'modify'
@usr.user_class_id = @options.user_class_id if @usr.user_class_id.blank? || @options.modify_profile == 'modify'
end

# check everything is valid
Expand All @@ -225,8 +226,9 @@ def user_edit_account
end
end


all_valid = false unless @usr.errors.length == 0

# same for address
all_valid = false unless assign_entry(@address, params[:address], @options.available_address_field_list.keys, @options.address_required_fields)

Expand All @@ -243,7 +245,7 @@ def user_edit_account
@failed = true unless all_valid

if all_valid

if params[:address]
@address.save
@usr.address_id = @address.id
Expand All @@ -267,16 +269,16 @@ def user_edit_account
update_subscriptions(@usr,@options.include_subscriptions,params[:subscription])
end

@model.save if @model
@model.save if @model

if @options.access_token_id
tkn = AccessToken.find_by_id(@options.access_token_id)
@usr.add_token!(tkn) if tkn
end
if @options.access_token_id
tkn = AccessToken.find_by_id(@options.access_token_id)
@usr.add_token!(tkn) if tkn
end
# run any triggered actions
paragraph.run_triggered_actions(@usr,'action',@usr)

# send mail template if we have one
# send mail template if we have one
if @options.mail_template_id.to_i > 0 && @mail_template = MailTemplate.find_by_id(@options.mail_template_id)
vars = {}
@mail_template.deliver_to_user(@usr,vars)
Expand All @@ -289,8 +291,8 @@ def user_edit_account
return
end

flash[:notice] = 'Account Updated'.t
@updated = true
flash[:notice] = 'Account Updated'.t
@updated = true
end
end
end
Expand Down Expand Up @@ -495,7 +497,7 @@ def edit_account
@required_fields = %w(email)
@optional_fields = %w{first_name last_name gender username dob}
@adr_fields = %w(company phone fax address city state zip country)

@user = myself
@address = @user.address ? @user.address : @user.build_address(:address_name => 'Default Address'.t )
@work_address = @user.work_address ? @user.work_address : @user.build_work_address(:address_name => 'Default Work Address'.t )
Expand All @@ -513,7 +515,7 @@ def edit_account
@address.validate_registration(:home,opts.address == 'required',opts.address_type )
all_valid = false unless @address.errors.empty?
end

if opts.work_address != 'off'
@work_address.attributes = params[:work_address].slice(*@adr_fields)
@work_address.country = opts.country unless opts.country.blank?
Expand All @@ -522,9 +524,9 @@ def edit_account
end

if opts.content_publication.to_i > 0
fill_entry(@publication,@entry,@user)
all_valid = false unless @entry.valid?
fill_entry(@publication,@entry,@user)

all_valid = false unless @entry.valid?
end

@user.valid?
Expand All @@ -538,16 +540,16 @@ def edit_account
@user.address_id = @address.id
end
if opts.work_address != 'off'
@work_address.save
@user.work_address_id = @work_address.id
@work_address.save
@user.work_address_id = @work_address.id
end

@user.save

if !opts.add_tags.to_s.empty?
@user.tag_names_add(opts.add_tags)
end
if !opts.add_tags.to_s.empty?
@user.tag_names_add(opts.add_tags)
end

if opts.include_subscriptions.is_a?(Array) && opts.include_subscriptions.length > 0
update_subscriptions(@user,opts.include_subscriptions,params[:subscription])
end
Expand All @@ -556,17 +558,17 @@ def edit_account
paragraph.run_triggered_actions(@user,'action',@user)
end

paragraph_action(myself.action('/editor/auth/edit_account_profile', :identifier => @user.email))
paragraph_action(myself.action('/editor/auth/edit_account_profile', :identifier => @user.email))

if opts.success_page
nd = SiteNode.find_by_id(opts.success_page)
if nd
redirect_paragraph nd.node_path if nd
return
end
end
render_paragraph :text => 'Successfully Edited Profile'.t
return
end
end
render_paragraph :text => 'Successfully Edited Profile'.t
return
end
end

Expand All @@ -579,12 +581,12 @@ def edit_account

render_paragraph :partial => '/editor/auth/edit_account',
:locals => { :user => @user,
:opts => opts.to_h.merge(:vertical => opts.form_display == 'vertical'),
:fields => @optional_fields,
:address => @address,
:work_address => @work_address,
:subscriptions => @subscriptions,
:reset_password => flash['reset_password'] }
:opts => opts.to_h.merge(:vertical => opts.form_display == 'vertical'),
:fields => @optional_fields,
:address => @address,
:work_address => @work_address,
:subscriptions => @subscriptions,
:reset_password => flash['reset_password'] }
end

# update users subscriptions
Expand Down

0 comments on commit 832b183

Please sign in to comment.