def create(username, email, send_invitation=True, **qwargs): kwargs = locals() if get(username=username): raise Exception("user '%s' already exists" % username) org = organization.get_by_username(username) query = { 'username__endswith': '@%s' % org.suffix } if org.uid_field == 'pid': query['pid__value'] = qwargs[org.uid_field] if get(**query): raise Exception("unique identifier field '%s' with value '%s' already exists" % (org.uid_field, kwargs[org.uid_field])) raw_password = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for x in range(10)) send_invitation = kwargs.pop('send_invitation') _ = kwargs.pop('qwargs') user = User(**kwargs) user.set_password(raw_password) user.full_clean() user.save() if 'pid' in qwargs: value = qwargs.pop('pid') pid = PID(user=user, organization=org, value=value) pid.full_clean() pid.save() registry.signal('user_create', user=user, **qwargs) registry.signal('user_approval', user=user, send_invitation=send_invitation, raw_password=raw_password)
def send_approve_email(**kwargs): user = kwargs['user'] send_invitation = False if 'send_invitation' in kwargs: send_invitation = kwargs['send_invitation'] if not send_invitation: return raw_password = '******' if 'raw_password' in kwargs: raw_password = kwargs['raw_password'] org = organization.get_by_username(user.username) msg = u"""Com a membre de %s pots participar en les primàries obertes. Entra a https://%s/identity/login/ i empra les següents credencials per a identificar-te: - Usuari: %s - Contrasenya: %s Et recomanem canviar la contrasenya a 'Canviar contrasenya'. Gràcies per fer-nos confiança, %s """ send_mail(u'Votació en línia de les Primàries de %s' % org.name, msg % (org.name, org.domain, user.username.split('@')[0], raw_password, org.name), org.contact, [ user.email ], fail_silently=False)
def auto_join(user, **kwargs): organization_ = organization.get_by_username(user.username) nexus = organization_.main_nexus if nexus == None: raise Exception("main nexus '%s' doesn't exist" % settings.MAIN_NEXUS) nexus.join(user)