Пример #1
0
def resetPassword():
  status = 200
  dynamoDBInstance = getDatabaseClient()
  res = user_ctrl.resetUserPassword(request.json, dynamoDBInstance)
  if res.hasErrors():
    status = 400
  return ResponseCreation.createResponse(res,status)
Пример #2
0
def public_class_list():
  status = 200
  dynamoDBInstance = getDatabaseClient()
  res = class_ctrl.getPublicClassList(dynamoDBInstance)
  if res.hasErrors():
    status = 400
  return ResponseCreation.createResponse(res, status)
Пример #3
0
def getClass(classCode):
  status = 200
  dynamoDBInstance = getDatabaseClient()
  res = class_ctrl.getClass(classCode, dynamoDBInstance)
  if res.hasErrors():
    status = 400
  return ResponseCreation.createResponse(res, status)
Пример #4
0
def activate(activationid):
  logger.info(str(request))
  dynamoDBInstance = getDatabaseClient()
  res = user_ctrl.activate(activationid, dynamoDBInstance)
  status = 200
  if res.hasErrors():
    status = 400
  flaskResponse = ResponseCreation.createResponse(res, status)
  logger.info(str(flaskResponse))
  return flaskResponse
Пример #5
0
def createBook():
  status = 200
  res = ResponseCreation.ControllerResponse()
  if g.authenticatedUser['userRole'] != "admin":
    res.addError('Role Error', 'Only admins can create books')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = book_ctrl.createBook(request.json, dynamoDBInstance)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res,status)
Пример #6
0
def register():
  logger.info(str(request))
  status = 200
  dynamoDBInstance = getDatabaseClient()
  httpOrigin = request.environ.get('HTTP_ORIGIN')
  jsonData = request.json
  res = user_ctrl.register(httpOrigin, jsonData, mail, dynamoDBInstance)
  status = 201
  if res.hasErrors():
    status = 400
  flaskResponse =  ResponseCreation.createResponse(res, status)
  logger.info(str(flaskResponse))
  return flaskResponse
Пример #7
0
def updateClassDetails():
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != 'admin' and role != 'teacher':
    res.addError('Role Error', 'Only teachers or admins can update class details')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.updateClassDetails(request.json, dynamoDBInstance)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res,status)
Пример #8
0
def getBookList():
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res.addError('Role error', 'Only those with teacher privileges can get all books.')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = book_ctrl.getBookList(dynamoDBInstance)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res,status)
Пример #9
0
def taughtClassList():
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != 'teacher' and role != 'admin' :
    res.addError('Role error', 'Only teachers can view a list of classes they are teaching')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.getTaughtClassList(dynamoDBInstance)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res, status)
Пример #10
0
def create_class():
  status = 200

  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res = ResponseCreation.ControllerResponse()
    res.addError('Role error', 'Only teachers can create classes')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.createClass(dynamoDBInstance, request.json)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res, status)
Пример #11
0
def getBook(bookId):
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res.addError('Role error', 'Only those with teacher privileges can get a book.')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    book = book_ctrl.getBook(bookId, dynamoDBInstance)
    if not book:
      res.addError('Data error', 'Unable to retrive book.')
      status = 400
    else:
      res.addToPayload('book', book)
  return ResponseCreation.createResponse(res,status)
Пример #12
0
def removeStudentFromClass():
  status = 200
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res = ResponseCreation.ControllerResponse()
    res.addError('Role error', 'Only those with teacher privileges can remove students from classes')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.removeStudent(dynamoDBInstance, request.json)
    if res.hasErrors():
      status = 400
    else:
      #send email
      class_ctrl.sendClassRemovalEmail(dynamoDBInstance, mail, request.json)
  return ResponseCreation.createResponse(res, status)
Пример #13
0
def getSampleProblems(bookId, chapterTitle, sectionTitle):
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res.addError('Role error', 'Only those with teacher privileges can get sample problems from a book.')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    problemCount = 4
    sampleProblems = set() #prevent duplicates
    for _ in range(problemCount):
      template = problem_ctrl.getProblemFromBook( bookId, chapterTitle, sectionTitle, g.authenticatedUser['email'], dynamoDBInstance)[1]
      sampleProblems.add(algebra.getProblem(template))
    sampleProblems = list(sampleProblems)
    if 'Bad Problem' in sampleProblems:
      status = 400
    else:
      res.addToPayload('problems', sampleProblems)
  return ResponseCreation.createResponse(res, status)
Пример #14
0
def signin():
  logger.info(str(request))
  status = 200

  email = request.authorization.username
  password = request.authorization.password
  dynamoDBInstance = getDatabaseClient()
  userRole = user_ctrl.getRole(email, dynamoDBInstance)
  if not userRole:
    userRole = 'student'
  userCredentials = {
    'email': email,
    'userRole': userRole,
    'password': password
  }

  response = ResponseCreation.ControllerResponse()
  token = MentiiAuth.generateAuthToken(userCredentials, appSecret)
  response.addToPayload('token', token)
  flaskResponse = ResponseCreation.createResponse(response, status)

  logger.info(str(flaskResponse))
  return flaskResponse
Пример #15
0
    else:
      res.addToPayload('problemIndex', index)
  elif request.method == 'POST':
    #Post the students results
    dynamoDBInstance = getDatabaseClient()
    try:
      status = 200
      problemIndex = int(request.json.get('problemIndex', ''))
      didSucceed = request.json.get('didSucceed', 'True') == 'True'
      res = problem_ctrl.updateUserTemplateHistory(classId, activity, userId, problemIndex, didSucceed, dynamoDBInstance)
      if res.hasErrors():
        status = 462
    except ValueError, TypeError:
      pass

  return ResponseCreation.createResponse(res,status)


@app.route('/classes/remove', methods=['POST', 'OPTIONS'])
@auth.login_required
@handleOptionsRequest
def removeStudentFromClass():
  status = 200
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res = ResponseCreation.ControllerResponse()
    res.addError('Role error', 'Only those with teacher privileges can remove students from classes')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.removeStudent(dynamoDBInstance, request.json)