def remove_campaign(mode): """ create a new campaign """ check_login() new_campaign = company.Campaign(session['username'], mode) new_campaign.delete(request.args['campaign_name']) flash('Campaign removed', 'success') return redirect(mode.server + 'user/')
def add_campaign(mode): """ create a new campaign """ check_login() if request.method == 'GET': return render_template('./issuer/add_campaign.html', **session['menu']) if request.method == 'POST': new_campaign = company.Campaign(session['username'], mode) new_campaign.add(request.form['name'], request.form['description']) flash('New campaign added', 'success') return redirect(mode.server + 'user/')
def add_campaign(mode): """ create a new campaign """ check_login() if request.method == 'GET': return render_template('./issuer/add_campaign.html', **session['menu']) if request.method == 'POST': new_campaign = company.Campaign(session['username'], mode) data = { 'description': request.form['description'], 'nb_subject': 0, 'startDate': '', 'endDate': '' } new_campaign.add(request.form['name'], json.dumps(data, ensure_ascii=False)) flash('New campaign added', 'success') return redirect(mode.server + 'user/')
def request_certificate(mode): """ The request call comes from the Search Bar or from the Identity page #@app.route('/user/request_certificate/', methods=['GET', 'POST']) """ check_login() if request.method == 'GET': session['credential_issuer_username'] = request.args.get( 'issuer_username') # check if campaign exist campaign = company.Campaign(session['credential_issuer_username'], mode) if not campaign.get_list(): flash('This company as no active campaign', 'warning') return redirect(mode.server + 'user/') return render_template('./issuer/request_certificate.html', **session['menu']) if request.method == 'POST': select = "" reviewer = company.Employee(session['credential_issuer_username'], mode) reviewer_list = reviewer.get_list('reviewer', 'all') for reviewer in reviewer_list: session['select'] = select + """<option value=""" + reviewer[ 'username'].split('.')[0] + """>""" + reviewer[ 'username'].split('.')[0] + """</option>""" if request.form['certificate_type'] == 'experience': return render_template( './issuer/request_experience_credential.html', **session['menu'], select=session['select']) elif request.form['certificate_type'] == 'reference': return render_template( './issuer/request_reference_credential.html', **session['menu'], select=session['select']) else: flash('credential not available', 'warning') return redirect(mode.server + 'user/')
def request_experience_credential(mode): """ Basic request for experience credential @app.route('/user/request_experience_certificate/', methods=['POST']) """ check_login() # check if campaign exist reference = request.form['reference'] campaign = company.Campaign(session['credential_issuer_username'], mode) if not campaign.get(reference.split(':')[0]): flash('This reference does not exist.', 'warning') logging.warning('campaign does ot exist') return render_template('./issuer/request_experience_credential.html', **session['menu'], select=session['select']) # load templates for verifiable credential template unsigned_credential = json.load( open('./verifiable_credentials/experience.jsonld', 'r')) # update credential with form data id = str(uuid.uuid1()) unsigned_credential["id"] = "data:" + id unsigned_credential["credentialSubject"]["id"] = ns.get_did( session['workspace_contract'], mode) unsigned_credential["credentialSubject"]["name"] = session['name'] unsigned_credential["credentialSubject"]["title"] = request.form['title'] unsigned_credential["credentialSubject"]["description"] = request.form[ 'description'] unsigned_credential["credentialSubject"]["startDate"] = request.form[ 'start_date'] unsigned_credential["credentialSubject"]["endDate"] = request.form[ 'end_date'] unsigned_credential["credentialSubject"]["skills"] = list() for skill in request.form['skills'].split(','): unsigned_credential["credentialSubject"]["skills"].append({ "@type": "DefinedTerm", "description": skill }) unsigned_credential["credentialSubject"]["companyLogo"] = session[ 'issuer_explore']['picture'] unsigned_credential["credentialSubject"]["companyName"] = session[ 'issuer_explore']['name'] unsigned_credential["credentialSubject"]["managerName"] = "" unsigned_credential["credentialSubject"]["reviewerName"] = "" # update local issuer database manager_username = ns.get_data_from_username( request.form['reviewer_username'] + '.' + session['credential_issuer_username'], mode)['referent'] credential = company.Credential(session['credential_issuer_username'], mode) credential.add(session['username'], request.form['reviewer_username'], manager_username, "drafted", id, json.dumps(unsigned_credential), reference) # send an email to reviewer for workflow reviewer_email = ns.get_data_from_username( request.form['reviewer_username'] + '.' + session['credential_issuer_username'], mode)['email'] subject = 'You have received a professional credential from ' + session[ 'name'] + ' to review' try: Talao_message.messageHTML(subject, reviewer_email, 'request_certificate', { 'name': session['name'], 'link': 'https://talao.co' }, mode) except: logging.error('email failed') # send email to user flash( 'Your request for an experience credential has been registered for review.', 'success') # clean up and return issuer_username = session['credential_issuer_username'] del session['select'] return redirect(mode.server + 'user/issuer_explore/?issuer_username=' + issuer_username)
def user(mode): """ #@app.route('/user/', methods = ['GET']) Main view for Identity Repository We setup Ientity with workspace or username depending of the login method """ check_login() if not session.get('uploaded', False): logging.info('start first instanciation') if not session.get('workspace_contract'): logging.info('Identity set up from username') data_from_username = ns.get_data_from_username( session['username'], mode) session['workspace_contract'] = data_from_username[ 'workspace_contract'] else: logging.info('Identity set up from workspace contract') session['username'] = ns.get_username_from_resolver( session['workspace_contract'], mode) if mode.test: user = Identity(session['workspace_contract'], mode, authenticated=True) else: try: user = Identity(session['workspace_contract'], mode, authenticated=True) except: logging.error('cannot init Identity') flash('session aborted', 'warning') return render_template('login.html') logging.info('end of first intanciation') # init session side by redis session['uploaded'] = True session['type'] = user.type session['address'] = user.address session['workspace_contract'] = user.workspace_contract session['issuer'] = user.issuer_keys session['partner'] = user.partners session['did'] = user.did session['eth'] = user.eth session['token'] = user.token session['rsa_key'] = user.rsa_key session['rsa_key_value'] = user.rsa_key_value session['rsa_filename'] = session['did'] + ".pem" session['private_key'] = user.private_key session['private_key_value'] = user.private_key_value session['relay_activated'] = user.relay_activated session['personal'] = user.personal session['identity_file'] = user.identity_file session['name'] = user.name session['secret'] = user.secret session['picture'] = user.picture session['signature'] = user.signature session['skills'] = user.skills session['certificate'] = user.certificate session['private_certificate'] = user.private_certificate session['secret_certificate'] = user.secret_certificate session[ 'all_certificate'] = user.certificate + user.private_certificate + user.secret_certificate session['has_vault_access'] = user.has_vault_access session['method'] = ns.get_method(session['workspace_contract'], mode) session['mode_server'] = mode.server if not session['method']: session['method'] = "ethr" phone = ns.get_data_from_username(session.get('username'), mode).get('phone') session['phone'] = phone if phone else "" if user.type == 'person': session['profil_title'] = user.profil_title session['experience'] = user.experience session['education'] = user.education # no credential workflow session['host'] = session['employee'] = None session['role'] = session['referent'] = None clipboard = mode.server + "resume/?did=" + session['did'] session['check_identity_key'] = False if session['type'] == 'company': session['profil_title'] = "" # data for credential workflow for admin, issuer or reviewer try: session['host'] = session['username'].split('.')[1] session['employee'] = session['username'].split('.')[0] session['role'] = ns.get_data_from_username( session['username'], mode)['role'] session['referent'] = ns.get_data_from_username( session['username'], mode)['referent'] # for creator except: session['host'] = session['username'] session['employee'] = None session['role'] = 'creator' session['referent'] = None clipboard = mode.server + "board/?did=" + session['did'] # for nav bar menu display session['menu'] = { 'picturefile': session['picture'], 'username': session.get('username', ""), 'name': session['name'], #'private_key_value' : user.private_key_value, 'rsa_filename': session['rsa_filename'], 'profil_title': session['profil_title'], 'clipboard': clipboard } # Dashboard start for employees if session['role'] in ['issuer', 'reviewer']: return redirect(mode.server + 'company/dashboard/') # Homepage start for Talent #if user.type == 'person' : # return render_template('homepage.html', **session['menu']) # check Identity key Pair for person only client side # Keypairs for companies are setpu server side if not ns.get_did(session['workspace_contract'], mode) and session['type'] == 'person': return redirect(mode.server + 'user/generate_identity/') else: session['check_identity_key'] = True # Partners if not session['partner']: my_partner = """<a class="text-info">No Partners available</a>""" else: my_partner = "" for partner in session['partner']: if partner['authorized'] == 'Pending': partner_html = """ <span><a href="/user/issuer_explore/?issuer_username=""" + partner[ 'username'] + """">""" + partner['username'] + """</a> (""" + partner[ 'authorized'] + """ - """ + partner['status'] + """ ) <a class="text-secondary" href="/user/reject_partner/?partner_username=""" + partner[ 'username'] + """&partner_workspace_contract=""" + partner[ 'workspace_contract'] + """"> <i data-toggle="tooltip" class="fa fa-thumbs-o-down" title="Reject this Partnership.">   </i> </a> <a class="text-secondary" href="/user/authorize_partner/?partner_username=""" + partner[ 'username'] + """&partner_workspace_contract=""" + partner[ 'workspace_contract'] + """"> <i data-toggle="tooltip" class="fa fa-thumbs-o-up" title="Authorize this Parnership."></i> </a> </spn>""" elif partner['authorized'] == 'Removed': partner_html = """ <span><a href="/user/issuer_explore/?issuer_username=""" + partner[ 'username'] + """">""" + partner[ 'username'] + """</a> (""" + partner[ 'authorized'] + """ - """ + partner[ 'status'] + """ ) </spn>""" else: partner_html = """ <span><a href="/user/issuer_explore/?issuer_username=""" + partner[ 'username'] + """">""" + partner[ 'username'] + """</a> (""" + partner[ 'authorized'] + """ - """ + partner['status'] + """ ) <a class="text-secondary" href="/user/remove_partner/?partner_username=""" + partner[ 'username'] + """&partner_workspace_contract=""" + partner[ 'workspace_contract'] + """"> <i data-toggle="tooltip" class="fa fa-trash-o" title="Remove this Partnership.">   </i> </spn>""" my_partner = my_partner + partner_html + """<br>""" # Issuer for document, they have an ERC725 key 20002 if not session['issuer']: my_issuer = """ <a class="text-info">No Referents available</a>""" else: my_issuer = "" for one_issuer in session['issuer']: issuer_username = ns.get_username_from_resolver( one_issuer['workspace_contract'], mode) issuer_username = '******' if issuer_username is None else issuer_username issuer_html = """ <span>""" + issuer_username + """ <a class="text-secondary" href="/user/remove_issuer/?issuer_username=""" + issuer_username + """&issuer_address=""" + one_issuer[ 'address'] + """"> <i data-toggle="tooltip" class="fa fa-trash-o" title="Remove">   </i> </a> <a class="text-secondary" href="/user/issuer_explore/?issuer_username=""" + issuer_username + """"> <i data-toggle="tooltip" class="fa fa-search-plus" title="Data Check"></i> </a> </span>""" my_issuer = my_issuer + issuer_html + """<br>""" # files if not session['identity_file']: my_file = """<a class="text-info">No Files available</a>""" else: my_file = "" for one_file in session['identity_file']: file_html = """ <b>File Name</b> : """ + one_file['filename'] + """ ( """ + one_file[ 'privacy'] + """ ) <br> <b>Created</b> : """ + one_file['created'] + """<br> <p> <a class="text-secondary" href="/user/remove_file/?file_id=""" + one_file[ 'id'] + """&filename=""" + one_file['filename'] + """"> <i data-toggle="tooltip" class="far fa-trash-alt" title="Remove">   </i> </a> <a class="text-secondary" href=/user/download/?filename=""" + one_file[ 'filename'] + """> <i data-toggle="tooltip" class="fa fa-download" title="Download"></i> </a> </p>""" my_file = my_file + file_html # skills if not session['skills'] or not session['skills'].get('id'): my_skills = """<a class="text-info">No data available</a>""" else: my_skills = "" for skill in session['skills']['description']: skill_html = skill['skill_name'] + """ (""" + skill[ 'skill_level'] + """)""" + """<br>""" my_skills = my_skills + skill_html my_skills = my_skills + """ <p> </p>""" # specific to person if session['type'] == 'person': # experience my_experience = "" if not session['experience']: my_experience = my_experience + """<a class="text-info">No Experience available</a>""" else: for experience in sorted( session['experience'], key=lambda d: time.strptime(d['start_date'], "%Y-%m-%d"), reverse=True): if not experience['end_date']: end_date = "Current" else: end_date = experience['end_date'] exp_html = """ <b>Company</b> : """ + experience['company']['name'] + """<br> <b>Title</b> : """ + experience['title'] + """<br> <b>Start Date</b> : """ + experience['start_date'] + """<br> <b>End Date</b> : """ + end_date + """<br> <b>Description</b> : """ + experience['description'][:100] + """...<br> <p> <a class="text-secondary" href="/user/remove_experience/?experience_id=""" + experience[ 'id'] + """"> <i data-toggle="tooltip" class="far fa-trash-alt" title="Remove">   </i> </a> </p>""" my_experience = my_experience + exp_html + "<hr>" # education my_education = "" if not session['education']: my_education = my_education + """<a class="text-info">No Education available</a>""" else: for education in session['education']: edu_html = """ <b>Organization</b> : """ + education['organization']['name'] + """<br> <b>Title</b> : """ + education['title'] + """<br> <b>Start Date</b> : """ + education['start_date'] + """<br> <b>End Date</b> : """ + education['end_date'] + """<br> <p> <a class="text-secondary" href="/user/remove_education/?education_id=""" + education[ 'id'] + """"> <i data-toggle="tooltip" class="far fa-trash-alt" title="Remove">   </i> </a> </p>""" my_education = my_education + edu_html + "<hr>" # personal TOPIC = { 'firstname': 'Firstname', 'lastname': 'Lastname', 'about': 'About', 'profil_title': 'Title', 'birthdate': 'Birth Date', 'contact_email': 'Contact Email', 'contact_phone': 'Contact Phone', 'postal_address': 'Postal Address', 'education': 'Education' } my_personal = "" for topicname in TOPIC.keys(): if session['personal'][topicname].get('claim_value'): text = session['personal'][topicname][ 'claim_value'] + ' (' + session['personal'][topicname][ 'privacy'] + ')' my_personal += """<b>""" + TOPIC[ topicname] + """</b> : """ + text + """<br>""" # Alias if session['username'] != ns.get_username_from_resolver( session['workspace_contract'], mode): display_alias = False my_access = "" else: display_alias = True my_access = "" access_list = ns.get_alias_list(session['workspace_contract'], mode) for access in access_list: if access['username'] == session['username']: access_html = """ <span>""" + session['username'] + """ (logged) </span>""" else: access_html = """ <span>""" + access['username'] + """ : """ + access['email'] + """ <a class="text-secondary" href="/user/remove_access/?alias_to_remove=""" + access[ 'username'] + """"> <i data-toggle="tooltip" class="fa fa-trash-o" title="Remove"> </i> </a> </span>""" my_access += access_html + """<br>""" # credentials/certificates my_certificates = "" if not session['all_certificate']: my_certificates = my_certificates + """<a class="text-info">No Credential available</a>""" else: for counter, certificate in enumerate(session['all_certificate'], 1): try: cert_html = """<hr> <b>Credential Type</b> : """ + certificate['credentialSubject'][ 'credentialCategory'].capitalize() + """<br> <b>Privacy</b> : """ + certificate['privacy'].capitalize( ) + """ credential<br> <b>Issuer name</b> : """ + certificate['credentialSubject'].get( 'companyName', 'None').capitalize() + """ <br> <b>Issuer DID</b> : """ + certificate['issuer'] + """<br> <b>Issuance Date</b> : """ + certificate['proof']['created'] + """<br>""" except: cert_html = """<hr> <b>#</b> : """ + str(counter) + "<br>" cert_html += """<b></b><a href= """ + mode.server + """certificate/?certificate_id=did:talao:""" + mode.BLOCKCHAIN + """:""" + session[ 'workspace_contract'][2:] + """:document:""" + str( certificate['doc_id'] ) + """>Display Credential</a><br> <p> <a class="text-secondary" href="/user/remove_certificate/?certificate_id=""" + certificate[ 'id'] + """"> <i data-toggle="tooltip" class="far fa-trash-alt" title="Remove">   </i> </a> <a class="text-secondary" href=/data/?dataId=""" + certificate['id'] + """:certificate> <i data-toggle="tooltip" class="fa fa-search-plus" title="Credential data">   </i> </a> <a class="text-secondary" onclick="copyToClipboard('#p""" + str( counter ) + """')"> <i data-toggle="tooltip" class="fa fa-clipboard" title="Copy Credential Link">   </i> </a> <a class="text-secondary" href=/user/swap_privacy/?certificate_id=""" + certificate[ 'id'] + """&privacy=""" + certificate['privacy'] + """> <i data-toggle="tooltip" title="Change privacy" class="fas fa-redo" >   </i> </a> </p> <p hidden id="p""" + str( counter ) + """" >""" + mode.server + """guest/certificate/?certificate_id=did:talao:""" + mode.BLOCKCHAIN + """:""" + session[ 'workspace_contract'][ 2:] + """:document:""" + str( certificate['doc_id']) + """</p>""" my_certificates += cert_html return render_template('person_identity.html', **session['menu'], display_alias=display_alias, personal=my_personal, experience=my_experience, education=my_education, skills=my_skills, certificates=my_certificates, access=my_access, partner=my_partner, issuer=my_issuer, digitalvault=my_file, nb_certificates=len(session['all_certificate'])) # specific to company if session['type'] == 'company': # init employee table employee = company.Employee(session['host'], mode) # Admin list and add admin my_admin_start = """<a href="/company/add_employee/?role_to_add=admin">Add an Admin</a><hr> """ my_admins = "" admin_list = employee.get_list('admin', 'all') for admin in admin_list: admin_html = """ <span>""" + admin['username'] + """ => """ + admin['identity_name'] + """ <a class="text-secondary" href="/user/remove_access/?employee_to_remove=""" + admin[ 'username'] + """"> <i data-toggle="tooltip" class="fas fa-trash-alt" title="Remove"> </i> </a> </span>""" my_admins += admin_html + """<br>""" my_admins = my_admin_start + my_admins # Issuer list and add issuer within a company my_managers_start = """<a href="/company/add_employee/?role_to_add=issuer">Add an Issuer</a><hr> """ my_managers = "" manager_list = employee.get_list('issuer', 'all') for manager in manager_list: manager_html = """ <span>""" + manager['username'] + """ => """ + manager[ 'identity_name'] + """ <a class="text-secondary" href="/user/remove_access/?employee_to_remove=""" + manager[ 'username'] + """"> <i data-toggle="tooltip" class="fas fa-trash-alt" title="Remove"> </i> </a> </span>""" my_managers += manager_html + """<br>""" my_managers = my_managers_start + my_managers # Reviewer list and add reviewers my_reviewers_start = """<a href="/company/add_employee/?role_to_add=reviewer">Add a Reviewer</a><hr> """ my_reviewers = "" reviewer_list = employee.get_list('reviewer', 'all') for reviewer in reviewer_list: reviewer_html = """ <span>""" + reviewer['username'] + """ => """ + reviewer[ 'identity_name'] + """ <a class="text-secondary" href="/user/remove_access/?employee_to_remove=""" + reviewer[ 'username'] + """"> <i data-toggle="tooltip" class="fas fa-trash-alt" title="Remove"> </i> </a> </span>""" my_reviewers += reviewer_html + """<br>""" my_reviewers = my_reviewers_start + my_reviewers # Company campaigns if session['role'] not in ['issuer', 'reviewer']: my_campaign = """<a href="/company/add_campaign/">Add a Campaign</a><hr> """ else: my_campaign = "" campaign = company.Campaign(session['host'], mode) campaign_list = campaign.get_list() if campaign_list: for camp in campaign_list: try: description = json.loads( camp['description'])['description'] except: description = camp.get('description', 'unkown') campaign_html = camp.get( 'campaign_name', 'unknown') + """ : """ + description[:100] remove_option = """... <a class="text-secondary" href="/company/remove_campaign/?campaign_name=""" + camp.get( 'campaign_name', 'unkown') + """"> <i data-toggle="tooltip" class="fas fa-trash-alt" title="Remove"> </i> </a>""" if session['role'] not in ['issuer', 'reviewer']: campaign_html += remove_option my_campaign += campaign_html + "<hr>" # company settings if session['role'] in ['creator', 'admin']: my_personal = """<a href="/user/picture/">Change Logo</a><br> <a href="/user/signature/">Change Signature</a><br>""" else: my_personal = "" for topicname in COMPANY_TOPIC: if session['personal'][topicname]['claim_value']: topicname_value = session['personal'][topicname]['claim_value'] topicname_privacy = ' (' + session['personal'][topicname][ 'privacy'] + ')' my_personal = my_personal + """ <span><b>""" + topicname + """</b> : """ + topicname_value + topicname_privacy + """ </span><br>""" if session['role'] in ['creator', 'admin']: my_personal = my_personal + """<a href="/user/update_company_settings/">Update Company Data</a>""" # credentials if not session['all_certificate']: my_certificates = """<a class="text-info">No Credentials available</a>""" else: my_certificates = """<div style="height:300px;overflow:auto;overflow-x: hidden;">""" for counter, certificate in enumerate(session['all_certificate'], 1): if '@context' in certificate: if certificate['credentialSubject'][ 'credentialCategory'] == "reference": cert_html = """<hr> <b>Issuer Name</b> : """ + certificate['credentialSubject'][ 'companyName'] + """<br> <b>Certificate Type</b> : """ + certificate['credentialSubject'][ 'credentialCategory'].capitalize() + """<br> <b>Title</b> : """ + certificate['credentialSubject']['offers'][ 'title'] + """<br> <b>Description</b> : """ + certificate['credentialSubject']['offers'][ 'description'] + """<br> <b></b><a href= """ + mode.server + """certificate/?certificate_id=did:talao:""" + mode.BLOCKCHAIN + """:""" + session[ 'workspace_contract'][ 2:] + """:document:""" + str( certificate['doc_id'] ) + """>Display Certificate</a><br> <p> <a class="text-secondary" href="/user/remove_certificate/?certificate_id=""" + certificate[ 'id'] + """"> <i data-toggle="tooltip" class="far fa-trash-alt" title="Remove">   </i> </a> <a class="text-secondary" href=/data/?dataId=""" + certificate[ 'id'] + """:certificate> <i data-toggle="tooltip" class="fa fa-search-plus" title="Data Check">   </i> </a> <a class="text-secondary" onclick="copyToClipboard('#p""" + str( counter) + """')"> <i data-toggle="tooltip" class="fa fa-clipboard" title="Copy Certificate Link"></i> </a> </p> <p hidden id="p""" + str(counter ) + """" >""" + mode.server + """guest/certificate/?certificate_id=did:talao:""" + mode.BLOCKCHAIN + """:""" + session[ 'workspace_contract'][ 2:] + """:document:""" + str( certificate['doc_id'] ) + """</p>""" else: cert_html = """<a class="text-secondary" href="/user/remove_certificate/?certificate_id=""" + certificate[ 'id'] + """"> <i data-toggle="tooltip" class="far fa-trash-alt" title="Remove">   </i> </a> <a class="text-secondary" href=/data/?dataId=""" + certificate[ 'id'] + """:certificate> <i data-toggle="tooltip" class="fa fa-search-plus" title="Data Check">   </i> </a>""" logging.warning('incorrect certificate type') my_certificates = my_certificates + cert_html my_certificates = my_certificates + """</div>""" return render_template('company_identity.html', **session['menu'], admin=my_admins, manager=my_managers, reviewer=my_reviewers, personal=my_personal, skills=my_skills, issuer=my_issuer, certificates=my_certificates, company_campaign=my_campaign, digitalvault=my_file)