def letter_proof_user(): description = """\ Apply verification returned by eduid-idproofing-letter after failure. The JSON data is found in the eduid-idproofing-letter log after a users successful verification. Example: 'letter_proof_user eppn idproofing-letter-json-data' """ usage = "usage: %prog eppn idproofing-letter-json-data" parser = optparse.OptionParser( usage=usage, description=textwrap.dedent(description) ) options, args = parser.parse_args(sys.argv[1:]) if not len(args) == 2: print('Two arguments required') print(usage) return 2 env = bootstrap(default_config_file) eppn = args[0] data = args[1] rdata = json.loads(data) user = _get_user_by_eppn(env['request'], eppn, legacy_user=False) if not user.nins.to_list() and rdata.get('verified', False): # Save data from successful verification call for later addition to user proofing collection rdata['created_ts'] = datetime.utcfromtimestamp(int(rdata['created_ts'])) rdata['verified_ts'] = datetime.utcfromtimestamp(int(rdata['verified_ts'])) user = DashboardUser(data = user.to_dict()) user.add_letter_proofing_data(rdata) # Look up users official address at the time of verification per Kantara requirements print "Looking up address via Navet for user {!r}.".format(user) user_postal_address = env['request'].msgrelay.get_full_postal_address(rdata['number']) print "Finished looking up address via Navet for user {!r}.".format(user) proofing_data = LetterProofing(user, rdata['number'], rdata['official_address'], rdata['transaction_id'], user_postal_address) # Log verification event and fail if that goes wrong print "Logging proofing data for user {!r}.".format(user) if env['request'].idproofinglog.log_verification(proofing_data): print "Finished logging proofing data for user {!r}.".format(user) try: # This is a hack to reuse the existing proofing functionality, the users code is # verified by the micro service set_nin_verified(env['request'], user, rdata['number']) try: env['request'].context.save_dashboard_user(user) except UserOutOfSync: print 'Verified norEduPersonNIN NOT saved for user {!r}. User out of sync.'.format(user) raise save_as_verified(env['request'], 'norEduPersonNIN', user, rdata['number']) print "Verified NIN by physical letter saved for user {!r}.".format(user) except UserOutOfSync: print "Verified NIN by physical letter NOT saved for user {!r}. User out of sync.".format(user) else: print 'You have successfully verified the identity for user {!r}'.format(user) else: print 'User {!r} already has verified NIN ({!s}).'.format(user, user.nins)
def save_dashboard_user(user): """ Save (new) user objects to the dashboard db in the new format, and propagate the changes to the central user db. May raise UserOutOfSync exception :param user: the modified user :type user: eduid_userdb.dashboard.user.DashboardUser """ if isinstance(user, User) and not isinstance(user, DashboardUser): # turn it into a DashboardUser before saving it in the dashboard private db user = DashboardUser(data=user.to_dict()) current_app.dashboard_userdb.save(user) return current_app.am_relay.request_user_sync(user)
def save_dashboard_user(self, user): """ Save (new) user objects to the dashboard db in the new format, and propagate the changes to the central user db. May raise UserOutOfSync exception :param user: the modified user :type user: eduid_userdb.dashboard.user.DashboardUser """ if isinstance(user, User): # turn it into a DashboardUser before saving it in the dashboard private db user = DashboardUser(data = user.to_dict()) self.request.dashboard_userdb.save(user, old_format=False) self.propagate_user_changes(user)
def save_dashboard_user(self, user): """ Save (new) user objects to the dashboard db in the new format, and propagate the changes to the central user db. May raise UserOutOfSync exception :param user: the modified user :type user: eduid_userdb.dashboard.user.DashboardUser """ if isinstance(user, User): # turn it into a DashboardUser before saving it in the dashboard private db user = DashboardUser(data=user.to_dict()) self.request.dashboard_userdb.save(user, old_format=False) self.propagate_user_changes(user)
def save_dashboard_user(user): """ Save (new) user objects to the dashboard db in the new format, and propagate the changes to the central user db. May raise UserOutOfSync exception :param user: the modified user :type user: eduid_userdb.dashboard.user.DashboardUser """ if isinstance(user, User) and not isinstance(user, DashboardUser): # turn it into a DashboardUser before saving it in the dashboard private db user = DashboardUser(data = user.to_dict()) current_app.dashboard_userdb.save(user) return current_app.am_relay.request_user_sync(user)
def letter_proof_user(): description = """\ Apply verification returned by eduid-idproofing-letter after failure. The JSON data is found in the eduid-idproofing-letter log after a users successful verification. Example: 'letter_proof_user eppn idproofing-letter-json-data' """ usage = "usage: %prog eppn idproofing-letter-json-data" parser = optparse.OptionParser(usage=usage, description=textwrap.dedent(description)) options, args = parser.parse_args(sys.argv[1:]) if not len(args) == 2: print('Two arguments required') print(usage) return 2 env = bootstrap(default_config_file) eppn = args[0] data = args[1] rdata = json.loads(data) user = _get_user_by_eppn(env['request'], eppn, legacy_user=False) if not user.nins.to_list() and rdata.get('verified', False): # Save data from successful verification call for later addition to user proofing collection rdata['created_ts'] = datetime.utcfromtimestamp( int(rdata['created_ts'])) rdata['verified_ts'] = datetime.utcfromtimestamp( int(rdata['verified_ts'])) user = DashboardUser(data=user.to_dict()) user.add_letter_proofing_data(rdata) # Look up users official address at the time of verification per Kantara requirements print "Looking up address via Navet for user {!r}.".format(user) user_postal_address = env['request'].msgrelay.get_full_postal_address( rdata['number']) print "Finished looking up address via Navet for user {!r}.".format( user) proofing_data = LetterProofing(user, rdata['number'], rdata['official_address'], rdata['transaction_id'], user_postal_address) # Log verification event and fail if that goes wrong print "Logging proofing data for user {!r}.".format(user) if env['request'].idproofinglog.log_verification(proofing_data): print "Finished logging proofing data for user {!r}.".format(user) try: # This is a hack to reuse the existing proofing functionality, the users code is # verified by the micro service set_nin_verified(env['request'], user, rdata['number']) try: env['request'].context.save_dashboard_user(user) except UserOutOfSync: print 'Verified norEduPersonNIN NOT saved for user {!r}. User out of sync.'.format( user) raise save_as_verified(env['request'], 'norEduPersonNIN', user, rdata['number']) print "Verified NIN by physical letter saved for user {!r}.".format( user) except UserOutOfSync: print "Verified NIN by physical letter NOT saved for user {!r}. User out of sync.".format( user) else: print 'You have successfully verified the identity for user {!r}'.format( user) else: print 'User {!r} already has verified NIN ({!s}).'.format( user, user.nins)