def add(self, name, *args, **kvargs): if not NEW_USERID_PATTERN.match(name): raise ValueError( 'name must start with lowercase a-z and only contain lowercase a-z, numbers, minus and underscore' ) super(Users, self).add(name, *args, **kvargs)
def twitter_login_complete(context, request): result = { 'profile': context.profile, 'credentials': context.credentials, } schema = createSchema('CSORegisterUserSchema').bind(context=context, request=request) form = Form(schema, action='/twitter_register', buttons=(button_register, )) oauth_token = result['credentials']['oauthAccessToken'] oauth_userid = result['profile']['accounts'][0]['userid'] if 'displayName' in result['profile']: userid = result['profile']['displayName'] else: userid = '' if 'name' in result['profile']: first_name = result['profile']['name']['givenName'] last_name = result['profile']['name']['familyName'] else: first_name = '' last_name = '' if 'verifiedEmail' in result['profile']: email = result['profile']['verifiedEmail'] else: email = '' if not NEW_USERID_PATTERN.match(userid): userid = '' appstruct = { 'userid': userid, 'oauth_access_token': oauth_token, 'oauth_userid': oauth_userid, 'first_name': first_name, 'last_name': last_name, 'email': email, } appstruct['came_from'] = request.session.get('came_from', '') del request.session['came_from'] return {'form': form.render(appstruct=appstruct)}
def twitter_login_complete(context, request): result = { 'profile': context.profile, 'credentials': context.credentials, } schema = createSchema('CSORegisterUserSchema').bind(context=context, request=request) form = Form(schema, action='/twitter_register', buttons=(button_register,)) oauth_token = result['credentials']['oauthAccessToken'] oauth_userid = result['profile']['accounts'][0]['userid'] if 'displayName' in result['profile']: userid = result['profile']['displayName'] else: userid = '' if 'name' in result['profile']: first_name = result['profile']['name']['givenName'] last_name = result['profile']['name']['familyName'] else: first_name = '' last_name = '' if 'verifiedEmail' in result['profile']: email = result['profile']['verifiedEmail'] else: email = '' if not NEW_USERID_PATTERN.match(userid): userid = '' appstruct = {'userid': userid, 'oauth_access_token': oauth_token, 'oauth_userid': oauth_userid, 'first_name': first_name, 'last_name': last_name, 'email': email,} appstruct['came_from'] = request.session.get('came_from', '') del request.session['came_from'] return {'form': form.render(appstruct=appstruct)}
def add(self, name, *args, **kvargs): if not NEW_USERID_PATTERN.match(name): raise ValueError('name must start with lowercase a-z and only contain lowercase a-z, numbers, minus and underscore') super(Users, self).add(name, *args, **kvargs)
def __call__(self, node, value): html_string_validator(node, value) users = find_root(self.context).users nouserid = set() invalid = set() notunique = set() email = set() password = set() row_count = 0 # the value shoud be in unicode from colander and csv wants ascii or utf-8 value = value.encode('UTF-8') data = csv.reader(StringIO(value), delimiter=';', quotechar='"') try: for row in data: row_count = row_count + 1 if not row[0]: nouserid.add("%s" % row_count) if row[0] and not NEW_USERID_PATTERN.match(row[0]): invalid.add(row[0]) if row[0] in users: notunique.add(row[0]) # only validate email if there is an email if len(row) > 2 and row[2]: try: UniqueEmail(self.context)(node, row[2]) except colander.Invalid: email.add("%s" % row[2]) except IndexError: raise colander.Invalid(node, _('add_participants_invalid_csv', default=u"""CSV file is not valid, make sure at least userid is specified on each row and field delimiter is ; and text delimiter is " """)) msgs = [] if nouserid: msgs.append(self.api.translate(_('add_participants_no_userid_error', default=u"The following rows had no userid specified: ${nouserid}.", mapping={'nouserid': nouserid}))) if invalid: invalid = ", ".join(invalid) msgs.append(self.api.translate(_('add_participants_userid_char_error', default=u"The following userids is invalid: ${invalid}. UserID must be 3-30 chars, start with lowercase a-z and only contain lowercase a-z, numbers, minus and underscore.", mapping={'invalid': invalid}))) if notunique: notunique = ", ".join(notunique) msgs.append(self.api.translate(_('add_participants_notunique_error', default=u"The following userids is already registered: ${notunique}.", mapping={'notunique': notunique}))) if email: email = ", ".join(email) msgs.append(self.api.translate(_('add_participants_email_error', default=u"The following email addresses is invalid or already registered: ${email}.", mapping={'email': email}))) if password: password = "******".join(password) msgs.append(self.api.translate(_('add_participants_password_error', default=u"The following rows has invalid password: ${password}. Password must be between 6 and 100 characters", mapping={'password': password}))) if msgs: msg = "\n".join(msgs) raise colander.Invalid(node, msg)