def register_social_login( request, data=None, resend_confirmation_url_name='account_resend_confirmation', template='account/register_social_login.html', renderer=_r): """For when a user is already associated with this email and has a usable password set """ from htk.apps.accounts.forms.auth import SocialRegistrationAuthenticationForm if data is None: data = wrap_data(request) email = request.session.get(SOCIAL_REGISTRATION_SETTING_EMAIL) data['email'] = email data.update(csrf(request)) success = False if request.method == 'POST': auth_form = SocialRegistrationAuthenticationForm(email, request.POST) if auth_form.is_valid(): user = auth_form.get_user() login_authenticated_user(request, user) success = True else: for error in auth_form.non_field_errors(): data['errors'].append(error) auth_user = auth_form.get_user() if auth_user and not auth_user.is_active: msg = get_resend_confirmation_help_message( resend_confirmation_url_name, email=auth_user.email) data['errors'].append(msg) else: auth_form = SocialRegistrationAuthenticationForm(email) if success: response = redirect_to_social_auth_complete(request) else: data['auth_form'] = auth_form response = renderer(request, template, data=data) return response
def register_social_login( request, data=None, resend_confirmation_url_name='account_resend_confirmation', template='account/register_social_login.html', renderer=_r ): """For when a user is already associated with this email and has a usable password set """ from htk.apps.accounts.forms.auth import SocialRegistrationAuthenticationForm if data is None: data = wrap_data(request) email = request.session.get(SOCIAL_REGISTRATION_SETTING_EMAIL) data['email'] = email data.update(csrf(request)) success = False if request.method == 'POST': auth_form = SocialRegistrationAuthenticationForm(email, request.POST) if auth_form.is_valid(): user = auth_form.get_user() login_authenticated_user(request, user) success = True else: for error in auth_form.non_field_errors(): data['errors'].append(error) auth_user = auth_form.get_user() if auth_user and not auth_user.is_active: msg = get_resend_confirmation_help_message(resend_confirmation_url_name, email=auth_user.email) data['errors'].append(msg) else: auth_form = SocialRegistrationAuthenticationForm(email) if success: response = redirect_to_social_auth_complete(request) else: data['auth_form'] = auth_form response = renderer(request, template, data=data) return response
def register_social_email(request, data=None, template='account/register_social_email.html', renderer=_r): from htk.apps.accounts.forms.auth import SocialRegistrationEmailForm if data is None: data = wrap_data(request) email = None success = False if request.method == 'POST': email_form = SocialRegistrationEmailForm(request.POST) if email_form.is_valid(): email = email_form.save(request) success = True else: for error in email_form.non_field_errors(): data['errors'].append(error) else: email_form = SocialRegistrationEmailForm(None) if success: user = get_user_by_email(email) if user: # a user is already associated with this email if user.has_usable_password(): # user should log into the existing account with a password url_name = htk_setting( 'HTK_ACCOUNTS_REGISTER_SOCIAL_LOGIN_URL_NAME') else: # no password was set, so user must log in with another social auth account url_name = htk_setting( 'HTK_ACCOUNTS_REGISTER_SOCIAL_ALREADY_LINKED_URL_NAME') response = redirect(url_name) else: response = redirect_to_social_auth_complete(request) else: data['email_form'] = email_form response = renderer(request, template, data=data) return response
def register_social_email( request, data=None, template='account/register_social_email.html', renderer=_r ): from htk.apps.accounts.forms.auth import SocialRegistrationEmailForm if data is None: data = wrap_data(request) email = None success = False if request.method == 'POST': email_form = SocialRegistrationEmailForm(request.POST) if email_form.is_valid(): email = email_form.save(request) success = True else: for error in email_form.non_field_errors(): data['errors'].append(error) else: email_form = SocialRegistrationEmailForm(None) if success: user = get_user_by_email(email) if user: # a user is already associated with this email if user.has_usable_password(): # user should log into the existing account with a password url_name = htk_setting('HTK_ACCOUNTS_REGISTER_SOCIAL_LOGIN_URL_NAME') else: # no password was set, so user must log in with another social auth account url_name = htk_setting('HTK_ACCOUNTS_REGISTER_SOCIAL_ALREADY_LINKED_URL_NAME') response = redirect(url_name) else: response = redirect_to_social_auth_complete(request) else: data['email_form'] = email_form response = _r(template, data) return response