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)
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()
def register_user(username, password, repassword): ''' Attempts to register a user and enter it in the users table. Returns a tuple containing a boolean indicating success and a message to flash to the user. ''' if username == '' or password == '' or repassword == '': return (False, "Please fill in all fields.") elif password != repassword: return (False, "Passwords do not match!") with sqlite3.connect("pennclubs.db") as db: if user_exists(username): return (False, "Username {} already exists.".format(username)) else: pw_hash = generate_password_hash(password) new_user = User(username=username, password=pw_hash) db_session.add(new_user) db_session.commit() return (True, "Successfully registered {}".format(username))
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)
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() db_session.add(post) db_session.commit() result['post'] = post.to_json() app.logger.info('create meeting') return json.dumps(result, ensure_ascii=True) @app.route('/like/meeting', methods=['POST']) 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: