Exemple #1
0
def login_kakao():
    result = {}

    id = request.args['id']
    username = request.args['username']
    profile_path = request.args['profile_path']

    if index.urls.existUserById(id) == False:
        user = User()
        user.type = 'KAKAO'
        user.id = id
        user.username = username
        user.profile_img_url = profile_path
        db_session.add(user)
        db_session.commit()

        result['user'] = user.to_json()

        app.logger.info('success signup')
        return json.dumps(result, ensure_ascii=False)
    
    user = db_session.query(User).filter_by(id=id).one()
    result['user'] = user.to_json()
    result['requestCode'] = 1
    result['requestMessage'] = 'success login'
    app.logger.info('success login')
    return json.dumps(result, ensure_ascii=False)
Exemple #2
0
def user_exists(username):
    '''
    Returns whether a user with the given username exists
    '''
    with sqlite3.connect("pennclubs.db") as db:
        u = db_session.query(User).filter_by(username=username).first()

        return u != None
Exemple #3
0
def regist_meeting():

    result = {}
    session = request.form['session']

    if index.urls.existUserBySession(session) == False:
        result['requestCode'] = -1
        result['requestMessage'] = '등록되지 않은 계정입니다.'
        app.logger.info('failed create meeting')
        app.logger.info('not exist user session')
        return json.dumps(result, ensure_ascii=False)

    result['requestCode'] = 1
    result['requestMessage'] = '일정이 등록되었습니다.'

    post = Meeting()
    user = db_session.query(User).filter_by(session=session).one()
    post.username = user.username
    post.session = user.session
    
    post.origin = request.form['origin']
    post.origin_lat = request.form['origin_lat']
    post.origin_long = request.form['origin_long']

    post.dest = request.form['dest']
    post.dest_lat = request.form['dest_lat']
    post.dest_long = request.form['dest_long']

    post.departure_time = datetime.datetime.fromtimestamp(int(request.form['departure_time'])/1000.0) # long to datetime 필요
    post.arrival_time = datetime.datetime.fromtimestamp(int(request.form['arrival_time'])/1000.0) # long to datetime 필요

    post.describe = request.form['describe']

    tags = [tag for tag in post.describe.split(' ') if tag.startswith('#')]
    for message in tags:
        query = db_session.query(Tag).filter_by(id=message)
        tag = None
        try:
            tag = query.one()
            tag.count += 1
        except NoResultFound, e:
            tag = Tag()
            tag.id = message
            tag.count = 1
            db_session.add(tag)
        db_session.commit()
Exemple #4
0
def getAllUsers():
    result = {}

    users = db_session.query(User).all()

    result['users'] = []
    for user in users:
        item = user.to_json()
        result['users'].append(item)

    app.logger.info('success return users')
    return json.dumps(result)
Exemple #5
0
def like_meeting():

    result = {}
    session = request.form['session']
    meeting_id = request.form['id']

    meeting = db_session.query(Meeting).filter_by(id=meeting_id).one()
    user = db_session.query(User).filter_by(session=session).one()
    if user in meeting.likes:
        meeting.likes.remove(user)
        app.logger.info('unlike')
    else:
        meeting.likes.append(user)
        app.logger.info('like')
    
    db_session.commit()
    app.logger.info('count : ' + str(len(meeting.likes)))
    result['requestCode'] = 1
    result['requestMessage'] = 'Success like or unlike'
    result['meeting'] = meeting.to_json()

    return json.dumps(result, ensure_ascii=False)
Exemple #6
0
def login_user(username, password):
    '''
    Attempts to log in a user by checking the users table.
    Returns a tuple containing a boolean indicating success
    and a message to flash to the user.
    '''
    if username == '' or password == '':
        return (False, "Username or password missing!")

    with sqlite3.connect("pennclubs.db") as db:
        u = db_session.query(User).filter_by(username=username).first()
        if u != None and check_password_hash(u.password, password):
            return (True, "Successfully logged in!")
    return (False, "Incorrect username or password.")
Exemple #7
0
def validateSession():
    result = {}

    session = request.form['session']
    app.logger.info('session : ' + session)

    if index.urls.existUserBySession(session) == False:
        result['requestCode'] = -1
        result['requestMessage'] = 'invalidate session'
        result['errorSession'] = session
        return json.dumps(result)

    user = db_session.query(User).filter_by(session=session).one()
    result['requestCode'] = 1
    result['user'] = user.to_json()
    result['requestMessage'] = 'validate session'
    return json.dumps(result)
Exemple #8
0
def get_all_meeting():

    result = {}
    session = request.form['session']

    if index.urls.existUserBySession(session) == False:
        result['requestCode'] = -1
        result['requestMessage'] = '등록되지 않은 계정입니다.'
        return json.dumps(result, ensure_ascii=False)        

    result['requestCode'] = 1
    result['requestMessage'] = '조회에 성공했습니다.'

    post_all = []

    query = db_session.query(Meeting).filter_by(session=session)
    post_all = query.all()

    result['meeting'] = []
    for post in post_all:
        result['meeting'].append(post.to_json())
        #app.logger.info('post ' + post.describe)

    return json.dumps(result)
Exemple #9
0
def get_userid(session):
    name = is_loggedin(session)
    with sqlite3.connect("pennclubs.db") as db:
        id = db_session.query(User).filter_by(username=name).first().id
        return id
Exemple #10
0
def existUserBySession(session):
    try:
        db_session.query(User).filter_by(session=session).one()
    except NoResultFound, e:
        return False
Exemple #11
0
def existUserById(id):
    try:
        db_session.query(User).filter_by(id=id).one()
    except NoResultFound, e:
        return False