Beispiel #1
0
    def create_if_not_exists(self, email, display_image_url, full_name,
                             provider_user_id, is_buy, auth_token):
        with session_scope() as session:
            user = (session.query(User).filter_by(
                provider_user_id=provider_user_id).one_or_none())
            if user is None:
                user = User(
                    email=email,
                    full_name=full_name,
                    display_image_url=display_image_url,
                    provider="linkedin",
                    can_buy=False,
                    can_sell=False,
                    provider_user_id=provider_user_id,
                    auth_token=auth_token,
                )
                session.add(user)
                session.flush()

                if is_buy is not None:
                    buy_req = UserRequest(user_id=str(user.id), is_buy=True)
                    session.add(buy_req)
                    if not is_buy:
                        sell_req = UserRequest(user_id=str(user.id),
                                               is_buy=False)
                        session.add(sell_req)

                    email_template = "register_buyer" if is_buy else "register_seller"
                    self.email_service.send_email(emails=[email],
                                                  template=email_template)

                    committee_emails = [
                        u.email for u in session.query(User).filter_by(
                            is_committee=True).all()
                    ]
                    self.email_service.send_email(emails=committee_emails,
                                                  template="new_user_review")
            else:
                user.email = email
                user.full_name = full_name
                user.display_image_url = display_image_url
                user.auth_token = auth_token

            session.commit()
            return user.asdict()
Beispiel #2
0
def create_user(id="", **kwargs):
    with session_scope() as session:
        user = User(**attributes_for_user(id, **kwargs))
        session.add(user)
        session.commit()
        return user.asdict()