Ejemplo n.º 1
0
def signup():
    form = request.form
    email = form.get('email')
    password = form.get('password')
    nickname = form.get('nickname')
    phone = form.get('phone')
    age = form.get('age')

    if not (email and password and nickname and phone and age):
        return error(40000)

    user = User.query.filter(
        or_(User.email == email, User.nickname == nickname)).first()
    if user:
        return error(40000)

    password = hashlib.sha256(password.encode('utf-8')).hexdigest()
    user = User(email=email,
                nickname=nickname,
                password=password,
                phone_number=phone,
                age=age)
    db.session.add(user)
    db.session.commit()
    return ok()
Ejemplo n.º 2
0
def db():
    test = Test.query.first()
    if test:
        message = test.message
    else:
        message = None
    return ok({'message': message})
Ejemplo n.º 3
0
def main():
    args = request.args
    movie_id = args.get('movie_id', 1)

    cinemas = Cinema.query.all()
    return ok(
        dict(cinemas=[cinema.asdict() for cinema in cinemas],
             movie_id=movie_id))
Ejemplo n.º 4
0
def vpp_login(request):
    name = request.GET['userName']
    password = request.GET['userPass']
    dict = {}
    if request.method == 'GET':
        user = AdminUser.get_user_by_name(name)
        if user.password == password:
            dict['response'] = 'success'
        else:
            dict['response'] = 'fail'

    return ok(dict)
Ejemplo n.º 5
0
def delete_post(post_id):
    post = Post.query.filter(Post.id == post_id).first()
    if not post:
        return error(40400)
    if current_user.id != post.user_id:
        return error(40300)

    Tag.query.filter(Tag.post_id == post_id).delete()
    View.query.filter(View.post_id == post_id).delete()
    Comment.query.filter(Comment.post_id == post_id).delete()
    db.session.delete(post)
    db.session.commit()
    return ok()
Ejemplo n.º 6
0
def proxy():
    args = request.args
    form = request.form
    url = args.get('url')

    if not url:
        return error(50000)

    if request.method == 'GET':
        res = requests.get(url=url)
    else:
        res = requests.post(url=url, data=form)

    return ok(dict(url=res.url, data=res.text, code=res.status_code))
Ejemplo n.º 7
0
def update_post(post_id):
    form = request.form
    title = form['title']
    content = form['content']
    tags = form['tags']

    post = Post.query.filter(Post.id == post_id).first()
    if not post:
        return error(40400)
    if current_user.id != post.user_id:
        return error(40300)

    Tag.query.filter(Tag.post_id == post_id).delete()

    post.title = title
    post.content = content
    post.tags = [Tag(title=tag) for tag in tags.split(',')]
    db.session.commit()
    return ok()
Ejemplo n.º 8
0
def create():
    form = request.form
    theater_id = form['theater_id']
    showtime_id = form['showtime_id']
    x = form['x']
    y = form['y']

    showtime = Showtime.query.filter_by(id=showtime_id,
                                        theater_id=theater_id).first()
    if not showtime:
        return error(40400)

    theater_ticket = TheaterTicket(theater_id=theater_id,
                                   showtime_id=showtime_id,
                                   x=x,
                                   y=y)
    db.session.add(theater_ticket)
    db.session.commit()
    return ok()
Ejemplo n.º 9
0
def signin():
    form = request.form
    email = form.get('email')
    password = form.get('password')
    if not (email and password):
        return error(40000)

    password = hashlib.sha256(password.encode('utf-8')).hexdigest()
    user = User.query.filter_by(email=email, password=password).first()
    if not user:
        return error(40400)

    res = {
        'nickname': user.nickname,
        'email': user.email,
        'age': user.age,
        'phone_number': user.phone_number,
        'profile_url': user.profile_url,
        'token': user.token
    }
    return ok(res)
