Last active
August 29, 2015 14:00
-
-
Save Theminijohn/004acfed2d6eced595e2 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
class RegistrationsController < Devise::RegistrationsController | |
def create | |
super # This calls Devise::RegistrationsController#create | |
if resource.save | |
# Mixpanel Create User Profile | |
mixpanel.track(@user.id, 'Created Account', { | |
'$first_name' => @user.first_name, | |
'$gametag' => @user.game_tag, | |
'$email' => @user.email, | |
'Server' => @user.server | |
}) | |
mixpanel.people.set(@user.id, { | |
'$first_name' => @user.first_name, | |
'$gametag' => @user.game_tag, | |
'$email' => @user.email, | |
'Server' => @user.server, | |
'Website' => @user.website?, | |
'Twitch' => @user.twitch_link?, | |
'Facebook' => @user.facebook_link?, | |
'Twitter' => @user.twitter_link?, | |
'Youtube' => @user.youtube_link?, | |
'Screenshots' => 0, | |
'Followers' => 0, | |
'Following' => 0, | |
'Likes' => 0, | |
'Comments' => 0 | |
}) | |
end | |
end | |
def update | |
account_update_params = devise_parameter_sanitizer.sanitize(:account_update) | |
# required for settings form to submit when password is left blank | |
if account_update_params[:password].blank? | |
account_update_params.delete("password") | |
account_update_params.delete("password_confirmation") | |
end | |
@user = User.find(current_user.id) | |
if @user.update_attributes(account_update_params) | |
set_flash_message :notice, :updated | |
sign_in @user, :bypass => true | |
# Mixpanel Update User Profile | |
mixpanel.people.set(@user.id, { | |
'$first_name' => @user.first_name, | |
'$email' => @user.email, | |
'Server' => @user.server, | |
'Website' => @user.website?, | |
'Twitch' => @user.twitch_link?, | |
'Facebook' => @user.facebook_link?, | |
'Twitter' => @user.twitter_link?, | |
'Youtube' => @user.youtube_link?, | |
}) | |
redirect_to after_update_path_for(@user) | |
else | |
render 'edit' | |
end | |
end | |
def destroy | |
# Delete Mixpanel Profile | |
mixpanel.track(@user.id, 'Deleted Account') | |
mixpanel.people.delete_user(@user.id) | |
resource.destroy | |
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) | |
yield resource if block_given? | |
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) } | |
end | |
protected | |
def after_update_path_for(resource) | |
:back | |
end | |
end | |
###### application_controller.rb | |
# def mixpanel | |
# if Rails.env.production? | |
# @mixpanel ||= Mixpanel::Tracker.new('TOKEN') | |
# else | |
# @mixpanel ||= Mixpanel::Tracker.new('TOKEN') | |
# end | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment