Created
March 8, 2009 17:10
-
-
Save phuesler/75830 to your computer and use it in GitHub Desktop.
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
def save_profile | |
unless params[:user].blank? | |
if params[:user][:uploaded_picture].blank? | |
params[:user].delete(:uploaded_picture) | |
end | |
end | |
u = current_user | |
err_msg = nil | |
begin | |
u.update_attributes(params[:user]) | |
rescue Magick::ImageMagickError | |
err_msg = 'Das Bild konnte nicht hochgeladen werden' | |
rescue | |
err_msg = 'Die Daten konnten nicht gespeichert werden' | |
end | |
u.sex = params[:sex] | |
u.street = params[:street] | |
u.postal_code = params[:postal_code] | |
u.city_name = params[:city_name] | |
u.university_id = params[:university_id] | |
u.country_id = params[:country] | |
u.field_of_study_id = params[:field_of_study_id].to_i | |
u.semester = params[:semester] | |
u.age_group = params[:age_group] | |
u.soc_studivz = params[:soc_studivz] | |
u.soc_studivz_num_contacts = params[:soc_studivz_num_contacts] | |
u.soc_xing = params[:soc_xing] | |
u.soc_xing_num_contacts = params[:soc_xing_num_contacts] | |
u.soc_skype = params[:soc_skype] | |
u.soc_blog = params[:soc_blog] | |
u.soc_other = params[:soc_other] | |
u.soc_other_type = params[:soc_other_type] | |
u.soc_other_num_contacts = params[:soc_other_num_contacts] | |
u.mobile_phone = params[:mobile_phone] | |
u.martial_status = params[:martial_status] | |
u.clubs = params[:clubs] | |
u.interested_in = params[:interested_in] | |
u.why_smaboo = params[:why_smaboo] | |
u.bank_account = params[:bank_account] | |
u.bank_name = params[:bank_name] | |
u.bank_account_holder = params[:bank_account_holder] | |
u.bank_code = params[:bank_code] | |
u.bank_iban = params[:bank_iban] | |
u.bank_swift_bic = params[:bank_swift_bic] | |
[:notebook_brand_id, :notebook_tag_type_id].each{|v| params[v] = params[:user][v]} | |
User.required_fields_in_profile.each do |f| | |
if !err_msg.nil? || params[f].blank? | |
@current_user = u | |
@user = @current_user | |
@university_id = params[:university_id].to_i | |
@city_id = params[:city_id].to_i | |
@region_id = params[:region_id].to_i | |
@country_id = params[:country_id].to_i | |
@is_agent = @current_user.is_agent? | |
@is_promoter = @current_user.is_promoter? | |
@required_fields = User.required_fields_in_profile | |
if err_msg.nil? | |
flash[:error] = 'Bitte fülle alle Pflichtfelder aus!' # + f.to_s | |
else | |
flash[:error] = err_msg | |
end | |
render :action => "profile" | |
return | |
end | |
end | |
if(params[:email_new] != params[:email_new_conf]) | |
flash[:error] = 'Bitte bestätige deine Email.' | |
redirect_to :action => 'profile' | |
return | |
end | |
unless params[:email_new].blank? | |
if(!params[:email_new].valid_email?) | |
flash[:error] = 'Bitte gib eine gültige Emailadresse ein.' | |
redirect_to :action => 'profile' | |
return | |
end | |
u.email = params[:email_new] | |
end | |
has_blank_pwd = false | |
has_non_blank_pwd = false | |
[:pwd_old, :pwd_new, :pwd_new_conf].each do |t| | |
if params[t].blank? | |
has_blank_pwd = true | |
else | |
has_non_blank_pwd = true | |
end | |
end | |
if has_blank_pwd && has_non_blank_pwd | |
flash[:error] = 'Um das Passwort zu ändern, müssen alle Passwortfelder ausgefüllt werden' | |
redirect_to :action => 'profile' | |
return | |
end | |
if has_non_blank_pwd | |
lo = u.login | |
my_hashed = Login.encrypted_password(params[:pwd_old]) | |
if lo.hashed_password == my_hashed | |
if (params[:pwd_new] == params[:pwd_new_conf]) | |
lo.password = params[:pwd_new] | |
unless lo.save | |
flash[:error] = "Das Passwort konnte nicht gespeichert werden" | |
redirect_to :action => 'profile' | |
return | |
end | |
else | |
flash[:error] = "Die Passwörter stimmen nicht überein" | |
redirect_to :action => 'profile' | |
return | |
end | |
else | |
flash[:error] = "Das eingegebene (alte) Passwort ist falsch" | |
redirect_to :action => 'profile' | |
return | |
end | |
end | |
u.save! | |
flash[:notice] = 'Deine Änderungen wurden gespeichert.' | |
redirect_to(:action => "profile") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment