def signin_complete(request): is_redirect = False next = clean_next(request.GET.get('next')) form1 = OpenidRegisterForm() form2 = OpenidVerifyForm() if request.POST: if not request.session.get('webauth_pui', None): return HttpResponseRedirect('/webauth/signin/') just_completed = False if 'bnewaccount' in request.POST.keys(): form1 = OpenidRegisterForm(request.POST) if form1.is_valid(): next = clean_next(form1.cleaned_data.get('next')) is_redirect = True tmp_pwd = User.objects.make_random_password() user_ = User.objects.create_user(form1.cleaned_data['username'], form1.cleaned_data['email'], tmp_pwd) # make association with openid uassoc = WebauthUser(userLiveID=request.session.get('webauth_pui'), user_id=user_.id) uassoc.save() # login user_.backend = "django.contrib.auth.backends.ModelBackend" login(request, user_) request.session['auth_type'] = 'webauth' elif 'bverify' in request.POST.keys(): form2 = OpenidVerifyForm(request.POST) if form2.is_valid(): is_redirect = True next = clean_next(form2.cleaned_data.get('next')) user_ = form2.get_user() uassoc = WebauthUser(userLiveID=request.session.get('webauth_pui'), user_id=user_.id) uassoc.save() login(request, user_) request.session['auth_type'] = 'webauth' # redirect, can redirect only if forms are valid. if is_redirect: return HttpResponseRedirect(next) return render_to_response('webauth/signin_complete.html', { 'form1': form1, 'form2': form2, }, context_instance=RequestContext(request))
def register(request): """ register an openid. If user is already a member he can associate its openid with its account. A new account could also be created and automaticaly associated to the openid. url : /complete/ template : authopenid/complete.html """ is_redirect = False next = clean_next(request.GET.get("next")) openid_ = request.session.get("openid", None) if not openid_: return HttpResponseRedirect(reverse("user_signin") + next) nickname = openid_.sreg.get("nickname", "") email = openid_.sreg.get("email", "") form1 = OpenidRegisterForm(initial={"next": next, "username": nickname, "email": email}) form2 = OpenidVerifyForm(initial={"next": next, "username": nickname}) user_ = None if request.POST: just_completed = False if "bnewaccount" in request.POST.keys(): form1 = OpenidRegisterForm(request.POST) if form1.is_valid(): next = clean_next(form1.cleaned_data.get("next")) is_redirect = True tmp_pwd = User.objects.make_random_password() user_ = User.objects.create_user(form1.cleaned_data["username"], form1.cleaned_data["email"], tmp_pwd) # make association with openid uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() # login user_.backend = "django.contrib.auth.backends.ModelBackend" login(request, user_) elif "bverify" in request.POST.keys(): form2 = OpenidVerifyForm(request.POST) if form2.is_valid(): is_redirect = True next = clean_next(form2.cleaned_data.get("next")) user_ = form2.get_user() uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() login(request, user_) # check if we need to post a question that was added anonymously # this needs to be a function call becase this is also done # if user just logged in and did not need to create the new account if user_ != None and settings.EMAIL_VALIDATION == "on": send_new_email_key(user_, nomessage=True) output = validation_email_sent(request) set_email_validation_message(user_) # message set after generating view return output elif user_.is_authenticated(): return HttpResponseRedirect("/") else: raise server_error("") openid_str = str(openid_) bits = openid_str.split("/") base_url = bits[2] # assume this is base url url_bits = base_url.split(".") provider_name = url_bits[-2].lower() providers = { "yahoo": '<font color="purple">Yahoo!</font>', "flickr": '<font color="#0063dc">flick</font><font color="#ff0084">r</font>™', "google": "Google™", "aol": '<font color="#31658e">AOL</font>', } if provider_name not in providers: provider_logo = provider_name else: provider_logo = providers[provider_name] return render( "authopenid/complete.html", {"form1": form1, "form2": form2, "provider": provider_logo, "nickname": nickname, "email": email}, context_instance=RequestContext(request), )
def register(request): """ register an openid. If user is already a member he can associate its openid with its account. A new account could also be created and automaticaly associated to the openid. url : /complete/ template : authopenid/complete.html """ logging.debug('') openid_ = request.session.get('openid', None) next = get_next_url(request) if not openid_: logging.debug('oops, no openid in session --> go back to signin') return HttpResponseRedirect(reverse('user_signin') + '?next=%s' % next) nickname = openid_.sreg.get('nickname', '') email = openid_.sreg.get('email', '') form1 = OpenidRegisterForm(initial={ 'next': next, 'username': nickname, 'email': email, }) form2 = OpenidVerifyForm(initial={ 'next': next, 'username': nickname, }) email_feeds_form = SimpleEmailSubscribeForm() user_ = None is_redirect = False logging.debug('request method is %s' % request.method) if request.method == 'POST': if 'bnewaccount' in request.POST.keys(): logging.debug('trying to create new account associated with openid') form1 = OpenidRegisterForm(request.POST) email_feeds_form = SimpleEmailSubscribeForm(request.POST) if not form1.is_valid(): logging.debug('OpenidRegisterForm is INVALID') elif not email_feeds_form.is_valid(): logging.debug('SimpleEmailSubscribeForm is INVALID') else: logging.debug('OpenidRegisterForm and SimpleEmailSubscribeForm are valid') next = form1.cleaned_data['next'] is_redirect = True logging.debug('creatng new django user %s ...' % form1.cleaned_data['username']) tmp_pwd = User.objects.make_random_password() user_ = User.objects.create_user(form1.cleaned_data['username'], form1.cleaned_data['email'], tmp_pwd) user_.set_unusable_password() # make association with openid logging.debug('creating new openid user association %s <--> %s' \ % (user_.username, str(openid_))) uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() # login user_.backend = "django.contrib.auth.backends.ModelBackend" logging.debug('logging the user in') login(request, user_) logging.debug('saving email feed settings') email_feeds_form.save(user_) elif 'bverify' in request.POST.keys(): logging.debug('processing OpenidVerify form') form2 = OpenidVerifyForm(request.POST) if form2.is_valid(): logging.debug('form is valid') is_redirect = True next = form2.cleaned_data['next'] user_ = form2.get_user() logging.debug('creating new openid user association %s <--> %s' \ % (user_.username, str(openid_))) uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() logging.debug('logging the user in') login(request, user_) #check if we need to post a question that was added anonymously #this needs to be a function call becase this is also done #if user just logged in and did not need to create the new account if user_ != None: if settings.EMAIL_VALIDATION == 'on': logging.debug('sending email validation') send_new_email_key(user_,nomessage=True) output = validation_email_sent(request) set_email_validation_message(user_) #message set after generating view return output if user_.is_authenticated(): logging.debug('success, send user to main page') return HttpResponseRedirect(reverse('index')) else: logging.debug('have really strange error') raise Exception('openid login failed')#should not ever get here openid_str = str(openid_) bits = openid_str.split('/') base_url = bits[2] #assume this is base url url_bits = base_url.split('.') provider_name = url_bits[-2].lower() providers = {'yahoo':'<font color="purple">Yahoo!</font>', 'flickr':'<font color="#0063dc">flick</font><font color="#ff0084">r</font>™', 'google':'Google™', 'aol':'<font color="#31658e">AOL</font>', 'myopenid':'MyOpenID', } if provider_name not in providers: provider_logo = provider_name logging.error('openid provider named "%s" has no pretty customized logo' % provider_name) else: provider_logo = providers[provider_name] logging.debug('printing authopenid/complete.html output') return render_to_response('authopenid/complete.html', { 'form1': form1, 'form2': form2, 'email_feeds_form': email_feeds_form, 'provider':mark_safe(provider_logo), 'username': nickname, 'email': email, 'login_type':'openid', 'gravatar_faq_url':reverse('faq') + '#gravatar', }, context_instance=RequestContext(request))
def register(request): """ register an openid. If user is already a member he can associate its openid with its account. A new account could also be created and automaticaly associated to the openid. url : /complete/ template : authopenid/complete.html """ is_redirect = False next = clean_next(request.GET.get('next')) openid_ = request.session.get('openid', None) if not openid_: return HttpResponseRedirect(reverse('user_signin') + next) nickname = openid_.sreg.get('nickname', '') email = openid_.sreg.get('email', '') form1 = OpenidRegisterForm(initial={ 'next': next, 'username': nickname, 'email': email, }) form2 = OpenidVerifyForm(initial={ 'next': next, 'username': nickname, }) if request.POST: just_completed = False if 'bnewaccount' in request.POST.keys(): form1 = OpenidRegisterForm(request.POST) if form1.is_valid(): next = clean_next(form1.cleaned_data.get('next')) is_redirect = True tmp_pwd = User.objects.make_random_password() user_ = User.objects.create_user(form1.cleaned_data['username'], form1.cleaned_data['email'], tmp_pwd) # make association with openid uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() # login user_.backend = "django.contrib.auth.backends.ModelBackend" login(request, user_) elif 'bverify' in request.POST.keys(): form2 = OpenidVerifyForm(request.POST) if form2.is_valid(): is_redirect = True next = clean_next(form2.cleaned_data.get('next')) user_ = form2.get_user() uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() login(request, user_) # redirect, can redirect only if forms are valid. if is_redirect: return HttpResponseRedirect(next) return render('authopenid/complete.html', { 'form1': form1, 'form2': form2, 'nickname': nickname, 'email': email }, context_instance=RequestContext(request))
def register(request): """ register an openid. If user is already a member he can associate its openid with its account. A new account could also be created and automaticaly associated to the openid. url : /complete/ template : authopenid/complete.html """ openid_ = request.session.get('openid', None) next = get_next_url(request) if not openid_: return HttpResponseRedirect(reverse('user_signin') + '?next=%s' % next) nickname = openid_.sreg.get('nickname', '') email = openid_.sreg.get('email', '') form1 = OpenidRegisterForm(initial={ 'next': next, 'username': nickname, 'email': email, }) form2 = OpenidVerifyForm(initial={ 'next': next, 'username': nickname, }) email_feeds_form = EditUserEmailFeedsForm() user_ = None is_redirect = False if request.POST: if 'bnewaccount' in request.POST.keys(): form1 = OpenidRegisterForm(request.POST) email_feeds_form = EditUserEmailFeedsForm(request.POST) if form1.is_valid() and email_feeds_form.is_valid(): next = form1.cleaned_data['next'] is_redirect = True tmp_pwd = User.objects.make_random_password() user_ = User.objects.create_user(form1.cleaned_data['username'], form1.cleaned_data['email'], tmp_pwd) user_.set_unusable_password() # make association with openid uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() # login user_.backend = "django.contrib.auth.backends.ModelBackend" login(request, user_) email_feeds_form.save(user_) elif 'bverify' in request.POST.keys(): form2 = OpenidVerifyForm(request.POST) if form2.is_valid(): is_redirect = True next = form2.cleaned_data['next'] user_ = form2.get_user() uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() login(request, user_) #check if we need to post a question that was added anonymously #this needs to be a function call becase this is also done #if user just logged in and did not need to create the new account if user_ != None: if settings.EMAIL_VALIDATION == 'on': send_new_email_key(user_,nomessage=True) output = validation_email_sent(request) set_email_validation_message(user_) #message set after generating view return output if user_.is_authenticated(): return HttpResponseRedirect(reverse('index')) else: raise Exception('openid login failed')#should not ever get here openid_str = str(openid_) bits = openid_str.split('/') base_url = bits[2] #assume this is base url url_bits = base_url.split('.') provider_name = url_bits[-2].lower() providers = {'yahoo':'<font color="purple">Yahoo!</font>', 'flickr':'<font color="#0063dc">flick</font><font color="#ff0084">r</font>™', 'google':'Google™', 'aol':'<font color="#31658e">AOL</font>', 'myopenid':'MyOpenID', } if provider_name not in providers: provider_logo = provider_name else: provider_logo = providers[provider_name] return render('authopenid/complete.html', { 'form1': form1, 'form2': form2, 'email_feeds_form': email_feeds_form, 'provider':mark_safe(provider_logo), 'username': nickname, 'email': email, 'login_type':'openid', 'gravatar_faq_url':reverse('faq') + '#gravatar', }, context_instance=RequestContext(request))
def register(request): """ register an openid. If user is already a member he can associate its openid with its account. A new account could also be created and automaticaly associated to the openid. url : /complete/ template : authopenid/complete.html """ is_redirect = False next = clean_next(request.GET.get('next')) openid_ = request.session.get('openid', None) if not openid_: return HttpResponseRedirect(reverse('user_signin') + next) nickname = openid_.sreg.get('nickname', '') email = openid_.sreg.get('email', '') form1 = OpenidRegisterForm(initial={ 'next': next, 'username': nickname, 'email': email, }) form2 = OpenidVerifyForm(initial={ 'next': next, 'username': nickname, }) user_ = None if request.POST: just_completed = False if 'bnewaccount' in request.POST.keys(): form1 = OpenidRegisterForm(request.POST) if form1.is_valid(): next = clean_next(form1.cleaned_data.get('next')) is_redirect = True tmp_pwd = User.objects.make_random_password() user_ = User.objects.create_user( form1.cleaned_data['username'], form1.cleaned_data['email'], tmp_pwd) # make association with openid uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() # login user_.backend = "django.contrib.auth.backends.ModelBackend" login(request, user_) elif 'bverify' in request.POST.keys(): form2 = OpenidVerifyForm(request.POST) if form2.is_valid(): is_redirect = True next = clean_next(form2.cleaned_data.get('next')) user_ = form2.get_user() uassoc = UserAssociation(openid_url=str(openid_), user_id=user_.id) uassoc.save() login(request, user_) #check if we need to post a question that was added anonymously #this needs to be a function call becase this is also done #if user just logged in and did not need to create the new account if user_ != None and settings.EMAIL_VALIDATION == 'on': send_new_email_key(user_, nomessage=True) output = validation_email_sent(request) set_email_validation_message( user_) #message set after generating view return output elif user_.is_authenticated(): return HttpResponseRedirect('/') else: raise server_error('') openid_str = str(openid_) bits = openid_str.split('/') base_url = bits[2] #assume this is base url url_bits = base_url.split('.') provider_name = url_bits[-2].lower() providers = { 'yahoo': '<font color="purple">Yahoo!</font>', 'flickr': '<font color="#0063dc">flick</font><font color="#ff0084">r</font>™', 'google': 'Google™', 'aol': '<font color="#31658e">AOL</font>', } if provider_name not in providers: provider_logo = provider_name else: provider_logo = providers[provider_name] return render('authopenid/complete.html', { 'form1': form1, 'form2': form2, 'provider': provider_logo, 'nickname': nickname, 'email': email }, context_instance=RequestContext(request))