Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## user.rb model
- class User < ActiveRecord::Base
- acts_as_authentic
- def deliver_password_reset_instructions!
- reset_perishable_token!
- Notifier.deliver_password_reset_instructions(self)
- end
- attr_accessor :givenName, :givenName_form
- def givenName
- LdapUser.find(self.login).givenName
- end
- before_create :try_ldap_create
- before_update :try_ldap_update
- def try_ldap_update
- ldap = LdapUser.find(self.login)
- ldap.userPassword = ActiveLdap::UserPassword.ssha(self.password) unless self.pass
- ldap.givenName = self.givenName_form
- if ldap.save
- return true
- else
- errors.add(:ldap, "couldn't update")
- return false
- end
- end
- ## user controller
- def edit
- @user = @current_user
- @user.givenName_form = @user.givenName
- end
- def update
- @user = @current_user # makes our views "cleaner" and more consistent
- if @user.update_attributes(params[:user])
- flash[:notice] = "Account updated!"
- redirect_to account_url
- else
- flash[:error] = "Something went wrong!"
- render :action => :edit
- end
- end
- ## form
- <h1>Edit My Account</h1>
- <% form_for @user, :url => account_path do |f| %>
- <%= f.error_messages %>
- <%= f.label :email %><br />
- <%= f.text_field :email %><br />
- <br />
- <%= f.label :password, f.object.new_record? ? nil : "Change password" %><br />
- <%= f.password_field :password %><br />
- <br />
- <%= f.label :password_confirmation %><br />
- <%= f.password_field :password_confirmation %><br />
- <br />
- <%= f.label :givenName_form %><br />
- <%= f.text_field :givenName_form %><br />
- <%= f.submit "Update" %>
- <% end %>
- <br /><%= link_to "My Profile", account_path %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement