Exemplo n.º 1
0
    def __call__(self, node, value):
        """
            Check if the NIN was not already registered and verified by any user
            Check if the NIN was not already registered by the present user in the
                verifications process.
        """

        from eduiddashboard.models import normalize_nin
        value = normalize_nin(copy(value))

        request = node.bindings.get('request')
        user = request.context.user
        user_nins = user.get_nins()

        unverified_user_nins = request.db.verifications.find({
            'obj_id': value,
            'model_name': 'norEduPersonNIN',
            'user_oid': user.get_id(),
            'verified': False
        })

        # Search the request.POST for any post that starts with "add"
        for post_value in request.POST:
            if post_value.startswith('add'):
                if unverified_user_nins.count() > 0 or value in user_nins:
                    err = _("This national identity number is already in use")
                    raise colander.Invalid(node,
                            get_localizer(request).translate(err))
Exemplo n.º 2
0
    def add_success_other(self, ninform):
        newnin = self.schema.serialize(ninform)
        newnin = newnin['norEduPersonNIN']

        newnin = normalize_nin(newnin)

        old_user = self.request.db.profiles.find_one({
            'norEduPersonNIN': newnin
            })

        if old_user:
            old_user = User(old_user)
            nins = [nin for nin in old_user.get_nins() if nin != newnin]
            old_user.set_nins(nins)
            addresses = [a for a in old_user.get_addresses() if not a['verified']]
            old_user.set_addresses(addresses)
            old_user.save(self.request)

        nins = self.user.get_nins()
        nins.append(newnin)
        self.user.set_nins(nins)

        # Save the state in the verifications collection
        save_as_verificated(self.request, 'norEduPersonNIN',
                            self.user.get_id(), newnin)

        self.user.save(self.request)
        self.request.session.flash(_('Changes saved'),
                                   queue='forms')
Exemplo n.º 3
0
    def __call__(self, node, value):
        """
            Check if the NIN was not already registered and verified by any user
            Check if the NIN was not already registered by the present user in the
                verifications process.
        """

        from eduiddashboard.models import normalize_nin
        value = normalize_nin(copy(value))

        request = node.bindings.get('request')
        user = request.context.user
        user_nins = user.get_nins()

        unverified_user_nins = request.db.verifications.find({
            'obj_id': value,
            'model_name': 'norEduPersonNIN',
            'user_id': user.get_id(),
            'verified': False
        })

        if 'add' in request.POST:
            if unverified_user_nins.count() > 0 or value in user_nins:
                raise colander.Invalid(
                    node,
                    _("This national identity number is already in use"))
Exemplo n.º 4
0
    def addition_with_code_validation(self, form):
        newnin = self.schema.serialize(form)
        newnin = newnin['norEduPersonNIN']

        newnin = normalize_nin(newnin)

        send_verification_code(self.request, self.user, newnin)
Exemplo n.º 5
0
    def addition_with_code_validation(self, form):
        newnin = self.schema.serialize(form)
        newnin = newnin['norEduPersonNIN']
        newnin = normalize_nin(newnin)

        send_verification_code(self.request, self.user, newnin)
        return True
Exemplo n.º 6
0
    def __call__(self, node, value):
        """
        Validator which makes sure that:
        1. the NiN has not already been added by the user
        2. the user does not already have a confirmed NiN.
        """

        from eduiddashboard.models import normalize_nin
        value = normalize_nin(copy(value))

        request = node.bindings.get('request')
        user = get_session_user(request)
        user_nins = user.nins

        unverified_user_nins = request.db.verifications.find({
            'obj_id': value,
            'model_name': 'norEduPersonNIN',
            'user_oid': user.user_id,
            'verified': False
        })

        # Search the request.POST for any post that starts with "add".
        for post_value in request.POST:
            if post_value.startswith('add') and (user_nins.find(value) or
                                      unverified_user_nins.count() > 0):
                err = _('National identity number already added')
                raise colander.Invalid(node, get_localizer(request).translate(err))

            elif post_value.startswith('add') and user_nins.count > 0:
                err = _('You already have a confirmed national identity number')
                raise colander.Invalid(node, get_localizer(request).translate(err))
