def create_user(cls, email, pwd): cls.logger.info("create_user") cus = None try: salt = AccountUtils.getn_salt() hashed_pwd = AccountUtils.set_pwd(pwd, salt) cid = AccountUtils.get_timestamp('CUS') with session_scope() as session: customer = Customer() customer.cid = cid customer.salt = salt customer.email = email customer.password = hashed_pwd session.add(customer) cus = {'email': email, 'uid': cid} except BaseException as e: cls.logger.warning("유저 생성중 문제가 발생했습니다.") cls.logger.warning(e) return set_response("99", {"errorMsg": "유저 생성중 문제가 발생했습니다."}) try: access_token = AccountUtils.get_token(cus) except BaseException as e: cls.logger.warning("토큰 생성중 에러가 발생했습니다.") cls.logger.warning(e) return set_response("99", {"errorMsg": "토큰 생성중 에러가 발생했습니다."}) return set_response("00", {'token': access_token})
def login(cls, email, pwd): # 아이디, pwd 확인 cls.logger.info("login 진입") cls.logger.info(email) cls.logger.info(pwd) with session_scope() as session: customer = session.query(Customer).filter( Customer.email == email).first() cls.logger.info("{} 조회성공".format(customer.email)) if customer is None: response = set_response("99", {"errorMsg": "존재하지 않는 이메일입니다."}) return response try: cid = customer.cid cus_pwd = customer.password salt = customer.salt pwd = AccountUtils.set_pwd(pwd, salt) isauth = AccountUtils.chk_pwd(pwd, cus_pwd) if isauth: cus = {'email': email, 'uid': cid} access_token = AccountUtils.get_token(cus) response = set_response("00", {"token": access_token}) else: response = set_response("99", {"errorMsg": '회원정보가 틀렸습니다.'}) except BaseException as e: cls.logger.warning("크리티컬 이슈") cls.logger.warning(e) response = set_response("99", {"errorMsg": '토큰 생성 실패'}) cls.logger.info("login response==") cls.logger.info(response) return response
def mysql_fetch_answer_post_p(cls, post_id, is_teacher=None): with session_scope() as session: answer = session.query(AnswerPost).filter( AnswerPost.id == post_id).first() if is_teacher is not None: answer.is_teacher_view = True elif answer.is_grade: # 확인중 채점되어있다면 answer.is_grade_view = True obj = { 'id': answer.id, 'time': answer.time, 'answer_img': answer.answer_img, 'is_over': answer.is_over, 'author': answer.author, 'is_grade_view': answer.is_grade_view, 'score': answer.score, 'problem_post': answer.problem_post, 'comment': answer.comment, 'is_teacher_view': answer.is_teacher_view, 'is_grade': answer.is_grade, 'created_at': answer.created_at, 'updated_at': answer.updated_at } return obj
def IsUseAccount(cls, email): with session_scope() as session: isUse = session.query(Customer).filter( Customer.email == email).first() if isUse is None: return False return True
def create_user(cls, email, pwd): cls.logger.info("create_user Teacher") cls.logger.info(email) cls.logger.info(pwd) cus = None try: salt = AccountUtils.getn_salt() hashed_pwd = AccountUtils.set_pwd(pwd, salt) tid = AccountUtils.get_timestamp('TEA') with session_scope() as session: teacher = Teacher() teacher.tid = tid teacher.salt = salt teacher.email = email teacher.password = hashed_pwd session.add(teacher) tea = { 'email': email, 'uid': tid } except BaseException as e: cls.logger.warning("유저 생성중 문제가 발생했습니다.") cls.logger.warning(e) return set_response("99", {"errorMsg": "유저 생성중 문제가 발생했습니다."}) try: access_token = AccountUtils.get_token(tea) except BaseException as e: cls.logger.warning("토큰 생성중 에러가 발생했습니다.") cls.logger.warning(e) return set_response("99", {"errorMsg": "토큰 생성중 에러가 발생했습니다."}) return set_response("00", {'token': access_token})
def mysql_fetch_answer_post(cls, filters=None): answer_post_list = [] with session_scope() as session: filter_list = [] for filter in filters.items(): key = filter[0] value = filter[1] if key == 'problem_post': filter_list.append(AnswerPost.problem_post == value) if key == 'is_grade': if value is None: continue else: filter_list.append(AnswerPost.is_grade == True if value == 'true' else False) if key == 'is_teacher_view': if value is None: continue else: filter_list.append(AnswerPost.is_teacher_view == True if value == 'true' else False) if key == 'is_grade_view': if value is None: continue else: filter_list.append(AnswerPost.is_grade_view == True if value == 'true' else False) if key == "author": if value is None: continue else: filter_list.append(AnswerPost.author == value) answer_model = session.query(AnswerPost).filter(*filter_list) count = answer_model.count() for answer in answer_model: obj = { 'id': answer.id, 'time': answer.time, 'answer_img': answer.answer_img, 'is_over': answer.is_over, 'author': answer.author, 'is_grade_view': answer.is_grade_view, 'score': answer.score, 'problem_post': answer.problem_post, 'comment': answer.comment, 'is_teacher_view': answer.is_teacher_view, 'is_grade': answer.is_grade, 'created_at': answer.created_at, 'updated_at': answer.updated_at } answer_post_list.append(obj) return count, answer_post_list
def mysql_update_answer_post(cls, post_id, comment, score): with session_scope() as session: answer_model = session.query(AnswerPost).filter( AnswerPost.id == post_id).first() if answer_model.is_grade == True: response = set_response("77", {"errorMsg": "이미 첨삭된 답안입니다."}) answer_model.is_grade = True answer_model.score = score answer_model.comment = comment response = set_response("00", {"successMsg": "성공적으로 채점되었습니다."}) return response
def mysql_create_answer_post(cls, params, file=None): answer_post = {} if file is not None: img_path = upload_img('answers', file) params['answer_img'] = img_path with session_scope() as session: now = int(dt.now().timestamp() * 10000000) params['created_at'] = now params['updated_at'] = now answer_post_model = AnswerPost(**params) session.add(answer_post_model) response = set_response("00", {"img_url": img_path}) cls.logger.info(response) return response
def mysql_create_problem_post(cls, params, file=None): problem_post = {} if file is not None: img_path = upload_img('problems', file) params['problem_img'] = img_path with session_scope() as session: now = int(dt.now().timestamp() * 10000000) params['view'] = 0 params['created_at'] = now params['updated_at'] = now problem_post_model = ProblemPost(**params) session.add(problem_post_model) response = set_response("00", {"successMsg": "성공적으로 등록되었습니다."}) return response
def login(cls, email, pwd): # 아이디, pwd 확인 with session_scope() as session: teacher = session.query(Teacher).filter(Teacher.email == email).first() if teacher is None: response = set_response("99", {"errorMsg": "존재하지 않는 이메일입니다."}) return response tid = teacher.tid cus_pwd = teacher.password salt = teacher.salt pwd = AccountUtils.set_pwd(pwd, salt) isauth = AccountUtils.chk_pwd(pwd, cus_pwd) if isauth: cus = { 'email': email, 'uid': tid } access_token = AccountUtils.get_token(cus) response = set_response("00", {"token": access_token}) else: response = set_response("99", {"errorMsg": '회원정보가 틀렸습니다.'}) return response
def mysql_fetch_problem_post(cls, filters=None): problem_post_list = [] with session_scope() as session: filter_list = [] for filter in filters.items(): key = filter[0] value = filter[1] if key == 'affiliation': filter_list.append(ProblemPost.affiliation == value) if filters.get('order') is not None: problem_model = session.query(ProblemPost).filter( *filter_list).order_by(ProblemPost.view.desc()) else: problem_model = session.query(ProblemPost).filter( *filter_list).order_by(ProblemPost.updated_at.desc()) for problem in problem_model: count = session.query(AnswerPost).filter( AnswerPost.problem_post == problem.id).distinct( AnswerPost.author).count() obj = { 'id': problem.id, 'max_time': problem.max_time, 'title': problem.title, 'sub_title': problem.sub_title, 'subject': problem.subject, 'category': problem.category, 'problem_img': problem.problem_img, 'view': problem.view, 'author': problem.author, 'affiliation': problem.affiliation, 'created_at': problem.created_at, 'updated_at': problem.updated_at, 'count': count } problem_post_list.append(obj) return problem_post_list