Guest User

Untitled

a guest
Nov 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. resources :instagram_users, except: [:new, :create, :edit]
  2. get 'set/:token', to: 'instagram_users#edit', as: 'set'
  3.  
  4. def edit
  5. @instagram_user = InstagramUser.find_by(password_reset_token: params[:token])
  6. end
  7.  
  8. def update
  9. @instagram_user = InstagramUser.find(params[:id])
  10. correct_user(@instagram_user, params[:token])
  11. if @instagram_user.update_attributes(instagram_user_params)
  12. flash[:success] = "Instagram user success!"
  13. redirect_to dashboard_path
  14. else
  15. flash[:alert] = "Something went wrong!"
  16. render 'edit'
  17. end
  18. end
  19.  
  20. private
  21.  
  22. def instagram_user_params
  23. params.require(:instagram_user).permit(:password, :password_confirmation, :backup_code, :token)
  24. end
  25.  
  26. def correct_user(ig_user, token)
  27. redirect_to root_url unless ig_user.password_reset_token == token
  28. end
  29.  
  30. edit.html.haml ('set/:token')
  31. = form_for @instagram_user, url: instagram_user_path(@instagram_user.id), html: { class: 'form-horizontal' } do |f|
  32. = render 'shared/error_messages'
  33.  
  34. = f.label :password
  35. = f.password_field :password, class: 'form-control'
  36. = f.label :password_confirmation, "Confirmation"
  37. = f.password_field :password_confirmation, class: 'form-control'
  38. = f.label :backup_code
  39. = f.text_field :backup_code, class: 'form-control'
  40.  
  41. = hidden_field_tag :token, @instagram_user.password_reset_token
  42. = f.submit "Save Changes", class: "btn btn-primary"
Add Comment
Please, Sign In to add comment