Example #1
0
 def like_post(post):
     if InteractionModel.find_by_actor_and_interactable(
             AuthService.get_current_user().actor,
             post.interactable) is None:
         InteractionModel(AuthService.get_current_user().actor,
                          post.interactable,
                          date="2018-02-01").save()
Example #2
0
def show_profile(user):
    user.friends = AuthService.get_friends(user)
    os.system(SYSTEM_CONST)
    print_header()
    print(user.name)
    print('Data de Nascimento: {}'.format(user.birthdate))
    print('Sexo: {}'.format({'M': 'masculino', 'F': 'feminino'}[user.gender]))
    print('Email: {}'.format(user.email))
    print('Quantidade de amigos: {}'.format(len(user.friends)))
    print('\nUltimas publicacoes:\n')
    last_posts = PostService.get_last_five_posts_from_actor(user.actor)
    output = '\n\n'.join([
        'Postado em: {}\nConteúdo: {}\nCurtidas: {}'.format(
            post.created_at, post.content, post.likes) for post in last_posts
    ])
    print(output + '\n')
    is_friend = AuthService.is_friend(user)
    print(
        '------------------------------------------------------------------------'
    )
    print('1. Ver amigos')
    if not is_friend:
        print('2. Tornar amigo')
        print('3. Voltar')
    else:
        print('2. Curtir publicação')
        print('3. Voltar')
    print(
        '--------------------------------------------------------------------------------'
    )
    op = get_op((1, 3))

    if op == 1:
        list_friends(user)
        return
    else:
        if not is_friend:
            if op == 2:
                AuthService.make_friendship(AuthService.get_current_user(),
                                            user)
                show_profile(user)
                return
        else:
            if op == 2:
                like_posts(user)
                return

        home()
        return
Example #3
0
def my_profile():
    os.system(SYSTEM_CONST)
    print_header()
    print(
        '------------------------------ MEU PERFIL ------------------------------'
    )
    user = AuthService.get_current_user()
    print(user.name)
    print('Data de Nascimento: {}'.format(user.birthdate))
    print('Sexo: {}'.format({'M': 'masculino', 'F': 'feminino'}[user.gender]))
    print('Email: {}'.format(user.email))
    print('Quantidade de amigos: {}'.format(len(user.friends)))
    print(
        '------------------------------------------------------------------------'
    )
    print('1. Listar Amigos')
    print('2. Mudar senha')
    print('3. Voltar')
    print(
        '--------------------------------------------------------------------------------'
    )
    op = get_op((1, 3))

    if op == 1:
        list_friends(user)
        return

    elif op == 2:
        change_password()
        return

    elif op == 3:
        home()
        return
Example #4
0
def change_password():
    os.system(SYSTEM_CONST)
    print_header()
    print(
        '------------------------------ MEU PERFIL ------------------------------'
    )
    print('Digite sua senha antiga')
    old = input()
    print('Digite a nova senha')
    new = input()
    if not AuthService.change_current_user_password(old, new):
        print('Senha antiga incorreta')
        print(
            '--------------------------------------------------------------------------------'
        )
        print('1. Tentar novamente')
        print('2. Voltar')
        print(
            '--------------------------------------------------------------------------------'
        )
        op = get_op((1, 2))

        if op == 1:
            change_password()
            return

    my_profile()
Example #5
0
def login():
    os.system(SYSTEM_CONST)
    print_header()
    print(
        '------------------------------ LOGIN ---------------------------------'
    )
    print('Digite seu email (ou -1 para voltar): ')
    email = input()
    if email == '-1':
        os.system(SYSTEM_CONST)
        initial()
        return
    print('Digite sua senha: ')
    senha = input()
    if senha == '-1':
        os.system(SYSTEM_CONST)
        initial()
        return
    print(
        '-------------------------------------------------------------------')

    while not AuthService.login(email, senha):
        print(
            '------------------------------ LOGIN ------------------------------'
        )
        print('Email ou senha incorretos :S')
        print('Digite seu email (ou -1 para voltar): ')
        email = input()
        if email == '-1':
            initial()
            return
        print('Digite sua senha: ')
        senha = input()
        if senha == '-1':
            os.system(SYSTEM_CONST)
            initial()
            return
        print(
            '-------------------------------------------------------------------'
        )

    home()
Example #6
0
def list_friends(user):
    os.system(SYSTEM_CONST)
    print_header()
    print(
        '------------------------------ AMIGOS ------------------------------')
    friends = user.friends
    output = '\n'.join(
        ['{}. {}'.format(i, friend.name) for i, friend in enumerate(friends)])
    print(output)
    print(str(len(friends)) + '. Voltar')
    print(
        '--------------------------------------------------------------------')
    print('Escolha um perfil para exibir')
    op = get_op((0, len(friends)))

    if op >= len(friends):
        show_profile(user)
        return
    else:
        friends[op].friends = AuthService.get_friends(friends[op])
        show_profile(friends[op])
        return
Example #7
0
    def search_users(pattern):
        if AuthService.get_current_user():
            return UserModel.find_users(pattern)

        return None
Example #8
0
def signup():
    os.system(SYSTEM_CONST)
    print_header()
    print(
        '------------------------------ CADASTRO ------------------------------'
    )
    print(
        '---------------------------- Insira [-1] a qualquer momento para voltar.'
    )

    print('Digite seu nome: ')
    name = input()
    if name == '-1':
        os.system(SYSTEM_CONST)
        initial()
        return

    print('Digite um email: ')
    email = input()
    if email == '-1':
        os.system(SYSTEM_CONST)
        initial()
        return

    while not is_valid_email(email):
        print('Digite um email válido: ')
        email = input()
        if email == '-1':
            os.system(SYSTEM_CONST)
            initial()
            return

    print('Digite uma senha: ')
    password = input()
    if password == '-1':
        os.system(SYSTEM_CONST)
        initial()
        return

    print('Digite seu sexo (M ou F): ')
    gender = input()
    if gender == '-1':
        os.system(SYSTEM_CONST)
        initial()
        return

    while not is_valid_gender(gender):
        print('Digite seu sexo válido (M ou F): ')
        gender = input()
        if gender == '-1':
            os.system(SYSTEM_CONST)
            initial()
            return

    print('Digite sua data de nascimento (ANO-MES-DIA): ')
    birthdate = input()
    if birthdate == '-1':
        os.system(SYSTEM_CONST)
        initial()
        return

    while not is_valid_birthdate(birthdate):
        print('Digite sua data de nascimento válida (ANO-MES-DIA): ')
        birthdate = input()
        if birthdate == '-1':
            os.system(SYSTEM_CONST)
            initial()
            return
    print(
        '-------------------------------------------------------------------')

    AuthService.signup(name, email, password, gender, birthdate)
    home()