Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. ## user.rb model
  2. class User < ActiveRecord::Base
  3. acts_as_authentic
  4.  
  5. def deliver_password_reset_instructions!
  6. reset_perishable_token!
  7. Notifier.deliver_password_reset_instructions(self)
  8. end
  9.  
  10. attr_accessor :givenName, :givenName_form
  11.  
  12. def givenName
  13. LdapUser.find(self.login).givenName
  14. end
  15.  
  16. before_create :try_ldap_create
  17. before_update :try_ldap_update
  18.  
  19. def try_ldap_update
  20. ldap = LdapUser.find(self.login)
  21.  
  22. ldap.userPassword = ActiveLdap::UserPassword.ssha(self.password) unless self.pass
  23. ldap.givenName = self.givenName_form
  24.  
  25. if ldap.save
  26. return true
  27. else
  28. errors.add(:ldap, "couldn't update")
  29. return false
  30. end
  31.  
  32. end
  33.  
  34. ## user controller
  35. def edit
  36. @user = @current_user
  37. @user.givenName_form = @user.givenName
  38. end
  39.  
  40. def update
  41. @user = @current_user # makes our views "cleaner" and more consistent
  42. if @user.update_attributes(params[:user])
  43. flash[:notice] = "Account updated!"
  44. redirect_to account_url
  45. else
  46. flash[:error] = "Something went wrong!"
  47. render :action => :edit
  48. end
  49. end
  50.  
  51. ## form
  52. <h1>Edit My Account</h1>
  53.  
  54. <% form_for @user, :url => account_path do |f| %>
  55. <%= f.error_messages %>
  56. <%= f.label :email %><br />
  57. <%= f.text_field :email %><br />
  58. <br />
  59. <%= f.label :password, f.object.new_record? ? nil : "Change password" %><br />
  60. <%= f.password_field :password %><br />
  61. <br />
  62. <%= f.label :password_confirmation %><br />
  63. <%= f.password_field :password_confirmation %><br />
  64. <br />
  65. <%= f.label :givenName_form %><br />
  66. <%= f.text_field :givenName_form %><br />
  67. <%= f.submit "Update" %>
  68. <% end %>
  69.  
  70. <br /><%= link_to "My Profile", account_path %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement