Send a registration even for github created users. Alias their new username to their old mixpanel ID passed in the OAuth state parameter.

This commit is contained in:
yackob03 2013-10-10 17:32:32 -04:00
parent b9a5060882
commit 32b28df2d2
4 changed files with 40 additions and 3 deletions

View file

@ -7,7 +7,7 @@ from flask.ext.login import login_user, UserMixin, login_required, logout_user
from flask.ext.principal import identity_changed, Identity, AnonymousIdentity
from data import model
from app import app, login_manager
from app import app, login_manager, mixpanel
logger = logging.getLogger(__name__)
@ -143,6 +143,14 @@ def github_oauth_callback():
return render_template('githuberror.html', error_message=ex.message)
if common_login(to_login):
# Success
mixpanel.track(to_login.username, 'register', {'service': 'github'})
state = request.args.get('state', None)
if state:
logger.debug('Aliasing with state: %s' % state)
mixpanel.alias(to_login.username, state)
return redirect(url_for('index'))
# TODO something bad happened, we need to tell the user somehow

View file

@ -141,6 +141,11 @@ function LandingCtrl($scope, $timeout, Restangular, UserService, KeyService) {
$scope.user = currentUser;
}, true);
angulartics.waitForVendorApi(mixpanel, 500, function(loadedMixpanel) {
var mixpanelId = loadedMixpanel.get_distinct_id();
$scope.github_state_clause = '&state=' + mixpanelId;
});
$scope.githubClientId = KeyService.githubClientId;
$scope.awaitingConfirmation = false;

View file

@ -47,7 +47,7 @@
<i class="icon-circle"></i>
<span class="inner-text">OR</span>
</span>
<a href="https://github.com/login/oauth/authorize?client_id={{ githubClientId }}&scope=user:email" class="btn btn-primary btn-block"><i class="icon-github icon-large"></i> Sign In with GitHub</a>
<a href="https://github.com/login/oauth/authorize?client_id={{ githubClientId }}&scope=user:email{{ github_state_clause }}" class="btn btn-primary btn-block"><i class="icon-github icon-large"></i> Sign In with GitHub</a>
<p class="help-block">No credit card required.</p>
</div>
</form>

View file

@ -7,7 +7,17 @@
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">
<link rel="stylesheet" href="static/css/signin.css">
<!-- start Mixpanel --><script type="text/javascript">
var isProd = document.location.hostname === 'quay.io';
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===e.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f);b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==
typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.track_charge people.clear_charges people.delete_user".split(" ");for(g=0;g<i.length;g++)f(c,i[g]);
b._i.push([a,e,d])};b.__SV=1.2}})(document,window.mixpanel||[]);
mixpanel.init(isProd ? "50ff2b2569faa3a51c8f5724922ffb7e" : "38014a0f27e7bdc3ff8cc7cc29c869f9", { track_pageview : false });</script><!-- end Mixpanel -->
</head>
<body>
<div class="container">
<form method="post" class="form-signin">
@ -20,7 +30,7 @@
<span class="inner-text">OR</span>
</span>
<a href="https://github.com/login/oauth/authorize?client_id={{ github_client_id }}&scope=user:email" class="btn btn-primary btn-lg btn-block"><i class="icon-github icon-large"></i> Sign In with GitHub</a>
<a id='github-signin-link' href="https://github.com/login/oauth/authorize?client_id={{ github_client_id }}&scope=user:email" class="btn btn-primary btn-lg btn-block"><i class="icon-github icon-large"></i> Sign In with GitHub</a>
</form>
{% if invalid_credentials %}
@ -31,5 +41,19 @@
<div class="alert alert-danger">You must verify your email address before you can sign in.</div>
{% endif %}
</div>
<script type="text/javascript">
function appendMixpanelId() {
if (mixpanel.get_distinct_id !== undefined) {
var signinLink = document.getElementById("github-signin-link");
signinLink.href += ("&state=" + mixpanel.get_distinct_id());
} else {
// Mixpanel not yet loaded, try again later
window.setTimeout(appendMixpanelId, 200);
}
};
appendMixpanelId();
</script>
</body>
</html>