Exemplo n.º 1
0
    def post(id_user):
        screen_name = request.form.get('screenname')

        # Validate required fields
        validation = Validation()
        validation.add_required_field('id-user', id_user)
        validation.add_required_field('screenname', screen_name)
        if not validation.is_valid():
            return validation.get_validation_response()

        # Validate the id parameter as an integer
        try:
            id_user = int(id_user)

        except ValueError:
            return Failures.not_a_number('idUser', id_user)

        # Validate user exists, is validated and is not blocked
        user = user_service.get_user(id_user)

        if user is None:
            return Failures.unknown_user_id(id_user)

        # Attempt to retrieve the proposed screen name to ensure that it is available
        user_by_email = user_service.get_user_by_screen_name(screen_name)

        if user_by_email is not None:
            if user.id != user_by_email.id:
                return Failures.screen_name_already_in_use(screen_name)

        # The screen name is available, Assign it to the user profile
        user.screen_name = screen_name
        db.session.commit()

        logging.info('User-controller: doInfoChange: success: %s (%s)',
                     id_user, user.screen_name)

        return {
            'success': True,
            'user': {
                'id': user.id,
                'email': user.email,
                'locale': user.locale,
                'screenname': user.screen_name,
                'authentication-source': user.auth_source,
                'bdmonth': user.birth_month,
                'bdyear': user.birth_year,
                'parent-email': user.parent_email,
                'parent-email-source': user.parent_email_source
            }
        }
Exemplo n.º 2
0
    def post(self):
        # Get values
        server = request.headers.get('server')
        email = request.form.get('email')
        password = request.form.get('password')
        password_confirm = request.form.get('password-confirm')
        locale = request.form.get('locale')
        screen_name = request.form.get('screenname')

        # Validate required fields
        validation = Validation()
        validation.add_required_field('server', server)
        validation.add_required_field('email', email)
        validation.add_required_field('password', password)
        validation.add_required_field('password-confirm', password_confirm)
        validation.add_required_field('locale', locale)
        validation.add_required_field('screenname', screen_name)
        validation.check_email('email', email)
        if not validation.is_valid():
            return validation.get_validation_response()

        # Validate email is not yet used
        existing_user = user_service.get_user_by_email(email)
        if existing_user is not None:
            return Failures.email_already_in_use(email)

        # Validate screen name is not yet used
        existing_user = user_service.get_user_by_screen_name(screen_name)
        if existing_user is not None:
            return Failures.screen_name_already_in_use(screen_name)

        # Validate password strength and confirm
        if password != password_confirm:
            return Failures.passwords_do_not_match()
        if not user_service.check_password_complexity(password):
            return Failures.password_complexity()

        id_user = user_service.create_local_user(server, email, password,
                                                 locale, screen_name)
        user_service.send_email_confirm(id_user, server)

        db.session.commit()

        logging.info('User-controller: register success: %s', id_user)

        # Create user
        return {'success': True, 'user': id_user}
Exemplo n.º 3
0
    def post(id_user):
        screen_name = request.form.get('screenname')

        # Validate required fields
        validation = Validation()
        validation.add_required_field('id-user', id_user)
        validation.add_required_field('screenname', screen_name)
        if not validation.is_valid():
            return validation.get_validation_response()

        # Validate the id parameter as an integer
        try:
            id_user = int(id_user)

        except ValueError:
            return Failures.not_a_number('idUser', id_user)

        # Validate user exists, is validated and is not blocked
        user = user_service.get_user(id_user)

        if user is None:
            return Failures.unknown_user_id(id_user)

        # Attempt to retrieve the proposed screen name to ensure that it is available
        user_by_email = user_service.get_user_by_screen_name(screen_name)

        if user_by_email is not None:
            if user.id != user_by_email.id:
                return Failures.screen_name_already_in_use(screen_name)

        # The screen name is available, Assign it to the user profile
        user.screen_name = screen_name
        db.session.commit()

        logging.info('User-controller: doInfoChange: success: %s (%s)', id_user, user.screen_name)

        return {'success': True, 'user': {
            'id': user.id,
            'email': user.email,
            'locale': user.locale,
            'screenname': user.screen_name,
            'authentication-source': user.auth_source,
            'bdmonth': user.birth_month,
            'bdyear': user.birth_year,
            'parent-email': user.parent_email,
            'parent-email-source': user.parent_email_source
        }}
Exemplo n.º 4
0
    def get(self, screen_name):
        # Validate user exists, is validated and is not blocked
        user = user_service.get_user_by_screen_name(screen_name)
        if user is None:
            return Failures.unknown_user_screen_name(screen_name)

        logging.info('User-controller: getUserByScreenname: success: %s (%s)',
                     screen_name, user.screen_name)

        return {
            'success': True,
            'user': {
                'id': user.id,
                'email': user.email,
                'locale': user.locale,
                'screenname': user.screen_name,
                'authentication-source': user.auth_source
            }
        }
Exemplo n.º 5
0
    def get(screen_name):
        # Validate user exists, is validated and is not blocked
        user = user_service.get_user_by_screen_name(screen_name)

        if user is None:
            return Failures.unknown_user_screen_name(screen_name)

        logging.info('User-controller: getUserByScreenname: success: %s (%s)', screen_name, user.screen_name)

        return {'success': True, 'user': {
            'id': user.id,
            'email': user.email,
            'locale': user.locale,
            'screenname': user.screen_name,
            'authentication-source': user.auth_source,
            'bdmonth': user.birth_month,
            'bdyear': user.birth_year,
            'parent-email': user.parent_email,
            'parent-email-source': user.parent_email_source
        }}
Exemplo n.º 6
0
    def post(self, id_user):
        screen_name = request.form.get('screenname')
        # Validate required fields
        validation = Validation()
        validation.add_required_field('id-user', id_user)
        validation.add_required_field('screenname', screen_name)
        if not validation.is_valid():
            return validation.get_validation_response()

        # Parse numbers
        try:
            id_user = int(id_user)
        except:
            return Failures.not_a_number('idUser', id_user)

        # Validate user exists, is validated and is not blocked
        user = user_service.get_user(id_user)
        if user is None:
            return Failures.unknown_user_id(id_user)

        user_by_email = user_service.get_user_by_screen_name(screen_name)
        if user_by_email is not None:
            if user.id != user_by_email.id:
                return Failures.screen_name_already_in_use(screen_name)

        user.screen_name = screen_name
        db.session.commit()

        logging.info('User-controller: doInfoChange: success: %s (%s)',
                     id_user, user.screen_name)

        return {
            'success': True,
            'user': {
                'id': user.id,
                'email': user.email,
                'locale': user.locale,
                'screenname': user.screen_name,
                'authentication-source': user.auth_source
            }
        }
Exemplo n.º 7
0
    def post(self):
        # Get values
        server = request.headers.get('server')
        email = request.form.get('email')
        locale = request.form.get('locale')
        screen_name = request.form.get('screenname')
        source = request.form.get('source')

        # Validate required fields
        validation = Validation()
        validation.add_required_field('server', server)
        validation.add_required_field('email', email)
        validation.add_required_field('locale', locale)
        validation.add_required_field('screenname', screen_name)
        validation.add_required_field('source', source)
        validation.check_email('email', email)
        if not validation.is_valid():
            return validation.get_validation_response()

        # Validate email is not yet used
        existing_user = user_service.get_user_by_email(email)
        if existing_user is not None:
            return Failures.email_already_in_use(email)

        # Validate screen name is not yet used
        existing_user = user_service.get_user_by_screen_name(screen_name)
        if existing_user is not None:
            return Failures.screen_name_already_in_use(screen_name)

        id_user = user_service.create_oauth_user(server, email, source, locale, screen_name)

        db.session.commit()

        logging.info('OAuth-controller: create success: %s', id_user)

        # Create user
        return {'success': True, 'user': id_user}
