Exemplo n.º 1
0
def get_sync(user_one, user_two):
    if dao.get_user(user_one) is None:
        return failure_response("User one not saved.")
    if dao.get_user(user_two) is None:
        return failure_response("User two not saved.")

    sync = dao.get_sync(user_one, user_two)
    if sync is None:
        return failure_response("Sync not saved.")
    return success_response(sync, 406)
Exemplo n.º 2
0
def create_sync():
    body = json.loads(request.data)
    user_one = body.get("user_one")
    user_two = body.get("user_two")

    if dao.get_user(user_one) is None:
        return failure_response("User one not saved.")
    if dao.get_user(user_two) is None:
        return failure_response("User two not saved.")

    sync = dao.create_sync(user_one, user_two)
    return success_response(sync)
Exemplo n.º 3
0
def add_playlist_user(username):
    body = json.loads(request.data)
    user = dao.get_user(username)
    if user is None:
        return failure_response("Username not saved.")
    dao.add_playlist(username, body.get("name"), body.get("playlist"))
    return success_response(user)
Exemplo n.º 4
0
    def get_user(dao, user=None, savedUser=None):
        if user is None and savedUser is not None:
            user = dao.get_user(user=savedUser['slack'])
        if user is not None and savedUser is None:
            savedUser = dao.get_saved_user(user=user['profile']['email'])

        tList = None
        if savedUser is not None and 'tags' in savedUser:
            tList = []
            if isinstance(savedUser['tags'], str):
                t = dao.get_saved_tag(type_tag='tag-user',
                                      tag_id=savedUser['tags'])
                tList.append(t.get('name'))

            elif isinstance(savedUser['tags'], list):
                for tag in savedUser['tags']:
                    t = dao.get_saved_tag(type_tag='tag-user', tag_id=tag)
                    tList.append(t.get('name'))

        teamList = None
        if savedUser is not None and 'teams' in savedUser:
            teamList = []
            if isinstance(savedUser['teams'], str):
                t = dao.get_saved_tag(type_tag='team',
                                      tag_id=savedUser['teams'])
                teamList.append(t.get('name'))

            elif isinstance(savedUser['teams'], list):
                for team in savedUser['teams']:
                    t = dao.get_saved_tag(type_tag='team', tag_id=team)
                    teamList.append(t.get('name'))

        txt = '*' + user['profile']['real_name'] + '* - <@' + user['id'] + '>\n'

        if savedUser is not None and 'leader' in savedUser:
            txt += '*Líder:* <@' + savedUser['leader'] + '>'

        if tList is not None and len(tList) > 0:
            txt += "\n*Times:* " + (', '.join(teamList))

        if tList is not None and len(tList) > 0:
            txt += "\n*Tags:* " + (', '.join(tList))

        ret = {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": txt
            },
            "accessory": {
                "type": "image",
                "image_url": user['profile']['image_512'],
                "alt_text": "profile picture"
            }
        }

        return ret
def create_review(id):
    body = json.loads(request.data)
    content = body.get("content", "")
    username = body.get("username", "")
    password = body.get("password", "")
    if content == None:
        return failure_response("Please provide a review and a book id!")
    if dao.get_user(username, password) is None:
        return failure_response("Please provide a valid login")
    new_review = dao.create_review(content, id, username, password)
    if new_review is None:
        return failure_response("Either book id or content is invalid")
    return success_response(new_review)
Exemplo n.º 6
0
def login():
    if 'username' in session:
        return redirect('custom')

    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        action = request.form['action']
        # make new account
        if action == 'register':
            # generate salt and hash for password
            salt = os.urandom(64)
            salt = salt.encode('base64')
            m = hashlib.md5()
            m.update(password + salt)
            # store user in database
            message = dao.create_user({
                'username': username,
                'hashedpass': m.hexdigest(),
                'salt': salt
            })
            return render_template('login.html', message=message)
        # login
        elif action == 'login':
            # see if user exists
            existing_user = dao.get_user(username)
            if existing_user is None:
                return render_template('login.html',
                                       message='username not found')
            else:
                # see if hash of entered password matches what's stored
                m = hashlib.md5()
                m.update(password + existing_user['salt'])
                if m.hexdigest() == existing_user['hashedpass']:
                    session['username'] = username
                    return redirect('custom')
                else:
                    return render_template('login.html',
                                           message='password incorrect')

    return render_template('login.html')
Exemplo n.º 7
0
def get_user(username):
    user = dao.get_user(username)
    if user is None:
        return failure_response("Username not saved. Create user first.")
    return success_response(user)
Exemplo n.º 8
0
def get_user(uid):
    user = dao.get_user(uid)
    if user is None:
        return failure_response("This user does not exist!")
    return success_response(user)
Exemplo n.º 9
0
Arquivo: app.py Projeto: a-2z/upick
def get_user(user_id):
    try:
        return success_response(dao.get_user(user_id))
    except UserNotFound as e:
        return failure_response("Please try again.")
Exemplo n.º 10
0
def get_user(user_id):
    user = dao.get_user(user_id)
    if user is None:
        return failure_response("User not found!")
    return success_response(user)