Exemplo n.º 7
0
    def __call__(self, node, value):
        """
        Validator which makes sure that:
        1. the NiN has not already been added by the user
        2. the user does not already have a confirmed NiN.
        """

        from eduiddashboard.models import normalize_nin
        value = normalize_nin(copy(value))

        request = node.bindings.get('request')
        user = request.context.user
        user_nins = user.nins

        unverified_user_nins = request.db.verifications.find({
            'obj_id': value,
            'model_name': 'norEduPersonNIN',
            'user_oid': user.user_id,
            'verified': False
        })

        # Search the request.POST for any post that starts with "add".
        for post_value in request.POST:
            if post_value.startswith('add') and (
                    user_nins.find(value) or unverified_user_nins.count() > 0):
                err = _('National identity number already added')
                raise colander.Invalid(node,
                                       get_localizer(request).translate(err))

            elif post_value.startswith('add') and user_nins.count > 0:
                err = _(
                    'You already have a confirmed national identity number')
                raise colander.Invalid(node,
                                       get_localizer(request).translate(err))
Exemplo n.º 8
0
    def __call__(self, node, value):
        """
            Check is the NIN is reachable by eduid_msg service through
            Mina Meddelanden service
        """

        from eduiddashboard.models import normalize_nin

        value = normalize_nin(copy(value))
        request = node.bindings.get('request')
        settings = request.registry.settings

        if settings.get('developer_mode', False):
            return

        msg = None
        try:
            reachable = request.msgrelay.nin_reachable(value)
        except request.msgrelay.TaskFailed:
            msg = _('Sorry, we are experiencing temporary technical '
                    'problem with ${service_name}, please try again '
                    'later.')
            reachable = 'Failed'

        if reachable is False:
            msg = _(
                'This national identity number is '
                'not registered with "${service_name}". Please register '
                'at <a href="${service_url}" target="_blank">${service_name}</a>.'
            )

        elif reachable is 'Anonymous':
            msg = _(
                'Your registration process with '
                '"${service_name}" is not complete. Please visit <a href='
                '"${service_url}" target="_blank">${service_name}</a> to complete your registration.'
            )

        elif reachable is 'Sender_not':
            msg = _(
                'According to "${service_name}"'
                ' you have opted out to receive messages from SUNET (eduID). In'
                ' order to receive a confirmation code from us, you need to'
                ' accept SUNET (eduID) as a sender at <a href="${service_url}" target="_blank">'
                '${service_name}</a>.')

        if msg:
            localizer = get_localizer(request)
            raise colander.Invalid(
                node,
                localizer.translate(msg,
                                    mapping={
                                        'service_name':
                                        settings.get('nin_service_name'),
                                        'service_url':
                                        settings.get('nin_service_url'),
                                    }))
Exemplo n.º 9
0
    def __call__(self, node, value):

        from eduiddashboard.models import normalize_nin
        value = normalize_nin(copy(value))
        request = node.bindings.get('request')
        try:
            request.userdb.get_user_by_nin(value)
        except UserDB.UserDoesNotExist:
            raise colander.Invalid(node,
                                   _("This national identity number does not exist, is not verified or is not active"))
Exemplo n.º 10
0
    def __call__(self, node, value):

        from eduiddashboard.models import normalize_nin
        value = normalize_nin(copy(value))
        request = node.bindings.get('request')
        try:
            request.userdb.get_user_by_nin(value)
        except UserDB.UserDoesNotExist:
            err = _("This national identity number does not exist, "
                    "is not verified or is not active")
            raise colander.Invalid(node, get_localizer(request).translate(err))
Exemplo n.º 11
0
def send_verification_code(request, user, nin, reference=None, code=None):
    """
    You need to replace the call to dummy_message with the govt
    message api
    """

    # Always normalize the nin before usage
    nin = normalize_nin(nin)

    if code is None or reference is None:
        reference, code = new_verification_code(request, 'norEduPersonNIN', nin, user, hasher=get_short_hash)

    language = request.context.get_preferred_language()

    request.msgrelay.nin_validator(reference, nin, code, language, nin, message_type='mm')
    request.stats.count('nin_send_verification_code')
Exemplo n.º 12
0
def send_verification_code(request, user, nin, reference=None, code=None):
    """
    You need to replace the call to dummy_message with the govt
    message api
    """

    # Always normalize the nin before usage
    nin = normalize_nin(nin)

    if code is None or reference is None:
        reference, code = new_verification_code(request, 'norEduPersonNIN', nin, user, hasher=get_short_hash)

    language = request.context.get_preferred_language()

    request.msgrelay.nin_validator(reference, nin, code, language, nin, message_type='mm')
    request.stats.count('dashboard/nin_send_verification_code', 1)
Exemplo n.º 13
0
    def __call__(self, node, value):
        """
            Check is the NIN is reachable by eduid_msg service through
            Mina Meddelanden service
        """

        from eduiddashboard.models import normalize_nin

        value = normalize_nin(copy(value))
        request = node.bindings.get('request')
        settings = request.registry.settings

        if settings.get('developer_mode', False):
            return
        
        msg = None
        try:
            reachable = request.msgrelay.nin_reachable(value)
        except request.msgrelay.TaskFailed:
            msg = _('Sorry, we are experiencing temporary technical '
                    'problem with ${service_name}, please try again '
                    'later.')
            reachable = 'Failed'

        if reachable is False:
            msg = _('This national identity number is '
                    'not registered with "${service_name}". Please register '
                    'at <a href="${service_url}" target="_blank">${service_name}</a>.')

        elif reachable is 'Anonymous':
            msg = _('Your registration process with '
                    '"${service_name}" is not complete. Please visit <a href='
                    '"${service_url}" target="_blank">${service_name}</a> to complete your registration.')

        elif reachable is 'Sender_not':
            msg = _('According to "${service_name}"'
                    ' you have opted out to receive messages from SUNET (eduID). In'
                    ' order to receive a confirmation code from us, you need to'
                    ' accept SUNET (eduID) as a sender at <a href="${service_url}" target="_blank">'
                    '${service_name}</a>.')

        if msg:
            localizer = get_localizer(request)
            raise colander.Invalid(node, localizer.translate(msg, mapping={
                'service_name': settings.get('nin_service_name'),
                'service_url': settings.get('nin_service_url'),
            }))
Exemplo n.º 14
0
    def step_1(self, data):
        """ The verification code form """
        nins_action_view = NINsActionsView(self.context, self.request)

        result = nins_action_view._verify_action(normalize_nin(self.datakey), data)

        if result['result'] == 'ok':
            return {
                'status': 'ok',
            }
        else:
            return {
                'status': 'failure',
                'data': {
                    'code': result['message']
                }
            }
Exemplo n.º 15
0
    def add_by_mobile_success(self, ninform):
        """ This method is bounded to the "add_by_mobile"-button by it's name """
        newnin = self.schema.serialize(ninform)
        newnin = newnin['norEduPersonNIN']
        newnin = normalize_nin(newnin)

        self.user = get_session_user(self.request)
        message = set_nin_verified(self.request, self.user, newnin)

        try:
            self.request.context.save_dashboard_user(self.user)
        except UserOutOfSync:
            log.info("Failed to save user {!r} after mobile phone vetting. User out of sync.".format(self.user))
            raise

        log.info("Saved user {!r} after NIN vetting using mobile phone".format(self.user))
        self.request.session.flash(
            get_localizer(self.request).translate(message),
            queue='forms')

        self.request.stats.count('nin_add_mobile')
Exemplo n.º 16
0
    def add_by_letter_success(self, ninform):
        """
        This method is bound to the "add_by_letter"-button by it's name
        """
        form = self.schema.serialize(ninform)
        nin = normalize_nin(form['norEduPersonNIN'])
        session_user = get_session_user(self.request)

        # self.user needs to be a new user in get_template_context
        self.user = session_user

        result = letter_status(self.request, session_user, nin)
        if result['result'] == 'success':
            result2 = send_letter(self.request, session_user, nin)
            if result2['result'] == 'success':
                new_verification_code(self.request, 'norEduPersonNIN',
                                      nin, session_user)
            msg = result2['message']
        else:
            msg = result['message']
        self.request.session.flash(msg, queue='forms')