Exemplo n.º 8
0
    def post():
        # Get values
        server = request.headers.get('server')
        email = request.form.get('email')
        password = request.form.get('password')
        password_confirm = request.form.get('password-confirm')
        locale = request.form.get('locale')
        screen_name = request.form.get('screenname')

        # COPPA support
        birth_month = request.form.get('bdmonth')
        birth_year = request.form.get('bdyear')
        parent_email = request.form.get('parent-email')
        parent_email_source = request.form.get('parent-email-source')

        # Validate required fields
        validation = Validation()
        validation.add_required_field('server', server)
        validation.add_required_field('email', email)
        validation.add_required_field('password', password)
        validation.add_required_field('password-confirm', password_confirm)
        validation.add_required_field('locale', locale)
        validation.add_required_field('screenname', screen_name)

        # COPPA support
        validation.add_required_field('bdmonth', birth_month)
        validation.add_required_field('bdyear', birth_year)
        if parent_email:
            validation.check_email('parent-email', parent_email)
            if not validation.is_valid():
                return validation.get_validation_response()

        # Verify user email address
        validation.check_email('email', email)
        if not validation.is_valid():
            return validation.get_validation_response()

        # Validate email is not yet used
        existing_user = user_service.get_user_by_email(email)
        if existing_user is not None:
            return Failures.email_already_in_use(email)

        # Validate screen name is not yet used
        existing_user = user_service.get_user_by_screen_name(screen_name)
        if existing_user is not None:
            return Failures.screen_name_already_in_use(screen_name)

        # Validate password strength and confirm
        if password != password_confirm:
            return Failures.passwords_do_not_match()
        if not user_service.check_password_complexity(password):
            return Failures.password_complexity()

        # Write user details to the database
        id_user = user_service.create_local_user(server, email, password,
                                                 locale, screen_name,
                                                 birth_month, birth_year,
                                                 parent_email,
                                                 parent_email_source)

        # Send a confirmation request email to user or parent
        (result, errno,
         mesg) = user_service.send_email_confirm(id_user, server)
        if result:
            # Commit the database record
            db.session.commit()
            logging.info('User-controller: register success: %s', id_user)

            # Create user
            return {'success': True, 'user': id_user}
        else:
            logging.error("Unable to register user. Error %s: %s", errno, mesg)
            return {'success': False, 'user': 0}
Exemplo n.º 9
0
    def post():
        # Get values
        server = request.headers.get('server')
        email = request.form.get('email')
        password = request.form.get('password')
        password_confirm = request.form.get('password-confirm')
        locale = request.form.get('locale')
        screen_name = request.form.get('screenname')

        # COPPA support
        birth_month = request.form.get('bdmonth')
        birth_year = request.form.get('bdyear')
        parent_email = request.form.get('parent-email')
        parent_email_source = request.form.get('parent-email-source')

        # Validate required fields
        validation = Validation()
        validation.add_required_field('server', server)
        validation.add_required_field('email', email)
        validation.add_required_field('password', password)
        validation.add_required_field('password-confirm', password_confirm)
        validation.add_required_field('locale', locale)
        validation.add_required_field('screenname', screen_name)

        # COPPA support
        validation.add_required_field('bdmonth', birth_month)
        validation.add_required_field('bdyear', birth_year)
        if parent_email:
            validation.check_email('parent-email', parent_email)
            if not validation.is_valid():
                return validation.get_validation_response()

        # Verify user email address
        validation.check_email('email', email)
        if not validation.is_valid():
            return validation.get_validation_response()

        # Validate email is not yet used
        existing_user = user_service.get_user_by_email(email)
        if existing_user is not None:
            return Failures.email_already_in_use(email)

        # Validate screen name is not yet used
        existing_user = user_service.get_user_by_screen_name(screen_name)
        if existing_user is not None:
            return Failures.screen_name_already_in_use(screen_name)

        # Validate password strength and confirm
        if password != password_confirm:
            return Failures.passwords_do_not_match()
        if not user_service.check_password_complexity(password):
            return Failures.password_complexity()

        # Write user details to the database
        id_user = user_service.create_local_user(
            server, email, password, locale, screen_name,
            birth_month, birth_year, parent_email, parent_email_source)

        # Send a confirmation request email to user or parent
        (result, errno, mesg) = user_service.send_email_confirm(id_user, server)
        if result:
            # Commit the database record
            db.session.commit()
            logging.info('User-controller: register success: %s', id_user)

            # Create user
            return {'success': True, 'user': id_user}
        else:
            logging.error("Unable to register user. Error %s: %s", errno, mesg)
            return {'success': False, 'user': 0}