def register_user(email: str, username: str, password: str) -> User: new_user = User(email=email, username=username) new_user.set_password(password) errors = check_for_existing_user(new_user) if errors: raise UserExists({"errors": errors}) new_user.save() UserMeta.objects.bulk_create([ UserMeta(user=new_user, key=UserMeta.MetaKeys.NEW_GAME_MAIL, value=True), UserMeta(user=new_user, key=UserMeta.MetaKeys.POST_SIDE, value="l"), UserMeta(user=new_user, key=UserMeta.MetaKeys.SHOW_AVATARS, value=True), ]) send_activation_email(new_user) return new_user
def authenticate(self, oauth2_session=None, **kwargs): if oauth2_session is None: # Not ours (password login) return None response = oauth2_session.get(settings.KOMPASSI_API_V2_USER_INFO_URL) response.raise_for_status() kompassi_user = response.json() # Non-editor users may not log in via OAuth2 if not STAFF_GROUPS.intersection(kompassi_user['groups']): return None user, created = User.objects.get_or_create(username=kompassi_user['username']) for key, value in user_attrs_from_kompassi(kompassi_user).items(): setattr(user, key, value) user.save() user_meta = UserMeta.get_for_user(user) for key, value in user_meta_attrs_from_kompassi(kompassi_user).items(): setattr(user_meta, key, value) user_meta.save() return user
def formatted_author(self): if self.author: return UserMeta.get_for_user(self.author).get_full_name() else: return u''