コード例 #1
0
 def post(self):
     questions = request.get_json()['questions']
     db = DBConnection()
     for item in questions:
         lastInsertId = db.AddQuestion(item['userAuthor'], item['question'],
                                       item['questionType'])
         self.AddAnswers(lastInsertId, item['rightAnswer'],
                         item['otherAnswers'])
     return questions
コード例 #2
0
 def post(self):
     username = request.get_json()['username']
     db = DBConnection()
     userInfo = db.GetUserByUserName(username)[0]
     return {
         "result": "ok",
         "userId": userInfo[0],
         "username": userInfo[1],
         "firstName": userInfo[2],
         "lastName": userInfo[3],
         "userGroups": userInfo[5]
     }
コード例 #3
0
 def post(self):
     result = DBConnection().GetAllQuestionCategory()
     category = []
     for item in result:
         category.append(item[1])
     ans = {"questionCategory": category}
     return ans
コード例 #4
0
 def post(self):
     questionId = request.get_json()['questionId']
     db = DBConnection()
     question = db.GetQuestionById(questionId)[0][0]
     print(question)
     result = db.GetAnswersForQuestionId(questionId)
     ans = []
     for item in result:
         if item[1] == 1:
             rightAnswer = item[0]
         else:
             ans.append(item[0])
     return {
         "question": question,
         "rightAsnwer": rightAnswer,
         "otherAnswers": ans
     }
コード例 #5
0
 def get(self):
     print("kek")
     result = DBConnection().GetTelegramUsers()
     ans = []
     for item in result:
         ans.append({
             "userId": item[0],
             "telegramName": item[1],
             "telegramId": item[2],
             "rating": item[3]
         })
     return {"telegramUsers": ans}
コード例 #6
0
    def post(self):
        try:
            username = request.get_json()['username']
            password = request.get_json()['password']

            db = DBConnection()
            res = db.GetUserByUserName(username)
            if res:
                if username in res[0]:
                    if check_password_hash(res[0][4], password):
                        userGroup = db.GetUserGroup(username)
                        access_token = create_access_token(identity={
                            'group':
                            userGroup[0][0],
                        },
                                                           expires_delta=False)
                        result = {'token': access_token, 'result': 'ok'}
                        return result
                return error('Invalid pass or login')
            return error('Not user in db')
        except:
            return error('Invalid json or maybe something else wrong')
コード例 #7
0
    def post(self):
        userName = request.get_json()['username']
        password = request.get_json()['password']
        repeatPassword = request.get_json()['passwordRepeat']
        firstName = request.get_json()['firstName']
        lastName = request.get_json()['lastName']
        email = request.get_json()['email']
        if userName == '':
            return error('Invalid user name')

        if password == '':
            return error('Invalid password')

        if firstName == '':
            return error('Invalid first name')

        if lastName == '':
            return error('Invalid last name')

        if email == '':
            return error('Invalid email')

        if password != repeatPassword:
            return error('password != repeat password')

        db = DBConnection()
        user = db.GetUserByUserName(userName)

        if len(user) != 0:
            return error('This username alredy exsist')

        db.AddUser(userName=userName,
                   firstName=firstName,
                   lastName=lastName,
                   passHash=generate_password_hash(password),
                   userGroup=1)

        return {"result": "ok"}
コード例 #8
0
 def post(self):
     message = request.get_json()['message']
     telegramId = request.get_json()['telegramId']
     db = DBConnection()
     db.AddMessage(message, telegramId)
     return ''
コード例 #9
0
 def post(self):
     category = request.get_json()['category']
     db = DBConnection()
     db.DeleteCategory(category)
     return ''
コード例 #10
0
 def post(self):
     questionId = request.get_json()['questionId']
     db = DBConnection()
     db.DeleteQuestion(questionId)
     return ''
コード例 #11
0
 def post(self):
     questionCategories = request.get_json()['categories']
     db = DBConnection()
     for item in questionCategories:
         db.AddCategory(item)
     return ''
コード例 #12
0
 def AddAnswers(self, lastInsertId, rightAnswer, otherAnswers):
     db = DBConnection()
     db.AddAnswer(lastInsertId[0][0], rightAnswer, 1)
     for item in otherAnswers:
         db.AddAnswer(lastInsertId[0][0], item, 0)
     return ''
コード例 #13
0
 def post(self):
     return DBConnection().Test()
コード例 #14
0
 def post(self):
     userName = request.get_json()['username']
     db = DBConnection()
     result = db.GetQuestionByUsername(userName)
     ans = QuestionArray(result)
     return {"result": "ok", "questions": ans}
コード例 #15
0
 def post(self):
     db = DBConnection()
     result = db.GetQuestion()
     ans = QuestionArray(result)
     return {"result": "ok", "questions": ans}