Exemplo n.º 17
0
    def add_by_mobile_success(self, ninform):
        """ This method is bounded to the "add_by_mobile"-button by it's name """
        newnin = self.schema.serialize(ninform)
        newnin = newnin['norEduPersonNIN']
        newnin = normalize_nin(newnin)

        self.user = get_session_user(self.request)
        message = set_nin_verified(self.request, self.user, newnin)

        try:
            self.request.context.save_dashboard_user(self.user)
        except UserOutOfSync:
            log.info("Failed to save user {!r} after mobile phone vetting. User out of sync.".format(self.user))
            raise

        log.info("Saved user {!r} after NIN vetting using mobile phone".format(self.user))
        self.request.session.flash(
            get_localizer(self.request).translate(message),
            queue='forms')

        self.request.stats.count('dashboard/nin_add_mobile', 1)
Exemplo n.º 18
0
    def add_by_letter_success(self, ninform):
        """
        This method is bound to the "add_by_letter"-button by it's name
        """
        form = self.schema.serialize(ninform)
        nin = normalize_nin(form['norEduPersonNIN'])
        session_user = get_session_user(self.request)

        # self.user needs to be a new user in get_template_context
        self.user = session_user

        result = letter_status(self.request, session_user, nin)
        if result['result'] == 'success':
            result2 = send_letter(self.request, session_user, nin)
            if result2['result'] == 'success':
                new_verification_code(self.request, 'norEduPersonNIN',
                                      nin, session_user)
            msg = result2['message']
        else:
            msg = result['message']
        self.request.session.flash(msg, queue='forms')
Exemplo n.º 19
0
    def add_success_other(self, ninform):
        newnin = self.schema.serialize(ninform)
        newnin = newnin['norEduPersonNIN']

        newnin = normalize_nin(newnin)

        old_user = self.request.db.profiles.find_one({
            'norEduPersonNIN': newnin
            })

        if old_user:
            old_user = OldUser(old_user)
            old_user.retrieve_modified_ts(self.request.db.profiles)
            nins = [nin for nin in old_user.get_nins() if nin != newnin]
            old_user.set_nins(nins)
            addresses = [a for a in old_user.get_addresses() if not a['verified']]
            old_user.set_addresses(addresses)
            old_user.save(self.request)

        nins = self.user.get_nins()
        nins.append(newnin)
        self.user.set_nins(nins)
        self.user.retrieve_address(self.request, newnin)

        try:
            self.user.save(self.request)
        except UserOutOfSync:
            message = _('Your user profile is out of sync. Please '
                        'reload the page and try again.')
        else:
            message = _('Your national identity number has been confirmed')
        # Save the state in the verifications collection
        save_as_verified(self.request, 'norEduPersonNIN',
                            self.user, newnin)
        self.request.session.flash(
                get_localizer(self.request).translate(message),
                queue='forms')
        self.request.stats.count('dashboard/nin_add_other', 1)
Exemplo n.º 20
0
    def add_success_other(self, ninform):
        newnin = self.schema.serialize(ninform)
        newnin = newnin['norEduPersonNIN']

        newnin = normalize_nin(newnin)

        old_user = self.request.db.profiles.find_one({
            'norEduPersonNIN': newnin
            })

        if old_user:
            old_user = DashboardUser(data=old_user)
            retrieve_modified_ts(old_user, self.request.dashboard_userdb)
            old_user.nins.remove(newnin)
            self.context.save_dashboard_user(old_user)

        primary = False
        if self.user.nins.count == 0:
            primary = True
        newnin_obj = Nin(number=newnin, application='dashboard',
                verified=True, primary=primary)
        self.user.nins.add(newnin_obj)

        try:
            self.context.save_dashboard_user(self.user)
        except UserOutOfSync:
            message = _('Your user profile is out of sync. Please '
                        'reload the page and try again.')
        else:
            message = _('Your national identity number has been confirmed')
        # Save the state in the verifications collection
        save_as_verified(self.request, 'norEduPersonNIN', self.user, newnin)
        self.request.session.flash(
                get_localizer(self.request).translate(message),
                queue='forms')
        self.request.stats.count('nin_add_other')