def check_email(request, details, user=None, *args, **kwargs): """Ask the user to enter the email if we don't have one yet The pipeline process was cut prior to this custom pipeline function, and will resume to this same function after completing """ response = None if user is None: social_email = details.get('email') collected_email = request.session.get(SOCIAL_REGISTRATION_SETTING_EMAIL) if social_email: # email available from social auth user = get_user_by_email(social_email) if user and user.is_active: # a user is already associated with this email # TODO: there is an error with linking accounts... request.session[SOCIAL_REGISTRATION_SETTING_EMAIL] = social_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) elif collected_email: # email provided by user details['email'] = collected_email response = { 'details' : details } else: # no email provided from social auth request.session[SOCIAL_REGISTRATION_SETTING_MISSING_EMAIL] = True url_name = htk_setting('HTK_ACCOUNTS_REGISTER_SOCIAL_EMAIL_URL_NAME') response = redirect(url_name) return response
def clean_email(self): email = self.cleaned_data['email'] user = get_user_by_email(email) if user is None: self.email = email else: raise forms.ValidationError('This email is already registered')
def clean(self): cleaned_data = self.cleaned_data email = self.cleaned_data.get('email', None) if email: user = get_user_by_email(email) if user: if user.is_active: pass else: self.inactive_user = True raise forms.ValidationError( "That account is not active yet because you haven't confirmed your email. <a id=\"resend_confirmation\" href=\"{}\">Resend email confirmation ></a>".format( # noqa reverse(htk_setting('HTK_ACCOUNTS_RESEND_CONFIRMATION')) ) ) else: user = None if user is None: raise forms.ValidationError( "That email address doesn't have an associated user account. Are you sure you've registered?" # noqa ) else: self.user_cache = user return cleaned_data
def register_social_email(request): data = wrap_data_accounts(request) data.update(csrf(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 response = redirect('account_register_social_login') else: response = redirect_to_social_auth_complete(request) else: data['email_form'] = email_form response = _r('account/register_social_email.html', data) return response
def clean_email(self): email = self.cleaned_data['email'] user = get_user_by_email(email) if user is None: self.email = email else: raise forms.ValidationError('This email is already registered') return email
def clean_email(self): email = self.cleaned_data['email'] user = get_user_by_email(email) if user is not None: self.email = None raise forms.ValidationError(self.error_messages['email_already_associated']) else: self.email = email return email
def clean_email(self): email = self.cleaned_data['email'] user = get_user_by_email(email) if user is not None: self.email = None raise forms.ValidationError(_("A user with that email already exists.")) else: self.email = email return email
def clean_email(self): email = self.cleaned_data['email'] from htk.utils.emails import normalize_email email = normalize_email(email) self.cleaned_data['email'] = email user = get_user_by_email(email) if user is not None: self.email = None raise forms.ValidationError(self.error_messages['email_already_associated']) else: self.email = email return email
def get_htk_staff_id_email_map(): """Gets a mapping of Htk staff Returns a dictionary mapping User ids to emails """ c = HtkStaffCache() staff_map = c.get() if staff_map is None: staff_map = {} for email in HTK_STAFF_EMAILS: user = get_user_by_email(email) if user: staff_map[user.id] = email c.cache_store(staff_map) return staff_map
def get_company_officers_id_email_map(): """Gets a mapping of company officers Returns a dictionary mapping User ids to emails """ c = HtkCompanyOfficersCache() officers_map = c.get() if officers_map is None: officers_map = {} for email in htk_setting('HTK_COMPANY_OFFICER_EMAILS'): user = get_user_by_email(email) if user: officers_map[user.id] = email c.cache_store(officers_map) return officers_map
def get_company_employees_id_email_map(): """Gets a mapping of company employees Returns a dictionary mapping User ids to emails """ c = HtkCompanyEmployeesCache() employees_map = c.get() if employees_map is None: employees_map = {} for email in htk_setting('HTK_COMPANY_EMPLOYEE_EMAILS'): user = get_user_by_email(email) if user: employees_map[user.id] = email c.cache_store(employees_map) return employees_map
def clean(self): cleaned_data = self.cleaned_data email = self.cleaned_data.get('email', None) if email: user = get_user_by_email(email) if user: if user.is_active: pass else: self.inactive_user = True raise forms.ValidationError("That account is not active yet because you haven't confirmed your email. <a id=\"resend_confirmation\" href=\"javascript:void(0);\">Resend email confirmation ></a>") else: user = None if user is None: raise forms.ValidationError("That email address doesn't have an associated user account. Are you sure you've registered?") else: self.user_cache = user return cleaned_data
def check_email(strategy, details, user=None, *args, **kwargs): """Ask the user to enter the email if we don't have one yet The pipeline process was cut prior to this custom pipeline function, and will resume to this same function after completing """ response = None if user is None: strategy.request.session['backend'] = kwargs.get( 'current_partial').backend social_email = details.get('email') collected_email = strategy.request.session.get( SOCIAL_REGISTRATION_SETTING_EMAIL) if social_email: # email available from social auth user = get_user_by_email(social_email) if user and user.is_active: # a user is already associated with this email # TODO: there is an error with linking accounts... strategy.request.session[ SOCIAL_REGISTRATION_SETTING_EMAIL] = social_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) elif collected_email: # email provided by user details['email'] = collected_email response = {'details': details} else: # no email provided from social auth strategy.request.session[ SOCIAL_REGISTRATION_SETTING_MISSING_EMAIL] = True url_name = htk_setting( 'HTK_ACCOUNTS_REGISTER_SOCIAL_EMAIL_URL_NAME') response = redirect(url_name) 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
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