def forgot_password(mode) : """ @app.route('/forgot_password/', methods = ['GET', 'POST']) This function is called from the login view. build JWE to store timestamp, username and email, we use Talao RSA key """ if request.method == 'GET' : return render_template('./login/forgot_password_init.html') if request.method == 'POST' : username = request.form.get('username') if not ns.username_exist(username, mode) : flash("Username not found", "warning") return render_template('./login/login_password.html') email= ns.get_data_from_username(username, mode)['email'] private_rsa_key = privatekey.get_key(mode.owner_talao, 'rsa_key', mode) RSA_KEY = RSA.import_key(private_rsa_key) public_rsa_key = RSA_KEY.publickey().export_key('PEM').decode('utf-8') expired = datetime.timestamp(datetime.now()) + 180 # 3 minutes live # build JWE jwe = JsonWebEncryption() header = {'alg': 'RSA1_5', 'enc': 'A256GCM'} json_string = json.dumps({'username' : username, 'email' : email, 'expired' : expired}) payload = bytes(json_string, 'utf-8') token = jwe.serialize_compact(header, payload, public_rsa_key) link = mode.server + 'forgot_password_token/?'+ urlencode({'token' : token.decode('utf-8')}, doseq=True) subject = "Renew your password" if Talao_message.messageHTML(subject, email, 'forgot_password', {'link': link}, mode): flash("You are going to receive an email to renew your password.", "success") return render_template('./login/login_password.html')
def login(mode): """ @app.route('login/', methods = ['GET', 'POST']) """ if request.method == 'GET': session.clear() return render_template('./login/login_password.html') if request.method == 'POST': if not session.get('try_number'): session['try_number'] = 1 session['username_to_log'] = request.form['username'] if not ns.username_exist(session['username_to_log'], mode): logging.warning('username does not exist') flash('Username not found', "warning") session['try_number'] = 1 return render_template('./login/login_password.html', username="") if not ns.check_password(session['username_to_log'], request.form['password'], mode): logging.warning('wrong secret code') if session['try_number'] == 1: flash('This password is incorrect, 2 trials left', 'warning') session['try_number'] += 1 return render_template('./login/login_password.html', username=session['username_to_log']) if session['try_number'] == 2: flash('This password is incorrect, 1 trials left', 'warning') session['try_number'] += 1 return render_template('./login/login_password.html', username=session['username_to_log']) flash("Too many trials (3 max)", "warning") session['try_number'] = 1 return render_template('./login/login_password.html', username="") else: # secret code to send by email or sms session['code'] = str(secrets.randbelow(99999)) session['code_delay'] = datetime.now() + timedelta(seconds=180) # send code by sms if phone exist else email try: session['support'] = send_secret_code( session['username_to_log'], session['code'], mode) logging.info('secret code sent = %s', session['code']) flash("Secret code sent by " + session['support'], 'success') session['try_number'] = 1 except: flash("Connexion problem", 'danger') return render_template('./login/login_password.html', username="") return render_template("./login/authentification.html", support=session['support'])
def _create_user_step_3(address, private_key, wallet_address, workspace_contract, username, email, password, phone, mode, decentralized): # add username to register in local nameservice Database with last check if ns.username_exist(username, mode): username = username + str(random.randint(1, 100)) ns.add_identity(username, workspace_contract, email, mode) # transfer workspace / alias if decentralized: email_address = wallet_address if not transfer_workspace(address, private_key, wallet_address, mode): print('Error : workspace transfer failed') return False print('Success : workspace ownership tranfered to ' + wallet_address) else: email_address = address if not ns.update_wallet(workspace_contract, wallet_address, mode): print('Error : Alias update failed') return False print('Success : wallet address added as an alias') # setup password if password: ns.update_password(username, password, mode) print('Success : password has been updated') # setup phone if phone: ns.update_phone(username, phone, mode) print('Success : phone has been updated') # If decentralized and if needed, pre-activate the wallet address if not has_vault_access(wallet_address, mode) and decentralized: ether_transfer(wallet_address, mode.ether2transfer, mode) token_transfer(wallet_address, mode.talao_to_transfer, mode) # emails sent to admin Talao_message.messageLog("", "", username, email, "createidentity.py", email_address, "", workspace_contract, "", email, "", "", mode) # an email sent to user Talao_message.messageUser("", "", username, email, email_address, "", workspace_contract, mode) # Oracle....to lock Talao token on Ethereum agains private bc #if mode.myenv == 'aws' : # ethereum_bridge.lock_ico_token(None, None) # print('transfer Ethereum token done') print("Success : create identity process step 3 is over") return True
def cci(mode) : session.clear() print('referrer = ', request.referrer) if request.method == 'GET' : whitelist = ['http://127.0.0.1:5000/profile', 'http://masociete.co/', 'http://127.0.0.1:4000/', mode.server + 'create_company_cci/', mode.server + 'create_company_cci/password/', mode.server + 'create_company_cci/code/',] if request.referrer in whitelist: return render_template("CCI/create_company_cci.html",message='') else: #flash('Incorrect referrer, you do not have access to this page', 'warning') print('Error : CCI incorrect referrer') return redirect('/register/') if request.method == 'POST' : session['email'] = request.form['email'] session['name'] = request.form['name'] session['username'] = request.form['name'].lower() if ns.username_exist(session['username'], mode) : session['username'] = session['username'] + str(random.randint(1, 100)) session['siren'] = request.form['siren'] return render_template("CCI/create_company_cci_password.html")
def resolver(mode): """ request GET , arguments @app.route('/api/v1/credential', methods=['GET'], defaults={'mode' : mode}) "siret" : required, only siren is used (9 first numbers) """ try: siren = request.args['siret'][:9] except: logging.info('request malformed %s', request.args) data = jsonify( message= "Malformed request syntax or invalid request message parameters.", category="error", status=400) return make_response(data, 400) username = directory.search_siren(siren, mode) if not username or not ns.username_exist(username, mode): logging.info('username not found for siren = %s', siren) data = jsonify(message="SIRET not found.", category="error", status=404) return make_response(data, 404) try: workspace_contract = ns.get_data_from_username( username, mode)['workspace_contract'] except: logging.error('talaonet call failed') data = jsonify(message="Internal server error.", category="error", status=500) return make_response(data, 500) did = ns.get_did(workspace_contract, mode) data = jsonify(message="DID", category="success", data=did, status=200) return make_response(data, 200)
def add_employee(mode): """ # add admin or issuer or reviewer in table issuer of host #@app.route('/user/add_employee/', methods=['GET', 'POST']) add_employee(employee_name, identity_name, role, referent, host_name, email, mode, phone=None, password='******') : """ check_login() # init employee db access employee = company.Employee(session['host'], mode) if request.method == 'GET': session['role_to_add'] = request.args.get('role_to_add') if session['role_to_add'] == 'issuer': return render_template('./issuer/add_issuer.html', **session['menu']) elif session['role_to_add'] == 'reviewer': issuer_list = employee.get_list('issuer', 'all') issuer_select = "" for issuer in issuer_list: issuer_select += """<option value=""" + issuer[ 'username'].split('.')[0] + """>""" + issuer[ 'username'].split('.')[0] + """</option>""" return render_template('./issuer/add_reviewer.html', **session['menu'], issuer_select=issuer_select) elif session['role_to_add'] == 'admin': return render_template('./issuer/add_admin.html', **session['menu']) if request.method == 'POST': # check if username is new if ns.username_exist(request.form['employee_username'], mode) or employee.exist( request.form['employee_username']): flash('This username is already used, lets try an another one !', 'warning') else: employee_username = request.form['employee_username'] identity_username = request.form['identity_username'] # let check who is the referent if session['role_to_add'] == 'reviewer': if session['role'] in ['admin', 'creator']: referent = request.form['referent_username'] else: referent = session['employee'] else: referent = None #add_employee(employee_name, identity_name, role, referent, host_name, email, mode, phone=None, password='******') : if employee.add(employee_username, identity_username, session['role_to_add'], referent, request.form['employee_email']): flash( employee_username.lower() + " has been added as " + session['role_to_add'], 'success') # clean up del session['role_to_add'] return redirect(mode.server + 'user/')
def issuer_explore(mode): check_login() issuer_username = request.args['issuer_username'] if 'issuer_username' not in session or session[ 'issuer_username'] != issuer_username: if not ns.username_exist(issuer_username, mode): flash('Issuer data not available', 'danger') return redirect(mode.server + 'user/') issuer_workspace_contract = ns.get_data_from_username( issuer_username, mode)['workspace_contract'] logging.info(' , issuer = %s', issuer_workspace_contract) session['issuer_explore'] = Identity( issuer_workspace_contract, mode, authenticated=True, ).__dict__.copy() session['issuer_username'] = issuer_username session['issuer_explore']['method'] = ns.get_method( session['issuer_explore']['workspace_contract'], mode) if not session['issuer_explore']['method']: session['issuer_explore']['method'] = 'ethr' #issuer_picture = session['issuer_explore']['picture'] if session['issuer_explore']['type'] == 'person': # file if session['issuer_explore']['identity_file'] == []: my_file = """<p class="text-center text-muted m-0 " style="font-size: 20px;">No data available</p>""" else: my_file = "" #is_encrypted = False for one_file in session['issuer_explore']['identity_file']: if one_file.get('content') == 'Encrypted': #is_encrypted = True file_html = """ <b>File Name</b> : """ + one_file[ 'filename'] + """ ( """ + 'Not available - Encrypted ' + """ ) <br> <b>Created</b> : """ + one_file['created'] + """<br>""" else: file_html = """ <b>File Name</b> : """ + one_file['filename'] + """ ( """ + one_file[ 'privacy'] + """ ) <br> <b>Created</b> : """ + one_file['created'] + """<br> <a class="text-secondary" href=/user/download/?filename=""" + one_file[ 'filename'] + """> <i data-toggle="tooltip" class="fa fa-download" title="Download"></i> </a>""" my_file = my_file + file_html + """<br>""" # experience experiences = [] for experience in session['issuer_explore']['certificate']: if experience['credentialSubject'][ 'credentialCategory'] == 'experience': experiences.append(experience) for experience in session['issuer_explore']['experience']: experiences.append(experience) # tri par date for i, experience in enumerate(experiences): min = i try: DTmin = time.strptime(experience['end_date'], "%Y-%m-%d") except: DTmin = time.strptime( experience['credentialSubject']['endDate'], "%Y-%m-%d") for j, certi in enumerate(experiences[i::]): try: DTcerti = time.strptime(certi['end_date'], "%Y-%m-%d") except: DTcerti = time.strptime( certi['credentialSubject']['endDate'], "%Y-%m-%d") if DTcerti < DTmin: min = j + i DTmin = DTcerti experiences[i], experiences[min] = experiences[min], experiences[i] experiences = experiences[::-1] carousel_indicators_experience = """<li data-target="#experience-carousel" data-slide-to="0" class="active" style="margin-bottom: 0;"></li>""" carousel_rows_experience = "" if experiences == []: pass else: nbr_rows = (len(experiences) - 1) // 3 for i in range(nbr_rows): carousel_indicators_experience += '<li data-target="#experience-carousel" data-slide-to="{}"></li>'.format( i + 1) for i, experience in enumerate(experiences): # for verifiable credentials try: logo = experience['credentialSubject']['companyLogo'] startDate = experience['credentialSubject']['startDate'] endDate = experience['credentialSubject']['endDate'] description = experience['credentialSubject'][ 'description'] title = experience['credentialSubject']['title'] issuer_name = experience['credentialSubject'][ 'companyName'] # for self claims except: logo = 'QmSbxr8xkucse2C1aGMeQ5Wt12VmXL96AUUpiBuMhCrrAT' startDate = experience['start_date'] endDate = experience['end_date'] description = experience['description'] title = experience['title'] issuer_name = "" if logo != None: if not path.exists(mode.uploads_path + logo): url = 'https://gateway.pinata.cloud/ipfs/' + logo response = requests.get(url, stream=True) with open(mode.uploads_path + logo, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response if i % 3 == 0: carousel_rows_experience += '<div class="carousel-item px-2 {a}"><div class="row" style="flex-direction: row;">'.format( a="active" if (i == 0) else '') carousel_rows_experience += """<div class="col-md-4 mb-2" ><figure class="snip1253 mw-100" style="height: 410px; "><div class="image text-center h-100" style="background-color: white;" ><img src=""" #image try: carousel_rows_experience += """"{}" style="height: 200px;" alt="Loading error"/></div><figcaption class="p-0">""".format( "/uploads/" + logo) except: carousel_rows_experience += """"https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sample59.jpg" alt="Loading error"/></div><figcaption >""" #verified if experience.get('topic') != 'certificate': carousel_rows_experience += """<div class="row overflow-hidden" style="flex-direction: row;height: 50px"><div class="col bg-transparent px-2" style="max-width:60px;" ><i class="fa fa-pencil-square-o" style="color: #747474;font-size: 50px;"></i></div>""" else: carousel_rows_experience += """<div class="row overflow-hidden" style="flex-direction: row;height: 50px"><div class="col bg-transparent px-2" style="max-width:60px;" ><i class="material-icons my-auto" style="color: rgb(60,158,255);font-size: 50px;">verified_user</i></div>""" #header carousel_rows_experience += "<div class='col px-0 my-auto'><h4 class='align-center' style='color: black;font-size: 1.4em'>" + title + "</h4></div></div><hr class='my-1'>" #body if experience.get('topic') == 'certificate': carousel_rows_experience += """<p style="font-size: 1em"><b>Issuer name : </b>""" + issuer_name + """<br>""" carousel_rows_experience += """<b>Start Date</b> : """ + startDate + """<br> """ carousel_rows_experience += """<b>End Date</b> : """ + endDate + """<br>""" if experience.get('topic') != 'experience': carousel_rows_experience += """<b>Description</b> : """ + description[: 100:] if len(description) > 100: carousel_rows_experience += "...<br>" else: carousel_rows_experience += "<br>" else: carousel_rows_experience += """<b>Description</b> : """ + description[: 150:] if len(description) > 150: carousel_rows_experience += "...<br>" else: carousel_rows_experience += "<br>" carousel_rows_experience += "</p>" #Footer if experience.get('topic') != 'certificate': carousel_rows_experience += """</figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #c9c9c9; text-align:center;font-size: 1em; color:black;">Self claim</footer>""" #carousel_rows_experience += """<a href= /certificate/?certificate_id=""" + experience['id'] + """:experience> </a>""" else: carousel_rows_experience += """</figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #3c9eff; text-align:center;font-size: 1em;" >Certified by """ + issuer_name + """</footer>""" carousel_rows_experience += """<a href= """ + mode.server + """certificate/?certificate_id=did:talao:""" + mode.BLOCKCHAIN + """:""" + session[ 'issuer_explore']['workspace_contract'][ 2:] + """:document:""" + str( experience['doc_id']) + """></a>""" carousel_rows_experience += """</figure></div>""" if (i + 1) % 3 == 0 and (len(experiences) % 3 != 0 or len(experiences) != i + 1): carousel_rows_experience += '</div></div>' if i == len(experiences) - 1: carousel_rows_experience += '</div></div>' # recommendation recommendations = [] for certificate in session['issuer_explore']['certificate']: if certificate['type'] == "recommendation": recommendations.append(certificate) carousel_indicators_recommendation = """<li data-target="#recommendation-carousel" data-slide-to="0" class="active" style="margin-bottom: 0;"></li>""" carousel_rows_recommendation = "" if recommendations == []: pass else: nbr_rows = (len(recommendations) - 1) // 3 for i in range(nbr_rows): carousel_indicators_recommendation += '<li data-target="#recommendation-carousel" data-slide-to="{}"></li>'.format( i + 1) for i, recommendation in enumerate(recommendations): if recommendation['issuer']['type'] == 1001: issuer_name = recommendation['issuer'][ 'firstname'] + ' ' + recommendation['issuer'][ 'lastname'] else: issuer_name = recommendation['issuer']['name'] try: logo = recommendation['logo'] except: try: logo = recommendation['picture'] except: logo = 'QmSbxr8xkucse2C1aGMeQ5Wt12VmXL96AUUpiBuMhCrrAT' if logo: if not path.exists(mode.uploads_path + logo): url = 'https://gateway.pinata.cloud/ipfs/' + logo response = requests.get(url, stream=True) with open(mode.uploads_path + logo, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response if i % 3 == 0: carousel_rows_recommendation += '<div class="carousel-item {a}"><div class="row">'.format( a="active" if (i == 0) else '') carousel_rows_recommendation += """<div class="col-md-4 mb-2" ><figure class="snip1253 mw-100" style="height: 410px; "><div class="image text-center h-100" style="background-color: white;" ><img src=""" #image try: carousel_rows_recommendation += """"{}" style="height: 200px;" alt="Loading error"/></div><figcaption class="p-0">""".format( "/uploads/" + logo) except: carousel_rows_recommendation += """"https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sample59.jpg" alt="Loading error"/></div><figcaption >""" #verified carousel_rows_recommendation += """<div class="row overflow-hidden" style="flex-direction: row;height: 50px"><div class="col bg-transparent px-2" style="max-width:60px;" ><i class="material-icons my-auto" style="color: rgb(60,158,255);font-size: 50px;">verified_user</i></div>""" #header carousel_rows_recommendation += "<div class='col px-0 my-auto'><h4 class='align-center' style='color: black;font-size: 1.4em'>" + recommendation.get( 'title', "") + "</h4></div></div>" #body carousel_rows_recommendation += """<hr class="my-1"><p style="font-size: 1em"><b>Referent name: </b>""" + issuer_name + "<br>" carousel_rows_recommendation += """<b> Relationship: </b>""" + recommendation[ 'relationship'] + "<br>" carousel_rows_recommendation += """<b> Description: </b>""" + recommendation[ 'description'][:100] if len(recommendation['description']) > 100: carousel_rows_recommendation += "...<br>" else: carousel_rows_recommendation += "<br>" carousel_rows_recommendation += "</p>" #Footer carousel_rows_recommendation += """</figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #3c9eff; text-align:center;font-size: 1em; color:white;">Certified by """ + issuer_name + """</footer>""" #Lien certificates carousel_rows_recommendation += """<a href= """ + mode.server + """certificate/?certificate_id=did:talao:""" + mode.BLOCKCHAIN + """:""" + session[ 'issuer_explore']['workspace_contract'][ 2:] + """:document:""" + str( recommendation['doc_id']) + """></a>""" carousel_rows_recommendation += """</figure></div>""" if (i + 1) % 3 == 0 and (len(recommendations) % 3 != 0 or len(recommendations) != i + 1): carousel_rows_recommendation += '</div></div>' if i == len(recommendations) - 1: carousel_rows_recommendation += '</div></div>' # Education carousel_indicators_education = """<li data-target="#education-carousel" data-slide-to="0" class="active" style="margin-bottom: 0;"></li>""" carousel_rows_education = "" if session['issuer_explore']['education'] == []: pass else: educations = session['issuer_explore']['education'] nbr_rows = (len(educations) - 1) // 3 for i in range(nbr_rows): carousel_indicators_education += '<li data-target="#education-carousel" data-slide-to="{}"></li>'.format( i + 1) for i, education in enumerate( session['issuer_explore']['education']): try: logo = education['logo'] except: try: logo = education['picture'] except: logo = 'QmSbxr8xkucse2C1aGMeQ5Wt12VmXL96AUUpiBuMhCrrAT' if logo != None: if not path.exists(mode.uploads_path + logo): url = 'https://gateway.pinata.cloud/ipfs/' + logo response = requests.get(url, stream=True) with open(mode.uploads_path + logo, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response if i % 3 == 0: carousel_rows_education += '<div class="carousel-item {a}"><div class="row">'.format( a="active" if (i == 0) else '') carousel_rows_education += """<div class="col-md-4 mb-2" ><figure class="snip1253 mw-100" style="height: 410px; "><div class="image text-center h-100" style="background-color: white;" ><img src=""" #image try: carousel_rows_education += """"{}" style="height: 200px;" alt="Loading error"/></div><figcaption class="p-0">""".format( "/uploads/" + logo) except: carousel_rows_education += """"https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sample59.jpg" alt="Loading error"/></div><figcaption >""" #verified carousel_rows_education += """<div class="row overflow-hidden" style="flex-direction: row;height: 50px"><div class="col bg-transparent px-2" style="max-width:60px;" ><i class="fa fa-pencil-square-o" style="color: #747474;font-size: 50px;"></i></div>""" #header carousel_rows_education += "<div class='col px-0 my-auto'><h4 class='align-center' style='color: black;font-size: 1.4em'>" + education[ 'title'] + "</h4></div></div>" #body carousel_rows_education += """<hr class="my-1"><p style="font-size: 1em"><b>Name: </b>""" + education[ 'organization']['name'] + '<br>' carousel_rows_education += """<b>Start Date</b> : """ + education[ 'start_date'] + """<br> """ carousel_rows_education += """<b>End Date</b> : """ + education[ 'end_date'] + """<br>""" carousel_rows_education += "</p>" #Footer carousel_rows_education += """</figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #c9c9c9; text-align:center;font-size: 1em; color:black;">Self claim</footer>""" #Lien certificates #carousel_rows_education += """<a href= /certificate/?certificate_id="""+education['id'] + """:education></a>""" carousel_rows_education += """</figure></div>""" if (i + 1) % 3 == 0 and (len(educations) % 3 != 0 or len(educations) != i + 1): carousel_rows_education += '</div></div>' if i == len(educations) - 1: carousel_rows_education += '</div></div>' # Skills skills = [] for certificate in session['issuer_explore']['certificate']: if certificate['type'] == "skill": skills.append(certificate) carousel_indicators_skill = """<li data-target="#skill-carousel" data-slide-to="0" class="active" style="margin-bottom: 0;"></li>""" carousel_rows_skill = "" if skills == []: if session['issuer_explore']['skills'] == None: pass else: if session['issuer_explore']['skills']['description'] != None: carousel_rows_skill += '<div class="carousel-item active"><div class="row">' carousel_rows_skill += """<div class="col-md-4 mb-2"> <figure class="snip1253 mw-100" style="height: 410px; "> <div class="image text-center h-100" style="background-color: white;"><img src="/uploads/QmSbxr8xkucse2C1aGMeQ5Wt12VmXL96AUUpiBuMhCrrAT" style="height: 200px;" alt="Loading error" /></div> <figcaption class="p-0"> <div class="row overflow-hidden" style="flex-direction: row;height: 50px"> <div class="col bg-transparent px-2" style="max-width:60px;"><i class="fa fa-pencil-square-o" style="color: #747474;font-size: 50px;"></i></div> <div class='col px-0 my-auto'> <h4 class='align-center' style='color: black;font-size: 1.4em'>Self claimed skills</h4> </div> </div> <hr class="my-1"> <p class="text-center" style="font-size: 1em;">""" for i, skill in enumerate(session['issuer_explore'] ['skills']['description']): if i < 4: carousel_rows_skill += skill['skill_name'] + "<br>" elif i == 4: carousel_rows_skill += "" carousel_rows_skill += """</p></figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #c9c9c9; text-align:center;font-size: 1em; color:black;">Self claim</footer>""" #carousel_rows_skill += """<a href= /certificate/?certificate_id="""+ session['issuer_explore']['skills']['id'] + """:skills></a>""" carousel_rows_skill += """</figure></div>""" carousel_rows_skill += '</div></div>' else: nbr_rows = (len(skills) - 1) // 3 for i in range(nbr_rows): carousel_indicators_skill += '<li data-target="#skill-carousel" data-slide-to="{}"></li>'.format( i + 1) for i, skill in enumerate(skills): try: logo = skill['logo'] except: logo = 'QmSbxr8xkucse2C1aGMeQ5Wt12VmXL96AUUpiBuMhCrrAT' if logo != None: if not path.exists(mode.uploads_path + logo): url = 'https://gateway.pinata.cloud/ipfs/' + logo response = requests.get(url, stream=True) with open(mode.uploads_path + logo, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response if i % 3 == 0: carousel_rows_skill += '<div class="carousel-item {a}"><div class="row">'.format( a="active" if (i == 0) else '') carousel_rows_skill += """<div class="col-md-4 mb-2" ><figure class="snip1253 mw-100" style="height: 410px; "><div class="image text-center h-100" style="background-color: white;" ><img src=""" #image try: carousel_rows_skill += """"{}" style="height: 200px;" alt="Loading error"/></div><figcaption class="p-0">""".format( "/uploads/" + logo) except: carousel_rows_skill += """"https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sample59.jpg" alt="Loading error"/></div><figcaption >""" #verified carousel_rows_skill += """<div class="row overflow-hidden" style="flex-direction: row;height: 50px"><div class="col bg-transparent px-2" style="max-width:60px;" ><i class="material-icons my-auto" style="color: rgb(60,158,255);font-size: 50px;">verified_user</i></div>""" #header carousel_rows_skill += "<div class='col px-0 my-auto'><h4 class='align-center' style='color: black;font-size: 1.4em'>" + skill[ 'title'] + "</h4></div></div>" #body carousel_rows_skill += """<hr class="my-1"><p class="text-center" style="font-size: 1em;">""" lines = skill['description'].split("\n") for l in lines: carousel_rows_skill += l.strip("\r") + "<br>" carousel_rows_skill += "</p>" #Footer if skill['issuer']['type'] == 'company': carousel_rows_skill += """</figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #3c9eff; text-align:center;font-size: 1em;" >Certified by """ + skill[ 'issuer']['name'] + """</footer>""" else: carousel_rows_skill += """</figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #3c9eff; text-align:center;font-size: 1em;" >Certified by """ + skill[ 'issuer']['firstname'] + " " + skill['issuer'][ 'lastname'] + """</footer>""" #Lien certificates #carousel_rows_skill += """<a href= """+ mode.server + """certificate/?certificate_id=did:talao:""" + mode.BLOCKCHAIN + """:""" + session['issuer_explore']['workspace_contract'][2:] + """:document:""" + str(skill['doc_id']) + """></a>""" carousel_rows_skill += """</figure></div>""" if (i + 1) % 3 == 0 and (len(skills) % 3 != 0 or len(skills) != i + 1): carousel_rows_skill += '</div></div>' if i == len(skills) - 1: created_row = False if (i + 1) % 3 == 0: carousel_rows_skill += '<div class="carousel-item"><div class="row">' created_row = True carousel_rows_skill += """<div class="col-md-4 mb-2"> <figure class="snip1253 mw-100" style="height: 410px; "> <div class="image text-center h-100" style="background-color: white;"><img src="/uploads/QmSbxr8xkucse2C1aGMeQ5Wt12VmXL96AUUpiBuMhCrrAT" style="height: 200px;" alt="Loading error" /></div> <figcaption class="p-0"> <div class="row overflow-hidden" style="flex-direction: row;height: 50px"> <div class="col bg-transparent px-2" style="max-width:60px;"><i class="fa fa-pencil-square-o" style="color: #747474;font-size: 50px;"></i></div> <div class='col px-0 my-auto'> <h4 class='align-center' style='color: black;font-size: 1.4em'>Self claimed skills</h4> </div> </div> <hr class="my-1"> <p class="text-center" style="font-size: 1em;">""" for i, skill in enumerate(session['issuer_explore'] ['skills']['description']): if i < 4: carousel_rows_skill += skill['skill_name'] + "<br>" elif i == 4: carousel_rows_skill += "..." carousel_rows_skill += """</p></figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #c9c9c9; text-align:center;font-size: 1em; color:black;">Self claim</footer>""" carousel_rows_skill += """<a href= /data/?dataId=""" + session[ 'issuer_explore']['skills']['id'] + """:skills></a>""" carousel_rows_skill += """</figure></div>""" if created_row: carousel_rows_skill += '</div></div>' carousel_rows_skill += '</div></div>' #Services if session['type'] == 'person': referent_list = is_username_in_list(session['issuer'], issuer_username) # est ce qu il est dans ma partnership list partner_list = is_username_in_list_for_partnership( session['partner'], issuer_username) # est ce que je suis dans l'issuer list de ce Talent ? in_referent_list = is_username_in_list( session['issuer_explore']['issuer_keys'], session['username']) is_manager = False if session['type'] == 'company': host_name = session['username'] if len(session['username'].split( '.')) == 1 else session['username'].split('.')[1] referent_list = is_username_in_list(session['issuer'], issuer_username) is_manager = company.Employee(host_name, mode).exist(issuer_username) in_referent_list = is_username_in_list( session['issuer_explore']['issuer_keys'], host_name) partner_list = not is_username_in_list_for_partnership( session['partner'], issuer_username) # personal details adress = session['issuer_explore']['personal']['postal_address'][ 'claim_value'] phone = session['issuer_explore']['personal']['contact_phone'][ 'claim_value'] email = session['issuer_explore']['personal']['contact_email'][ 'claim_value'] birth_date = session['issuer_explore']['personal']['birthdate'][ 'claim_value'] education = session['issuer_explore']['personal']['education'][ 'claim_value'] about = session['issuer_explore']['personal']['about']['claim_value'] return render_template( './person_issuer_identity.html', **session['menu'], issuer_name=session['issuer_explore']['name'], issuer_address=session['issuer_explore']['address'], issuer_username=issuer_username, issuer_profil_title=session['issuer_explore']['profil_title'], issuer_picturefile=session['issuer_explore']['picture'], digitalvault=my_file, adress=adress, phone=phone, email=email, birth_date=birth_date, education=education, about=about, user_type=session['type'], referent_list=referent_list, partner_list=partner_list, in_referent_list=in_referent_list, is_manager=is_manager, carousel_indicators_experience=carousel_indicators_experience, carousel_indicators_recommendation= carousel_indicators_recommendation, carousel_indicators_education=carousel_indicators_education, carousel_indicators_skill=carousel_indicators_skill, carousel_rows_experience=carousel_rows_experience, carousel_rows_recommendation=carousel_rows_recommendation, carousel_rows_education=carousel_rows_education, carousel_rows_skill=carousel_rows_skill) if session['issuer_explore']['type'] == 'company': # file if session['issuer_explore']['identity_file'] == []: my_file = """<a class="text-info">No Files available</a>""" else: my_file = "" for one_file in session['issuer_explore']['identity_file']: if one_file.get('content') == 'Encrypted': file_html = """ <b>File Name</b> : """ + one_file[ 'filename'] + """ ( """ + 'Not available - Encrypted ' + """ ) <br> <b>Created</b> : """ + one_file['created'] + """<br>""" else: file_html = """ <b>File Name</b> : """ + one_file['filename'] + """ ( """ + one_file[ 'privacy'] + """ ) <br> <b>Created</b> : """ + one_file['created'] + """<br> <a class="text-secondary" href=/user/download/?filename=""" + one_file[ 'filename'] + """> <i data-toggle="tooltip" class="fa fa-download" title="Download"></i> </a>""" my_file = my_file + file_html + """<br>""" #aggrement credentials agreements = [] for certificate in session['issuer_explore']['certificate']: try: if certificate['credentialSubject'][ 'credentialCategory'] == 'agreement': agreements.append(certificate) except: pass carousel_indicators_agreement = """<li data-target="#agreement-carousel" data-slide-to="0" class="active" style="margin-bottom: 0;"></li>""" carousel_rows_agreement = "" if agreements == []: pass else: nbr_rows = (len(agreements) - 1) // 3 for i in range(nbr_rows): carousel_indicators_agreement += '<li data-target="#agreement-carousel" data-slide-to="{}"></li>'.format( i + 1) for i, agreement in enumerate(agreements): try: logo = agreement['issued_by']['logo'] except: logo = 'QmSbxr8xkucse2C1aGMeQ5Wt12VmXL96AUUpiBuMhCrrAT' if logo != None: if not path.exists(mode.uploads_path + logo): url = 'https://gateway.pinata.cloud/ipfs/' + logo response = requests.get(url, stream=True) with open(mode.uploads_path + logo, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response if i % 3 == 0: carousel_rows_agreement += '<div class="carousel-item {a}"><div class="row">'.format( a="active" if (i == 0) else '') carousel_rows_agreement += """<div class="col-md-4 mb-2" ><figure class="snip1253 mw-100" style="height: 410px; "><div class="image p-2 text-center h-100" style="background-color: white;" ><img src=""" #image try: carousel_rows_agreement += """"{}" style="height: 180px;" alt="Loading error"/></div><figcaption class="p-0">""".format( "/uploads/" + logo) except: carousel_rows_agreement += """"https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sample59.jpg" alt="Loading error"/></div><figcaption >""" #verified carousel_rows_agreement += """<div class="row overflow-hidden" style="flex-direction: row;height: 50px"><div class="col bg-transparent px-2" style="max-width:60px;" ><i class="material-icons my-auto" style="color: rgb(60,158,255);font-size: 50px;">verified_user</i></div>""" #header carousel_rows_agreement += "<div class='col px-0 my-auto'><h4 class='align-center' style='color: black;font-size: 1.4em'>" + agreement[ 'title'] + "</h4></div></div>" #body carousel_rows_agreement += """<hr class="my-1"><p class="my-0" style="font-size: 1em"><b>Issuer Name: </b>""" + agreement[ 'issuer']['name'] + '<br>' carousel_rows_agreement += """<b>Issue date</b> : """ + agreement[ 'date_of_issue'] + """<br> """ carousel_rows_agreement += """<b>End of validity date</b> : """ + agreement[ 'valid_until'] + """<br>""" carousel_rows_agreement += """<b> Description: </b>""" + agreement[ 'description'][:150] if len(agreement['description']) > 150: carousel_rows_agreement += "...<br>" else: carousel_rows_agreement += "<br>" carousel_rows_agreement += "</p>" #Footer carousel_rows_agreement += """</figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #3c9eff; text-align:center;font-size: 1em;" >Certified by """ + agreement[ 'issuer']['name'] + """</footer>""" #Lien certificates carousel_rows_agreement += """<a href= /certificate/?certificate_id=""" + agreement[ 'id'] + """></a>""" carousel_rows_agreement += """</figure></div>""" if (i + 1) % 3 == 0 and len(agreements) % 3 != 0: carousel_rows_agreement += '</div></div>' if i == len(agreements) - 1: carousel_rows_agreement += '</div></div>' # reference credentials references = [] for certificate in session['issuer_explore']['certificate']: try: if certificate['credentialSubject'][ 'credentialCategory'] == 'reference': references.append(certificate) except: pass carousel_indicators_reference = """<li data-target="#reference-carousel" data-slide-to="0" class="active" style="margin-bottom: 0;"></li>""" carousel_rows_reference = "" if not references: pass else: nbr_rows = (len(references) - 1) // 3 for i in range(nbr_rows): carousel_indicators_reference += '<li data-target="#reference-carousel" data-slide-to="{}"></li>'.format( i + 1) for i, reference in enumerate(references): logo = reference['credentialSubject']['companyLogo'] startDate = reference['credentialSubject']['offers'][ 'startDate'] endDate = reference['credentialSubject']['offers']['endDate'] description = reference['credentialSubject']['offers'][ 'description'] title = reference['credentialSubject']['offers']['title'] issuer_name = reference['credentialSubject']['companyName'] budget = reference['credentialSubject']['offers']['price'] if not logo: logo = 'QmSbxr8xkucse2C1aGMeQ5Wt12VmXL96AUUpiBuMhCrrAT' if not path.exists(mode.uploads_path + logo): url = 'https://gateway.pinata.cloud/ipfs/' + logo response = requests.get(url, stream=True) with open(mode.uploads_path + logo, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response if i % 3 == 0: carousel_rows_reference += '<div class="carousel-item {a}"><div class="row">'.format( a="active" if (i == 0) else '') carousel_rows_reference += """<div class="col-md-4 mb-2" ><figure class="snip1253 mw-100" style="height: 410px; "><div class="image text-center h-100" style="background-color: white;" ><img src=""" #image try: carousel_rows_reference += """"{}" style="height: 200px;" alt="Loading error"/></div><figcaption class="p-0">""".format( "/uploads/" + logo) except: carousel_rows_reference += """"https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sample59.jpg" alt="Loading error"/></div><figcaption >""" #verified carousel_rows_reference += """<div class="row overflow-hidden" style="flex-direction: row;height: 50px"><div class="col bg-transparent px-2" style="max-width:60px;" ><i class="material-icons my-auto" style="color: rgb(60,158,255);font-size: 50px;">verified_user</i></div>""" #header carousel_rows_reference += "<div class='col px-0 my-auto'><h4 class='align-center' style='color: black;font-size: 1.4em'>" + title + "</h4></div></div>" #body carousel_rows_reference += """<hr class="my-1"><p class="my-0" style="font-size: 1em"><b>Issuer Name: </b>""" + issuer_name + '<br>' carousel_rows_reference += """<b>Start date</b> : """ + startDate + """<b> End date</b> : """ + endDate + """<br> """ carousel_rows_reference += """<b>Project Budget</b> : """ + budget + """<br> """ carousel_rows_reference += """<b> Description: </b>""" + description[: 150] if len(description) > 150: carousel_rows_reference += "...<br>" else: carousel_rows_reference += "<br>" carousel_rows_reference += "</p>" #Footer carousel_rows_reference += """</figcaption><footer class="w-100" style="position: absolute; bottom:0; background-color: #3c9eff; text-align:center;font-size: 1em;" >Certified by """ + issuer_name + """</footer>""" #Lien certificates carousel_rows_reference += """<a href= /certificate/?certificate_id=""" + reference[ 'id'] + """></a>""" carousel_rows_reference += """</figure></div>""" if (i + 1) % 3 == 0 and len(references) % 3 != 0: carousel_rows_reference += '</div></div>' if i == len(references) - 1: carousel_rows_reference += '</div></div>' #Services referent_list = False partner_list = False in_referent_list = False if session['type'] == 'person': referent_list = is_username_in_list(session['issuer'], issuer_username) # est ce qu il est dans ma partnership list partner_list = is_username_in_list_for_partnership( session['partner'], issuer_username) # est ce que je suis dans l'issuer list de ce Talent ? in_referent_list = is_username_in_list( session['issuer_explore']['issuer_keys'], session['username']) if session['type'] == 'company': host_name = session['username'] if len(session['username'].split( '.')) == 1 else session['username'].split('.')[1] referent_list = is_username_in_list(session['issuer'], issuer_username) in_referent_list = is_username_in_list( session['issuer_explore']['issuer_keys'], host_name) partner_list = is_username_in_list_for_partnership( session['partner'], issuer_username) #kyc user_type = session['type'] contact_name = session['issuer_explore']['personal']['contact_name'][ 'claim_value'] contact_email = session['issuer_explore']['personal']['contact_email'][ 'claim_value'] contact_phone = session['issuer_explore']['personal']['contact_phone'][ 'claim_value'] website = session['issuer_explore']['personal']['website'][ 'claim_value'] about = session['issuer_explore']['personal']['about']['claim_value'] staff = session['issuer_explore']['personal']['staff']['claim_value'] siren = session['issuer_explore']['personal']['siren']['claim_value'] try: sales = "{:,}".format( int(session['issuer_explore']['personal']['sales'] ['claim_value'])).replace(',', ' ') except: sales = session['issuer_explore']['personal']['sales'][ 'claim_value'] if session['issuer_explore']['skills'] is None or session[ 'issuer_explore']['skills'].get('id') is None: my_competencies = """<p class="text-center text-muted m-0 " style="font-size: 20px;">No data available</p>""" else: my_competencies = "" for competencie in session['issuer_explore']['skills'][ 'description']: competencie_html = competencie['skill_name'] + """<br>""" my_competencies = my_competencies + competencie_html my_competencies = my_competencies + """ <p> <a class="text-secondary" href=/data/?dataId=""" + session[ 'issuer_explore']['skills']['id'] + """:skills> <i data-toggle="tooltip" class="fa fa-search-plus" title="Data Check"></i> </a> </p>""" return render_template( './company_issuer_identity.html', **session['menu'], issuer_name=session['issuer_explore']['name'], issuer_address=session['issuer_explore']['address'], issuer_username=issuer_username, user_type=user_type, issuer_picturefile=session['issuer_explore']['picture'], contact_name=contact_name, contact_email=contact_email, contact_phone=contact_phone, website=website, about=about, staff=staff, sales=sales, siren=siren, digitalvault=my_file, referent_list=referent_list, partner_list=partner_list, in_referent_list=in_referent_list, carousel_indicators_agreement=carousel_indicators_agreement, carousel_rows_agreement=carousel_rows_agreement, carousel_indicators_reference=carousel_indicators_reference, carousel_rows_reference=carousel_rows_reference, competencies=my_competencies)
def credential_list(mode): """ request GET , arguments @app.route('/api/v1/credential', methods=['GET'], defaults={'mode' : mode}) "siret" : required, only siren is used (9 first numbers) "data : optionam to get content """ print(request.args) data = request.args.get('data') try: siren = request.args['siret'][:9] except: logging.info('request malformed %s', request.args) return make_response( jsonify( message= "Malformed request syntax or invalid request message parameters.", category="error", status=400), 400) username = directory.search_siren(siren, mode) if not username or not ns.username_exist(username, mode): logging.info('username not found for siren = %s', siren) return make_response( jsonify(message="SIRET not found.", category="error", status=404), 404) try: workspace_contract = ns.get_data_from_username( username, mode)['workspace_contract'] contract = mode.w3.eth.contract(workspace_contract, abi=constante.workspace_ABI) doc_list = contract.functions.getDocuments().call() except: logging.error('talaonet call failed') return make_response( jsonify(message="Internal server error.", category="error", status=500), 200) result = [] if data: for doc_id in doc_list: if contract.functions.getDocument(doc_id).call()[0] == 20000: credential = Document('credential') credential.relay_get_credential(workspace_contract, doc_id, mode) result.append(credential.__dict__) message = "Credential data" else: for doc_id in doc_list: if contract.functions.getDocument(doc_id).call( )[0] == 20000: # doctype for public credential link = mode.server + 'certificate/?certificate_id=did:talao:talaonet:' + workspace_contract[ 2:] + ':document:' + str(doc_id) result.append(link) message = "Credential link list" return make_response( jsonify(message=message, category="success", data=result, status=200), 200)