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()
def db(): test = Test.query.first() if test: message = test.message else: message = None return ok({'message': message})
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))
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)
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()
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))
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()
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()
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)
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)
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))
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))
def update_comment(post_id, comment_id): return ok()
def index(): return ok('Index')
def index(): return ok()
def delete_test(test_id): test = Test.query.filter(Test.id == test_id).first() db.session.delete(test) db.session.commit() return ok()
def create(): return ok()
def main(): return ok()
def delete_comment(post_id, comment_id): return ok()
def create_comment(post_id): return ok()
def main(): movies = Movie.query.all() return ok(dict(movies=[movie.asdict() for movie in movies]))
def create_test(): test = Test(message='Hello World!!!') db.session.add(test) db.session.commit() return ok()
def get_posts(): return ok()
def ping(): return ok('pong')
def create_post(): return ok()
def detail(movie_id): movie = Movie.query.filter_by(id=movie_id).first().asdict() return ok(dict(movie=movie))
def update_test(test_id): test = Test.query.filter(Test.id == test_id).first() test.message = 'Hello World2!!!' db.session.commit() return ok()