Merge branch 'dev-signup-check-pubkey'

This commit is contained in:
poka 2019-11-08 16:03:12 +01:00
commit 8d5d361e38
9 changed files with 174 additions and 29 deletions

View File

@ -0,0 +1,25 @@
<?php
if(isset($_GET['vendeur']))
{
// Get public key from pseudo
$parseUser = $_GET['vendeur'];
putenv("parseUser=$parseUser");
$silkPubKey = system('curl -s https:\/\/duniter-g1.p2p.legal/wot/members | grep -w -i -B 1 $parseUser | grep "pubkey" | awk -F \'"\' \'{ print $4 }\'');
if (empty($silkPubKey))
{
$silkPubKeyUser = shell_exec('curl -s https:\/\/duniter-g1.p2p.legal/wot/lookup/$parseUser | head | grep -i -w -A 3 "pubkey" | awk -F \'"\' \'{ print $4 }\' | awk \'NF > 0\'');
putenv("silkPubKeyUser=$silkPubKeyUser");
$silkUser = system('echo "$silkPubKeyUser" | tail -n2 | head -n1');
if ($silkUser == $parseUser)
{
$silkPubKey = system('echo "$silkPubKeyUser" | head -n1');
}
}
if (empty($silkPubKey))
{
echo "Aucune clé n'a été trouvé à partir de ce pseudo";
}
}
?>

View File

@ -19,7 +19,7 @@ $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password);
$params["antenne_slug"] = $antenne_slug;
$requete = "SELECT products.*, users.username
$requete = "SELECT products.*, users.username, users.pubkey
FROM products
LEFT JOIN antennes
ON antennes.id = products.antenne_id
@ -52,12 +52,19 @@ $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password);
$data .= "<tr style='background:lightblue;color:black;'>
<td>$number</td>";
$data .= '<td>'.$row['name'].'</td>';
$prix = $row['prix'];
$vendeur = $row['username'];
$produit = $row['name'];
$pubkey = $row['pubkey'];
$pubkeyShort = substr($pubkey, 0, 8);
$vendeur_format = "<a target=\"_blank\" href=\"https://g1.duniter.fr/#/app/wot/$pubkey/\">$vendeur</a>";
$cle_pub_format = "<a target=\"_blank\" href=\"https://g1.duniter.fr/api/#/v1/payment/$pubkey?amount=$prix&name=$vendeur&comment=[Achat GMarche] : $produit&preferred_node=https://g1.librelois.fr&redirect_url=https://gmarche.monnaie-libre.fr\" title=$pubkey> $pubkeyShort... </a>";
$data .= '<td>'.$produit.'</td>';
$data .= '<td><img src="/uploads/products/'.$antenne_slug.'/'.$row['image'].'" width="100" height="100" /></td>';
$data .= '<td>'.$row['username'].'</td>';
$data .= '<td></td>';
$data .= '<td>'.$vendeur_format.'</td>';
$data .= '<td>'.$cle_pub_format.'</td>';
$data .= '<td>'.$row['quantite'].'</td>';
$data .= '<td>'.$row['prix'].'</td>';
$data .= '<td>'.$prix.'</td>';
if ($row['username'] == $_GET['nom_connecte'] ) {
$data .= '<td>';
$data .= '<button onclick="GetProduitsDetails(\'';

View File

@ -20,7 +20,7 @@ $data = '<table class="table table-bordered table-striped">
$params["antenne_slug"] = $antenne_slug;
$requete = "SELECT souhaits.*, users.username
$requete = "SELECT souhaits.*, users.username, users.pubkey
FROM souhaits
LEFT JOIN antennes
ON antennes.id = souhaits.antenne_id
@ -39,12 +39,19 @@ if ($count > 0)
$data .= "<tr style='background:lightblue;color:black;'>
<td>$number</td>";
$data .= '<td>'.$row['name'].'</td>';
$data .= '<td><img src="/uploads/recherches/'.$antenne_slug.'/'.$row['image'].'" width="100" height="100" /></td>';
$data .= '<td>'.$row['username'].'</td>';
$data .= '<td></td>';
$data .= '<td>'.$row['quantite'].'</td>';
$data .= '<td>'.$row['prix'].'</td>';
$prix = $row['prix'];
$vendeur = $row['username'];
$produit = $row['name'];
$pubkey = $row['pubkey'];
$vendeur_format = "<a target=\"_blank\" href=\"https://g1.duniter.fr/#/app/wot/$pubkey/\">$vendeur</a>";
$pubkeyShort = substr($pubkey, 0, 8);
$data .= '<td>'.$produit.'</td>';
$data .= '<td><img src="/uploads/products/'.$antenne_slug.'/'.$row['image'].'" width="100" height="100" /></td>';
$data .= '<td>'.$vendeur_format.'</td>';
$data .= '<td>'.$pubkeyShort.'...</td>';
$data .= '<td>'.$row['quantite'].'</td>';
$data .= '<td>'.$prix.'</td>';
$data .= '<td>';
$data .= '<button onclick="GetRecherchesDetails(\'';
$data .= $row['id'];

View File

@ -24,8 +24,13 @@ img {
height: auto;
}
a :hover {
background-color: lightgreen;
#la_page a {
color: #5B5EA6;
}
.breadcrumbs a:hover {
/* background-color: lightgreen; */
font-size: 1.03em;
text-decoration: none;
}
@ -103,6 +108,57 @@ header.header img {
margin: 5px auto;
text-align: center;
}
#signupContain {
background-color: lightgray;
opacity: 0.9;
margin: auto;
margin-top: 1rem;
padding:1rem;
width: 550px;
}
#firstnameDiv {
width: 49%;
display: inline-block;
}
#lastnameDiv {
width: 50%;
display: inline-block;
}
#champsOgligatoire {
float: right;
font-size: 0.8em;
}
#validSignup {
display: block;
margin: auto;
}
/******************************************************************/
/* LOADING PUBKEY */
/******************************************************************/
#cle_pub {
display: none;
}
.loadingPubkey {
display: none;
height: 20px;
width: 20px;
content:url('../images/ajax-loader.gif')
}
body.loading .loadingPubkey {
overflow: hidden;
display: block;
}
/******************************************************************/
/* POUR MOBILES */
/******************************************************************/

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

