Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- resources :instagram_users, except: [:new, :create, :edit]
- get 'set/:token', to: 'instagram_users#edit', as: 'set'
- def edit
- @instagram_user = InstagramUser.find_by(password_reset_token: params[:token])
- end
- def update
- @instagram_user = InstagramUser.find(params[:id])
- correct_user(@instagram_user, params[:token])
- if @instagram_user.update_attributes(instagram_user_params)
- flash[:success] = "Instagram user success!"
- redirect_to dashboard_path
- else
- flash[:alert] = "Something went wrong!"
- render 'edit'
- end
- end
- private
- def instagram_user_params
- params.require(:instagram_user).permit(:password, :password_confirmation, :backup_code, :token)
- end
- def correct_user(ig_user, token)
- redirect_to root_url unless ig_user.password_reset_token == token
- end
- edit.html.haml ('set/:token')
- = form_for @instagram_user, url: instagram_user_path(@instagram_user.id), html: { class: 'form-horizontal' } do |f|
- = render 'shared/error_messages'
- = f.label :password
- = f.password_field :password, class: 'form-control'
- = f.label :password_confirmation, "Confirmation"
- = f.password_field :password_confirmation, class: 'form-control'
- = f.label :backup_code
- = f.text_field :backup_code, class: 'form-control'
- = hidden_field_tag :token, @instagram_user.password_reset_token
- = f.submit "Save Changes", class: "btn btn-primary"
Add Comment
Please, Sign In to add comment