Exemplo n.º 1
0
def host_signup(
        email: str,
        password: str,
        name: str,
        primary_affiliation: int,
        reason: str = None
) -> Tuple[Optional['UserData'], Optional[str], bool]:
    with session_scope() as session:
        if PrimaryAffiliation.get_by_id(session,
                                        primary_affiliation) is not None:
            user = User.create(
                session,
                User(email=email,
                     password=password,
                     name=name,
                     primary_affiliation=primary_affiliation))
            if user is not None:
                code = None
                threshold = int(get_property('user.threshold'))
                if threshold > 0:
                    code = UserVerification.add(session, user.id).code
                    set_property('user.threshold', str(threshold - 1))
                host_request = UserHostRequest(
                    user=user.id,
                    primary_affiliation=primary_affiliation,
                    reason=reason)
                session.add(host_request)
                return UserData(user), code, True
            return None, None, True
    return None, None, False
Exemplo n.º 2
0
def invite_next_users():
    threshold = int(get_property('user.threshold'))
    with session_scope() as session:
        users = UserData.list(User.next_users_to_permit(session))
        for user in users:
            if threshold < 1:
                break
            code = UserVerification.add(session, user.id).code
            send_verification_email(to=user.email, code=code)
            threshold -= 1
    set_property('user.threshold', str(threshold))
Exemplo n.º 3
0
def login(email: str, password: str) -> 'UserData':
    with session_scope() as session:
        if User.verify_credentials(session, email, password):
            user = User.get_by_email(session, email)
            if not user.active:
                verification = UserVerification.get_by_user(session, user.id)
                threshold = int(get_property('user.threshold'))
                if not verification and threshold > 0:
                    verification = UserVerification.add(session,
                                                        user_id=user.id)
                    send_verification_email(to=email, code=verification.code)
                    set_property('user.threshold', threshold - 1)
            user.login_count += 1
            return UserData(user)
    return None
Exemplo n.º 4
0
def signup(email: str,
           password: str,
           name: str = None) -> Tuple[Optional['UserData'], Optional[str]]:
    """
    Sign user up with
    :param email:
    :param password:
    :param name:
    :return:
    """
    with session_scope() as session:
        user = User.create(session, User(email=email, password=password))
        if user is not None:
            code = None
            threshold = int(get_property('user.threshold'))
            if threshold > 0:
                logging.info("passed threshold")
                code = UserVerification.add(session, user.id).code
                set_property('user.threshold', str(threshold - 1))
            else:
                logging.info("failed threshold")
            return UserData(user), code
    return None, None
Exemplo n.º 5
0
def get_all_users() -> List[UserData]:
    with session_scope() as session:
        users = User.get_all(session)
        return UserData.list(users)
Exemplo n.º 6
0
def get_user_by_email(email: str) -> Optional[UserData]:
    with session_scope() as session:
        user = User.get_by_email(session, email)
        return None if not user else UserData(user)
Exemplo n.º 7
0
def get_user(id: int) -> Optional[UserData]:
    with session_scope() as session:
        user = User.get_by_id(session, id)
        return None if not user else UserData(user)
Exemplo n.º 8
0
def event_recommendation(event: Union[Event, 'EventData']) -> List[UserData]:
    return [UserData(user) for user in _event_recommendation(event)]