コード例 #1
0
ファイル: test_user_ctrl.py プロジェクト: mentii/mentii
    def test_addDataToClassAndUser(self):
        userRole = 'student'
        email = '*****@*****.**'
        classCode = 'abcef12345'
        title = 'some class'
        response = ControllerResponse()

        # add student to user table
        usersTable = db.getTable('users', dynamodb)
        jsonData = {'email': email}
        db.putItem(jsonData, usersTable)

        # add class to class table
        classesTable = db.getTable('classes', dynamodb)
        jsonData = {'code': classCode, 'title': title}
        db.putItem(jsonData, classesTable)

        usr.addDataToClassAndUser(classCode, email, response, dynamodb)
        self.assertFalse(response.hasErrors())
        self.assertEqual(response.payload['title'], title)
        self.assertEqual(response.payload['code'], classCode)
コード例 #2
0
def register(httpOrigin, jsonData, mailer, dbInstance):
  response = ControllerResponse()
  if not validateRegistrationJSON(jsonData):
    response.addError('Register Validation Error', 'The json data did not have an email or did not have a password')
  else:
    email = parseEmail(jsonData)
    password = parsePassword(jsonData)

    if not isEmailValid(email):
      response.addError('Email invalid', 'The email is invalid')

    if not isPasswordValid(password):
      response.addError('Password Invalid', 'The password is invalid')

    if isEmailInSystem(email, dbInstance) and isUserActive(getUserByEmail(email, dbInstance)):
      response.addError('Registration Failed', 'We were unable to register this user')

    if not response.hasErrors():
      hashedPassword = hashPassword(parsePassword(jsonData))
      activationId = addUserAndSendEmail(httpOrigin, email, hashedPassword, mailer, dbInstance)
      if activationId is None:
        response.addError('Activation Id is None', 'Could not create an activation Id')

  return response
コード例 #3
0
ファイル: class_ctrl.py プロジェクト: mentii/mentii
def removeStudent(dynamoDBInstance, jsonData, response=None, userRole=None):
    currentUserEmail = None
    if response is None:
        response = ControllerResponse()
    email = jsonData.get('email')
    classCode = jsonData.get('classCode')
    if g:
        userRole = g.authenticatedUser['userRole']
        currentUserEmail = g.authenticatedUser['email']
    if not (userRole == 'teacher' or userRole == 'admin'
            or currentUserEmail == email):
        response.addError(
            'Role error',
            'Only those with teacher privileges can remove students from classes'
        )
    elif email is None or classCode is None:
        response.addError('Failed to remove student from class',
                          'Invalid data given')
    else:
        removeClassFromStudent(dynamoDBInstance, response, email, classCode)
        if not response.hasErrors():
            removeStudentFromClass(dynamoDBInstance, response, email,
                                   classCode)
    return response