Ejemplo n.º 10
0
def callback():
    id_token = request.form.get('id_token')

    if not id_token:
        return error(50000, 'required id_token')

    try:
        id_info = google_id_token.verify_oauth2_token(
            id_token, google_requests.Request(), Config.GOOGLE_CLIENT_ID)
    except ValueError:
        # wrong id_token
        return error(50000, 'wrong id_token')

    # wrong issuer
    if id_info['iss'] not in [
            'accounts.google.com', 'https://accounts.google.com'
    ]:
        return error(50000, 'wrong issuer')

    res = requests.get('https://www.googleapis.com/oauth2/v3/tokeninfo',
                       {'id_token': id_token})
    data = res.json()

    user = User.query.filter_by(email=data['email']).first()
    if not user:
        user = User(email=data['email'],
                    nickname=data['name'],
                    profile_url=data['picture'])
        db.session.add(user)
        db.session.commit()

    res = {
        'nickname': user.nickname,
        'email': user.email,
        'age': user.age,
        'phone_number': user.phone_number,
        'profile_url': user.profile_url,
        'token': user.token
    }
    return ok(res)
Ejemplo n.º 11
0
def main():
    week = {
        0: 'mon',
        1: 'tue',
        2: 'wed',
        3: 'thu',
        4: 'fri',
        5: 'sat',
        6: 'sun'
    }
    week_list = []
    now = current_time()
    now_weekday = now.weekday()

    args = request.args
    movie_id = args.get('movie_id')
    selected_date = args.get('date', now.strftime('%Y-%m-%d'))
    selected_cinema_id = args.get('cinema_id')
    selected = {
        'date': selected_date,
        'cinema_id': selected_cinema_id,
        'movie_id': movie_id
    }

    for i in range(now_weekday, now_weekday + 7):
        day = i - now_weekday
        date = now + timedelta(days=day)
        i %= 7
        week_list.append({
            'weekday': week[i],
            'date': date.strftime('%Y-%m-%d')
        })

    movies = Movies(movie_id=movie_id,
                    selected_date=selected_date,
                    cinema_id=selected_cinema_id).result()
    return ok(dict(week=week_list, selected=selected, movies=movies))
Ejemplo n.º 12
0
def detail(theater_id, showtime_id):
    showtime = Showtime.query.filter_by(id=showtime_id,
                                        theater_id=theater_id).first()
    if not utc2local(showtime.start_time) > current_time():
        return error(40400)

    theater = Theater.query.filter_by(id=theater_id).first()

    seats = []
    x, y = 1, 1
    for _ in range(theater.seat):
        data = {'seat_number': '{}-{}'.format(x, y), 'selected_seat': False}
        theater_tickets = TheaterTicket.query.filter_by(
            theater_id=theater_id, showtime_id=showtime_id).all()
        for theater_ticket in theater_tickets:
            if theater_ticket.x == x and theater_ticket.y == y:
                data['selected_seat'] = True
        seats.append(data)
        if y > 9:
            y = 0
            x += 1
        y += 1
    return ok(dict(seats=seats, theater_id=theater_id,
                   showtime_id=showtime_id))
Ejemplo n.º 13
0
def update_comment(post_id, comment_id):
    return ok()
Ejemplo n.º 14
0
def index():
    return ok('Index')
Ejemplo n.º 15
0
def index():
    return ok()
Ejemplo n.º 16
0
def delete_test(test_id):
    test = Test.query.filter(Test.id == test_id).first()
    db.session.delete(test)
    db.session.commit()
    return ok()
Ejemplo n.º 17
0
def create():
    return ok()
Ejemplo n.º 18
0
def main():
    return ok()
Ejemplo n.º 19
0
def delete_comment(post_id, comment_id):
    return ok()
Ejemplo n.º 20
0
def create_comment(post_id):
    return ok()
Ejemplo n.º 21
0
def main():
    movies = Movie.query.all()
    return ok(dict(movies=[movie.asdict() for movie in movies]))
Ejemplo n.º 22
0
def create_test():
    test = Test(message='Hello World!!!')
    db.session.add(test)
    db.session.commit()
    return ok()
Ejemplo n.º 23
0
def get_posts():
    return ok()
Ejemplo n.º 24
0
def ping():
    return ok('pong')
Ejemplo n.º 25
0
def create_post():
    return ok()
Ejemplo n.º 26
0
def detail(movie_id):
    movie = Movie.query.filter_by(id=movie_id).first().asdict()
    return ok(dict(movie=movie))
Ejemplo n.º 27
0
def update_test(test_id):
    test = Test.query.filter(Test.id == test_id).first()
    test.message = 'Hello World2!!!'
    db.session.commit()
    return ok()