View File

@ -1,4 +1,5 @@
// Add Record
function addRecord(antenne_slug, antenne_id, nom_connecte, id_user) {
var produit = $("#produit").val();

View File

@ -58,10 +58,11 @@ class SignupAction
}
$params = $request->getParsedBody();
$validator = (new Validator($params))
->required('username', 'email', 'password', 'password_confirm', 'firstname', 'lastname', 'created_at')
->required('username', 'pubkey', 'email', 'password', 'password_confirm', 'created_at')
->length('username', 3)
->length('firstname', 2)
->length('lastname', 2)
->length('pubkey', 43)
->length('firstname', 0)
->length('lastname', 0)
->email('email')
->confirm('password')
->length('password', 4)
@ -70,6 +71,7 @@ class SignupAction
if ($validator->isValid()) {
$userParams = [
'username' => $params['username'],
'pubkey' => $params['pubkey'],
'firstname'=> $params['firstname'],
'lastname'=> $params['lastname'],
'email' => $params['email'],
@ -89,6 +91,7 @@ class SignupAction
'errors' => $errors,
'user' => [
'username' => $params['username'],
'pubkey' => $params['pubkey'],
'email' => $params['email'],
'firstname'=> $params['firstname'],
'lastname'=> $params['lastname'],

View File

@ -1,16 +1,66 @@
{% extends 'layout.twig' %}
{% block body %}
<div class="container" style="background-color: lightgray;opacity: 0.9;margin: 1rem;padding:1rem;">
<!-- <script type="text/javascript" src="../../../public/js/script.js"></script>-->
<div class="container" id="signupContain">
<form action="{{ path('account.signup') }}" method="post">
{{ csrf_input() }}
{{ field('username', user.username, "Pseudo") }}
{{ field('firstname', user.firstname, "Prénom") }} {{ field('lastname', user.lastname, "Nom") }}
{{ field('email', user.email, "Email", {type: 'email'}) }}
{{ field('password', null, "Mot de passe", {type: 'password'}) }}
{{ field('password_confirm', null, "Confirmez le mot de passe", {type: 'password'}) }}
{{ field('username', user.username, "Pseudo *") }}
<div class="loadingPubkey"></div>
<div id="livesearch-pubkey"></div>
<div id=cle_pub>{{ field('pubkey', user.pubkey, "Clé publique*") }}</div>
<div id=lastnameDiv>{{ field('lastname', user.lastname, "Nom") }}</div>
<div id=firstnameDiv>{{ field('firstname', user.firstname, "Prénom") }}</div>
{{ field('email', user.email, "Email *", {type: 'email'}) }}
{{ field('password', null, "Mot de passe *", {type: 'password'}) }}
{{ field('password_confirm', null, "Confirmez le mot de passe *", {type: 'password'}) }}
<div id="champsOgligatoire">* Champs obligatoires</div>
{{ field('created_at', date(), null, {type: 'hidden'}) }}
<button class="btn btn-primary">S'inscrire</button>
<button class="btn btn-primary" id="validSignup">S'inscrire</button>
</form>
</div>
{% endblock %}
<script>
var textInput = document.getElementById('username');
var timeout = null;
$body = $("body");
(document.getElementById("pubkey").value) ? noPubKey("block") : true ;
textInput.onkeyup = function (e) {
clearTimeout(timeout);
timeout = setTimeout(function () {
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
pubkeyAnswer=this.responseText;
pubkeyIsNull = pubkeyAnswer.includes("Aucune clé n'a été trouvé à partir de ce pseudo");
// (pubkeyIsNull) ? sentenceAnswer=this.responseText : sentenceAnswer="j'ai trouvé ta clé publique Ḡ1 !";
// sentenceAnswer=this.responseText;
(pubkeyIsNull) ? document.getElementById("livesearch-pubkey").innerHTML=pubkeyAnswer : document.getElementById("livesearch-pubkey").innerHTML='ḠTrouvé une clé ! =)<br>Clé publique: ' + pubkeyAnswer;
(pubkeyIsNull) ? document.getElementById("pubkey").value="" : document.getElementById("pubkey").value=pubkeyAnswer;
document.getElementById("livesearch-pubkey").style.border="2px solid #A5ACB2";
(pubkeyIsNull) ? noPubKey("block") : noPubKey("hide");
}
}
$body.addClass("loading");
xmlhttp.open("GET","/ajax/getG1PubKey.php?vendeur="+textInput.value,true);
xmlhttp.send();
}, 800);
};
function noPubKey(state) {
$body.removeClass("loading");
var textMbr = document.getElementById("cle_pub");
if (state == "hide"){
textMbr.style.display = "none";
} else {
textMbr.style.display = "block";
}
}
</script>
{% endblock %}

View File

@ -178,10 +178,6 @@
</div>
</div>
<div class="form-group">
<label for="cle_pub">Clé publique</label>
<input type="text" id="cle_pub" placeholder="Clé publique" class="form-control"/>
</div>
<div class="form-group">
<label for="quantite">Quantité</label>
<input type="number" id="quantite" placeholder="Quantité" class="form-control"/>
</div>