def verify_nin(request, user, new_nin, reference): log.info('Trying to verify NIN for user {!r}.'.format(user)) log.debug('NIN: {!s}.'.format(new_nin)) # Start by removing nin from any other user old_user_docs = request.db.profiles.find({ 'norEduPersonNIN': new_nin }) steal_count = 0 for old_user_doc in old_user_docs: old_user = User(old_user_doc) if old_user: log.debug('Found old user {!r} with NIN ({!s}) already verified.'.format(old_user, new_nin)) log.debug('Old user NINs BEFORE: {!r}.'.format(old_user.get_nins())) nins = [nin for nin in old_user.get_nins() if nin != new_nin] old_user.set_nins(nins) log.debug('Old user NINs AFTER: {!r}.'.format(old_user.get_nins())) log.debug('Old user addresses BEFORE: {!r}.'.format(old_user.get_addresses())) addresses = [a for a in old_user.get_addresses() if not a['verified']] old_user.set_addresses(addresses) log.debug('Old user addresses AFTER: {!r}.'.format(old_user.get_addresses())) old_user.retrieve_modified_ts(request.db.profiles) old_user.save(request) log.info('Removed NIN and associated addresses from user {!r}.'.format(old_user)) steal_count += 1 # Add the verified nin to the requesting user user.add_verified_nin(new_nin) user.retrieve_address(request, new_nin) # Connect the verification to the transaction audit log request.msgrelay.postal_address_to_transaction_audit_log(reference) # Reset session eduPersonIdentityProofing on NIN verification request.session['eduPersonIdentityProofing'] = None log.info('NIN verified for user {!r}.'.format(user)) request.stats.count('dashboard/verify_nin_stolen', steal_count) request.stats.count('dashboard/verify_nin_completed', 1) return user, _('National identity number {obj} verified')
def verify_mobile(request, user, new_mobile): log.info('Trying to verify mobile number for user {!r}.'.format(user)) log.debug('Mobile number: {!s}.'.format(new_mobile)) # Start by removing mobile number from any other user old_user_docs = request.db.profiles.find({ 'mobile': {'$elemMatch': {'mobile': new_mobile, 'verified': True}} }) steal_count = 0 for old_user_doc in old_user_docs: old_user = User(old_user_doc) if old_user: log.debug('Found old user {!r} with mobile number ({!s}) already verified.'.format(old_user, new_mobile)) log.debug('Old user mobile numbers BEFORE: {!r}.'.format(old_user.get_mobiles())) mobiles = [m for m in old_user.get_mobiles() if m['mobile'] != new_mobile] old_user.set_mobiles(mobiles) log.debug('Old user mobile numbers AFTER: {!r}.'.format(old_user.get_mobiles())) old_user.retrieve_modified_ts(request.db.profiles) old_user.save(request) log.info('Removed mobile number from user {!r}.'.format(old_user)) steal_count += 1 # Add the verified mobile number to the requesting user user.add_verified_mobile(new_mobile) log.info('Mobile number verified for user {!r}.'.format(user)) request.stats.count('dashboard/verify_mobile_stolen', steal_count) request.stats.count('dashboard/verify_mobile_completed', 1) return user, _('Mobile {obj} verified')
def verify_mail(request, user, new_mail): log.info('Trying to verify mail address for user {!r}.'.format(user)) log.debug('Mail address: {!s}.'.format(new_mail)) # Start by removing mail address from any other user old_user_docs = request.db.profiles.find({ 'mailAliases': {'$elemMatch': {'email': new_mail, 'verified': True}} }) steal_count = 0 for old_user_doc in old_user_docs: old_user = User(old_user_doc) if old_user: log.debug('Found old user {!r} with mail address ({!s}) already verified.'.format(old_user, new_mail)) log.debug('Old user mail BEFORE: {!s}.'.format(old_user.get_mail())) log.debug('Old user mail aliases BEFORE: {!r}.'.format(old_user.get_mail_aliases())) if old_user.get_mail() == new_mail: old_user.set_mail('') mails = [m for m in old_user.get_mail_aliases() if m['email'] != new_mail] old_user.set_mail_aliases(mails) log.debug('Old user mail AFTER: {!s}.'.format(old_user.get_mail())) log.debug('Old user mail aliases AFTER: {!r}.'.format(old_user.get_mail_aliases())) old_user.retrieve_modified_ts(request.db.profiles) old_user.save(request) steal_count += 1 # Add the verified mail address to the requesting user user.add_verified_email(new_mail) log.info('Mail address verified for user {!r}.'.format(user)) request.stats.count('dashboard/verify_mail_stolen', steal_count) request.stats.count('dashboard/verify_mail_completed', 1) return user, _('Email {obj} verified')
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) 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 = _('User data out of sync. Please 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.get_id(), newnin) self.request.session.flash( get_localizer(self.request).translate(message), queue='forms') self.request.stats.count('dashboard/nin_add_other', 1)