def create_userprofile_for(email, username, full_name): """Create a fake user profile.""" user = User.query.filter_by(email=email).one_or_none() if user: profile = UserProfile(user_id=int(user.get_id())) profile.username = username profile.full_name = full_name db.session.add(profile) db.session.commit()
def _register_or_update_user(entries, user_account=None): """Register or update a user.""" email = entries[app.config['LDAPCLIENT_EMAIL_ATTRIBUTE']].values[0] username = entries[app.config['LDAPCLIENT_USERNAME_ATTRIBUTE']].values[0] if 'LDAPCLIENT_FULL_NAME_ATTRIBUTE' in app.config: full_name = entries[ app.config['LDAPCLIENT_FULL_NAME_ATTRIBUTE']].values[0] if user_account is None: kwargs = dict(email=email, active=True, password=uuid.uuid4().hex) _datastore.create_user(**kwargs) user_account = User.query.filter_by(email=email).one_or_none() profile = UserProfile(user_id=int(user_account.get_id())) else: user_account.email = email db.session.add(user_account) profile = user_account.profile profile.full_name = full_name profile.username = username db.session.add(profile) return user_account