Beispiel #1
0
def enroll(username, friend_id):
    error = InternalServerError()
    error.type = 'enroll'
    
    if len(friend_id) != 14 or not friend_id.isnumeric()\
                            or not friend_id.startswith('2440'):
        error.msg = 'err_enroll_friend_id_knit'
        raise error
    if len(username) <= 2:
        error.msg = 'err_username_too_short'
        raise error
        
    friend_id = int(friend_id)
    query = database.User.filter(or_(
        database.User.friend_id == int(friend_id),
        database.User.alias.contains(username)))
    if query.count() > 0:
        user = query.first()
        if user.friend_id == friend_id:
            error.msg = 'err_enroll_duplicated_friend_id'
        elif user.alias == username:
            error.msg = 'err_enroll_duplicated_alias'
        else:
            error.msg = 'err_enroll_duplicate' # available?
        raise error

    database.session.add(database.User(friend_id, username))
    database.session.add(database.UserRequest(friend_id))
    return render_template('enroll.html', username=username)
Beispiel #2
0
def request_music(username, music_key):
    if music_key.isnumeric():
        music_id = int(music_key)
    else:
        music_id = Music.by_keyword(music_key, g.lang)
    args = dependency.build(check_user)
    user = args['user']
    try:
        database.MusicRequest.by(friend_id=user.friend_id)
        e = InternalServerError()
        e.type = 'request'
        e.title = 'err_request_denied'
        e.msg = 'err_request_duplicated'
        raise e
    except:
        pass
    database.session.add(database.MusicRequest(user.friend_id, music_id))
    return render_templace('request.html', **args)