mirror of
https://gitlab.com/CodeSolutionsProject/CodeShare.git
synced 2026-02-14 09:01:33 +01:00
26
Source/assets/css/alert.css
Normal file
26
Source/assets/css/alert.css
Normal file
@@ -0,0 +1,26 @@
|
||||
.myAlert-top{
|
||||
position: fixed;
|
||||
top: 5px;
|
||||
left:2%;
|
||||
width: 96%;
|
||||
}
|
||||
|
||||
.myAlert-bottom{
|
||||
position: fixed;
|
||||
bottom: 5px;
|
||||
left:2%;
|
||||
width: 96%;
|
||||
}
|
||||
|
||||
div.fullscreen {
|
||||
position: absolute;
|
||||
width:100%;
|
||||
height:960px;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background-color: lightblue;
|
||||
}
|
||||
|
||||
.alert{
|
||||
display: none;
|
||||
}
|
||||
@@ -5,8 +5,10 @@
|
||||
<link type="text/css" rel="stylesheet" href="{{ app.frontcss }}/bootstrap-paper.css"/>
|
||||
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
|
||||
<link type="text/css" rel="stylesheet" href="{{ app.frontcss }}/main.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="{{ app.frontcss }}/alert.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="{{ app.frontcss }}/codeStyles/vs.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
|
||||
{#<link rel="shortcut icon" href="{{ path.img }}favicon.ico" type="image/x-icon"/>#}
|
||||
{% block css %}{% endblock %}
|
||||
|
||||
@@ -19,6 +21,7 @@
|
||||
<script src="{{ app.frontjs }}/bootstrap.min.js"></script>
|
||||
<script src='https://www.google.com/recaptcha/api.js'></script>
|
||||
<script src="{{ app.frontjs }}/functions.js"></script>
|
||||
<script src="{{ app.frontjs }}/like.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
{% include app.fronthtml~'/nav.twig' %}
|
||||
@@ -26,6 +29,10 @@
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
|
||||
<div class="myAlert-bottom alert alert-dismissible alert-danger">
|
||||
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a><strong>Oh snap!</strong> Something wrong
|
||||
</div>
|
||||
|
||||
{% include app.fronthtml~"/footer.twig" %}
|
||||
|
||||
{% block js %}
|
||||
|
||||
@@ -1,35 +1,45 @@
|
||||
<table style="width: 100%; text-align:center">
|
||||
<tr>
|
||||
<th>
|
||||
<a href="{{ path('code',{'idc': code.idc,'lang': code.lang,'version': code.version}) }}">{{ code.name }}</a>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Author:</strong> {{ code.nick }} <strong> Version: </strong>{{ code.version }} <strong>
|
||||
Lang: </strong>{{ code.lLang }}</td>
|
||||
</tr>
|
||||
{% if code.extlib is defined and code.extlib != "" %}
|
||||
<tr>
|
||||
<td>
|
||||
<strong>External library:</strong> {{ code.extlib }}
|
||||
{% if code.extlibver is not null %}
|
||||
<strong> Version used: </strong>{{ code.extlibver }}
|
||||
<div class="container-fluid" style="width: 100%; text-align:center">
|
||||
<div class="row">
|
||||
<div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-2 col-xs-offset-2 col-lg-8 col-md-8 col-sm-8 col-xs-8">
|
||||
<h5><a href="{{ path('code',{'idc': code.idc,'lang': code.lang,'version': code.version}) }}">{{ code.name }}</a></h5>
|
||||
</div>
|
||||
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="text-align: right">
|
||||
<h4>
|
||||
<a href="javascript:;" onclick="likeAndSave('l',{{ code.idc }},'{{ code.lang }}'{% if user.nick is defined %},'{{ user.nick }}'{% endif %})"
|
||||
data-toggle="tooltip" data-placement="top" title="" data-original-title="Like">
|
||||
<i class="{% if code.like == 1 %}fas{% else %}far{% endif %} fa-heart" id="l-{{ code.idc }}-{{ code.lang|raw }}" style="padding-right: 0.05em;"></i>
|
||||
</a>
|
||||
<a href="javascript:;" onclick="likeAndSave('s',{{ code.idc }},'{{ code.lang }}'{% if user.nick is defined %},'{{ user.nick }}'{% endif %})"
|
||||
data-toggle="tooltip" data-placement="top" title="" data-original-title="Save">
|
||||
<i class="{% if code.save == 1 %}fas{% else %}far{% endif %} fa-bookmark" id="s-{{ code.idc }}-{{ code.lang }}"></i>
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
{% if page.page!="home"%}
|
||||
{% if code.extlib is defined and code.extlib != "" %}
|
||||
<div class="row">
|
||||
<strong>External library:</strong> {{ code.extlib }}
|
||||
{% if code.extlibver is not null %}
|
||||
<strong> Version used: </strong>{{ code.extlibver }}
|
||||
{% endif %}
|
||||
<div/>
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th colspan="6">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="6">{{ code.description }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="6">Code</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="6">
|
||||
<div class="row">
|
||||
<div class="col-lg-offset-3 col-md-offset-3 col-sm-offset-3 col-xs-offset-3 col-lg-6 col-md-6 col-sm-6 col-xs-6">
|
||||
{% if page.page!="home"%}<strong>Description:</strong> {{ code.description }}{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6" style="text-align: left"><strong>{{ code.lLang }}</strong></div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6" style="text-align: right"><strong>{{ code.nick }}</strong></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
||||
<pre class="highlight"><code class='{{ code.lang }} codeto toHightlight'>{{ code.code }}</code></pre>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
48
Source/assets/html/codebox_firstPage.twig
Normal file
48
Source/assets/html/codebox_firstPage.twig
Normal file
@@ -0,0 +1,48 @@
|
||||
{#<table style="width: 100%; text-align:center">
|
||||
<tr>
|
||||
<th>
|
||||
<h4><a href="{{ path('code',{'idc': code.idc,'lang': code.lang,'version': code.version}) }}">{{ code.name }}</a></h4>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Author:</strong> {{ code.nick }} <strong> Version: </strong>{{ code.version }} <strong>
|
||||
Lang: </strong>{{ code.lLang }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="6">
|
||||
<pre class="highlight"><code class='{{ code.lang }} codeto toHightlight'>{{ code.code }}</code></pre>
|
||||
</td>
|
||||
</tr>
|
||||
</table>#}
|
||||
|
||||
<div class="container-fluid" style="width: 100%; text-align:center">
|
||||
<div class="row">
|
||||
<div class="col-lg-12"><h5><a href="{{ path('code',{'idc': code.idc,'lang': code.lang,'version': code.version}) }}">{{ code.name }}</a></h5></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-12"></div>
|
||||
</div>
|
||||
{% if page.page!=home%}
|
||||
{% if code.extlib is defined and code.extlib != "" %}
|
||||
<div class="row">
|
||||
<strong>External library:</strong> {{ code.extlib }}
|
||||
{% if code.extlibver is not null %}
|
||||
<strong> Version used: </strong>{{ code.extlibver }}
|
||||
{% endif %}
|
||||
<div/>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<strong>Description:</strong> {{ code.description }}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6" style="text-align: left"><strong>{{ code.lLang }}</strong></div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6" style="text-align: right"><strong>{{ code.nick }}</strong></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
||||
<pre class="highlight"><code class='{{ code.lang }} codeto toHightlight'>{{ code.code }}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -12,6 +12,7 @@
|
||||
<p class="text-danger loginMessage" id="POST_ERROR">Error during sign-up, check your data</p>
|
||||
<p class="text-danger loginMessage" id="MAIL_IN_USE">The e-mail is currently in use</p>
|
||||
<p class="text-danger loginMessage" id="NICK_IN_USE">The nickname is currently in use</p>
|
||||
<p class="text-danger loginMessage" id="CONFIRM_MAIL">Please, confirm your email before</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var options = {success: function(data){
|
||||
console.log(data);
|
||||
window.location.href = '{{path('home')}}';
|
||||
},
|
||||
url: '{{ path("restore")}}',
|
||||
} ;
|
||||
|
||||
16
Source/assets/html/saved.twig
Normal file
16
Source/assets/html/saved.twig
Normal file
@@ -0,0 +1,16 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<h5 class="col-sm-offset-1">Saved codes</h5>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-offset-1">
|
||||
<ul class="list-group">
|
||||
{% for s in saved %}
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<a href="{{ path('code',{'idc': s.idc,'lang': s.lang,'version': s.version}) }}">{{ s.name }} on {{ s.lLang }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -3,50 +3,77 @@
|
||||
<h4 style="text-align: center" xmlns="http://www.w3.org/1999/html">{{ user.nick }}</h4>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<p class="col-md-1"><strong>Nickname</strong></p>
|
||||
<p class="col-md-11">{{ user.nick }}</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<p class="col-md-1"><strong>Email</strong></p>
|
||||
<p class="col-md-11">{{ user.email }}</p>
|
||||
</div>
|
||||
<hr/>
|
||||
</div>
|
||||
<div class="container">
|
||||
{% if page.status == 1 %}
|
||||
<p class="text-success">Password updated successfully</p>
|
||||
{% elseif page.status == 2 %}
|
||||
<p class="text-danger">Old password incorrect</p>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<h5 class="col-sm-offset-1">Change password</h5>
|
||||
</div>
|
||||
<div class="row">
|
||||
<form class="form-horizontal" method="post">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2" for="passact">Current password:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" class="form-control" required="required" name="passact" id="passact" placeholder="Current password">
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="navbar-link active" href="#data" role="tab" data-toggle="tab">My information</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="navbar-link" href="#saved" role="tab" data-toggle="tab">Saved codes</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="navbar-link" href="#password" role="tab" data-toggle="tab">Change password</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane fade in active" id="data">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<h5 class="col-sm-offset-1">My information</h5>
|
||||
</div>
|
||||
<div class="row">
|
||||
<p class="col-md-1 col-sm-offset-1"><strong>Nickname</strong></p>
|
||||
<p class="col-md-10">{{ user.nick }}</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<p class="col-md-1 col-sm-offset-1"><strong>Email</strong></p>
|
||||
<p class="col-md-10">{{ user.email }}</p>
|
||||
</div>
|
||||
<hr/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2" for="newpass">New password:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" class="form-control" required="required" name="newpass" id="newpass" onchange="onPasswordChange()" placeholder="New password">
|
||||
<div role="tabpanel" class="tab-pane fade" id="saved">
|
||||
{% include app.fronthtml~'/saved.twig' %}
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane fade" id="password">
|
||||
<div class="container">
|
||||
{% if page.status == 1 %}
|
||||
<p class="text-success">Password updated successfully</p>
|
||||
{% elseif page.status == 2 %}
|
||||
<p class="text-danger">Old password incorrect</p>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<h5 class="col-sm-offset-1">Change password</h5>
|
||||
</div>
|
||||
<div class="row">
|
||||
<form class="form-horizontal" method="post">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2" for="passact">Current password:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" class="form-control" required="required" name="passact" id="passact" placeholder="Current password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2" for="newpass">New password:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" class="form-control" required="required" name="newpass" id="newpass" onchange="onPasswordChange()" placeholder="New password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2" for="newpass-re">Repeat new password:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" class="form-control" required="required" name="newpass-re" id="newpass-re" onchange="onPasswordChange()" placeholder="Repear new password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2" for="newpass-re">Repeat new password:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" class="form-control" required="required" name="newpass-re" id="newpass-re" onchange="onPasswordChange()" placeholder="Repear new password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
69
Source/assets/js/like.js
Normal file
69
Source/assets/js/like.js
Normal file
@@ -0,0 +1,69 @@
|
||||
function likeAndSave(m,c,l,i=null){
|
||||
var b=$('#'+m+"-"+c+"-"+l);
|
||||
var data = {};
|
||||
switch (m) {
|
||||
case 'l':
|
||||
if(b.hasClass('fas')){
|
||||
data.mode = "unvote";
|
||||
data.before = 'fas';
|
||||
data.after = 'far';
|
||||
}else{
|
||||
data.mode = "vote";
|
||||
data.before = 'far';
|
||||
data.after = 'fas';
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if(b.hasClass('fas')){
|
||||
data.mode = "unsave";
|
||||
data.before = 'fas';
|
||||
data.after = 'far';
|
||||
}else{
|
||||
data.mode = "save";
|
||||
data.before = 'far';
|
||||
data.after = 'fas';
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (i==null){
|
||||
window.location.replace('/login')
|
||||
}
|
||||
|
||||
data.idc=c;
|
||||
data.lang=l;
|
||||
|
||||
$.ajax({
|
||||
url: '/vote-save',
|
||||
type: 'POST',
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
traditional: true,
|
||||
success: function(result) {
|
||||
console.log(result);
|
||||
if (result == 0){
|
||||
b.addClass(data.after);
|
||||
b.removeClass(data.before);
|
||||
}
|
||||
else
|
||||
myAlertBottom();
|
||||
|
||||
},
|
||||
error: function (result) {
|
||||
myAlertBottom();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function myAlertTop(){
|
||||
$(".myAlert-top").fadeToggle();
|
||||
setTimeout(function(){
|
||||
$(".myAlert-top").fadeToggle();
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function myAlertBottom(){
|
||||
$(".myAlert-bottom").fadeToggle();
|
||||
setTimeout(function(){
|
||||
$(".myAlert-bottom").fadeToggle();
|
||||
}, 2000);
|
||||
}
|
||||
2
Source/composer.lock
generated
2
Source/composer.lock
generated
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "1d57e016803e2095db2110462e070da3",
|
||||
|
||||
@@ -497,9 +497,12 @@ class DB
|
||||
$libV = "";
|
||||
}
|
||||
|
||||
$save = false;
|
||||
$version = $this->getLastVersion($IDC, $lang);
|
||||
if ($version == null)
|
||||
if ($version == null){
|
||||
$save = true;
|
||||
$version = 0;
|
||||
}
|
||||
$version++;
|
||||
$modification = time();
|
||||
$queryBuilder = $this->newQueryBuilder();
|
||||
@@ -519,6 +522,9 @@ class DB
|
||||
)
|
||||
->setParameters(array($IDC,$lang,$version,$modification,$code,$lib,$libV,$IDU));
|
||||
$this->execute($queryBuilder);
|
||||
if($save){
|
||||
$this->save($IDU, $IDC, $lang);
|
||||
}
|
||||
return $version;
|
||||
}
|
||||
|
||||
@@ -705,6 +711,7 @@ class DB
|
||||
*/
|
||||
public function register($email, $pass, $nick)
|
||||
{
|
||||
$token = RandomString(50);
|
||||
if ($this->loadIDU($email))
|
||||
return 'MAIL_IN_USE';
|
||||
else if ($this->loadIDU($nick,'nick'))
|
||||
@@ -717,10 +724,12 @@ class DB
|
||||
->values(array(
|
||||
'email' => '?',
|
||||
'pass' => '?',
|
||||
'nick' => '?'
|
||||
'nick' => '?',
|
||||
'token' => '?'
|
||||
))
|
||||
->setParameters(array($email,$password,$nick));
|
||||
->setParameters(array($email,$password,$nick,hash('sha256',$token)));
|
||||
$this->execute($queryBuilder);
|
||||
newUser($email, $nick, $token);
|
||||
return 'CORRECT';
|
||||
}
|
||||
}
|
||||
@@ -743,6 +752,24 @@ class DB
|
||||
$this->execute($queryBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set role
|
||||
*
|
||||
* @param $IDU user's identifier
|
||||
* @param $role Role
|
||||
*/
|
||||
public function setRole($IDU, $role=1)
|
||||
{
|
||||
$queryBuilder = $this->newQueryBuilder();
|
||||
$queryBuilder
|
||||
->update('Users')
|
||||
->set('ROLE','?')
|
||||
->where($queryBuilder->expr()->eq('IDU','?'))
|
||||
->setParameter(0,$role)
|
||||
->setParameter(1,$IDU);
|
||||
$this->execute($queryBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change password
|
||||
*
|
||||
@@ -764,9 +791,9 @@ class DB
|
||||
/**
|
||||
* Check if token to restore password is correct
|
||||
*
|
||||
* @param string $nick string nick to restore password
|
||||
* @param string $token random string generate
|
||||
* @param int $timestamp moment when restore activate
|
||||
* @param $nick string $nick string nick to restore password
|
||||
* @param $token string $token random string generate
|
||||
* @param $timestamp int $timestamp moment when restore activate
|
||||
* @return bool true is are similar
|
||||
*/
|
||||
public function checkRestoreToken($nick,$token,$timestamp){
|
||||
@@ -780,6 +807,24 @@ class DB
|
||||
return $tk == hash('sha256',"$token-$timestamp");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if token to confirm is correct
|
||||
*
|
||||
* @param $token string $token random string generate
|
||||
* @param $idu int user identifier
|
||||
* @return bool true is are similar
|
||||
*/
|
||||
public function checkConfirmToken($idu,$token){
|
||||
$queryBuilder = $this->newQueryBuilder();
|
||||
$queryBuilder
|
||||
->select('token')
|
||||
->from('Users')
|
||||
->where($queryBuilder->expr()->eq('idu','?'))
|
||||
->setParameter(0,$idu);
|
||||
$tk = $this->getData($queryBuilder)[0]['token'];
|
||||
return $tk == hash('sha256',"$token");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random token to restore password
|
||||
*
|
||||
@@ -841,7 +886,7 @@ class DB
|
||||
* @return int 0 if correct, 1 if error
|
||||
*/
|
||||
public function vote($idu,$idc,$lang){
|
||||
return $this->voteOrSave($idu,$idc,$lang,"Votes");
|
||||
return $this->voteOrSave($idu,$idc,$lang,"Likes");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -892,7 +937,7 @@ class DB
|
||||
* @return int 0 if correct, 1 if error
|
||||
*/
|
||||
public function unvote($idu,$idc,$lang){
|
||||
return $this->unvoteOrUnsave($idu,$idc,$lang,"Votes");
|
||||
return $this->unvoteOrUnsave($idu,$idc,$lang,"Likes");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -917,18 +962,20 @@ class DB
|
||||
$queryBuilder = $this->newQueryBuilder();
|
||||
$subQuery = $this->newQueryBuilder();
|
||||
$queryBuilder
|
||||
->select(array('s.IDC','s.Lang','s.Version'))
|
||||
->select(array('s.IDC','s.Lang','s.Version','c.Name'))
|
||||
->from('Saves','sa')
|
||||
->join('sa','Sources','s',
|
||||
$queryBuilder->expr()->andX(
|
||||
$queryBuilder->expr()->eq("sa.IDC","s.IDC"),
|
||||
$queryBuilder->expr()->eq("sa.Lang","s.Lang")
|
||||
))
|
||||
->join('s','Codes','c',
|
||||
$queryBuilder->expr()->eq("s.IDC",'c.IDC'))
|
||||
->where(
|
||||
$queryBuilder->expr()->andX(
|
||||
$queryBuilder->expr()->eq("IDU",'?'),
|
||||
$queryBuilder->expr()->eq("sa.IDU",'?'),
|
||||
$queryBuilder->expr()->eq(
|
||||
'so.Version','('.
|
||||
's.Version','('.
|
||||
$subQuery
|
||||
->select('MAX(Version)')
|
||||
->from('Sources')
|
||||
@@ -993,7 +1040,7 @@ class DB
|
||||
* @return int 0 or 1
|
||||
*/
|
||||
public function iVote($idu,$idc,$lang){
|
||||
return $this->iVoteSave($idu,$idc,$lang,"Votes");
|
||||
return $this->iVoteSave($idu,$idc,$lang,"Likes");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,11 +7,13 @@ require_once __DIR__ .'/../vendor/autoload.php';
|
||||
|
||||
require_once __DIR__ . '/Config.php';
|
||||
require 'functions.php';
|
||||
require 'domails.php';
|
||||
require 'DB.php';
|
||||
require 'dbToTable.php';
|
||||
require 'users.php';
|
||||
|
||||
|
||||
|
||||
$app = new Silex\Application();
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -54,6 +56,11 @@ $app->boot();
|
||||
$app->get('/', function (Request $request) use($app) {
|
||||
|
||||
$user = getUser($app);
|
||||
$idu=0;
|
||||
if($user != null){
|
||||
$idu=$app['data']->loadIDU($user['nick'],'nick');
|
||||
}
|
||||
|
||||
$ajax=false;
|
||||
if($request->getMethod()=="POST"){
|
||||
if($request->get('globalSearch')!=null){
|
||||
@@ -65,10 +72,10 @@ $app->get('/', function (Request $request) use($app) {
|
||||
$ajax=true;
|
||||
}
|
||||
$last = $app['data']->loadFilter($data,$type);
|
||||
$last = lastToArray($last,$app['supported']);
|
||||
$last = lastToArray($last,$app['supported'],$app['data'],$idu);
|
||||
}else{
|
||||
$query = $app['data']->loadLast();
|
||||
$last = lastToArray($query,$app['supported']);
|
||||
$last = lastToArray($query,$app['supported'],$app['data'],$idu);
|
||||
}
|
||||
$page = array( 'title' => "CodeShare",
|
||||
"description" => "Sharing your solutions with all",
|
||||
@@ -177,8 +184,11 @@ function loginOrRegister($state,$request){
|
||||
case 3:
|
||||
return loginRegister('login','BAD_CREDENTIAL');
|
||||
case 1:
|
||||
if(checklogin($request->get('email'),$request->get('pwd'),$app['data'])==''){
|
||||
$result = checklogin($request->get('email'),$request->get('pwd'),$app['data']);
|
||||
if($result==''){
|
||||
return 'redirect';
|
||||
}else if($result=='VALIDATE'){
|
||||
return loginRegister('login','CONFIRM_MAIL');
|
||||
}else{
|
||||
return loginRegister("login",'BAD_CREDENTIAL');
|
||||
}
|
||||
@@ -221,7 +231,8 @@ $app->get('/user', function(Request $request) use ($app){
|
||||
"description" => "NOT RELEVANT",
|
||||
"status" => $status
|
||||
);
|
||||
return $app['twig']->render($app['fronthtml']."/user.twig",array("page"=>$page,"user"=>$user));
|
||||
$saved = $app['data']->allSaves($app['data']->loadIDU($user['nick'],'nick'));
|
||||
return $app['twig']->render($app['fronthtml']."/user.twig",array("page"=>$page,"user"=>$user,"saved"=>savedToArray($saved,$app['supported'])));
|
||||
|
||||
})->bind('user')->method('GET|POST');
|
||||
|
||||
@@ -300,7 +311,11 @@ $app->get('/code/{lang}-{idc}-{version}', function (Request $request, $lang, $id
|
||||
"existedLangs" => $app['data']->loadLangs($idc),
|
||||
"original" => $app['data']->loadOriginalAuthor($idc),
|
||||
);
|
||||
$code = allCodeToArray($array,$app['supported']);
|
||||
$idu=0;
|
||||
if($user != null){
|
||||
$idu=$app['data']->loadIDU($user['nick'],'nick');
|
||||
}
|
||||
$code = allCodeToArray($array,$app['supported'],$app['data'],$idu);
|
||||
if($array['Version']!=1)
|
||||
$page['otherV'] = true;
|
||||
$diff = $app['data']->loadDiff($idc,$lang);
|
||||
@@ -418,7 +433,17 @@ $app->get('/add', function(Request $request) use($app){
|
||||
$app->get('/restore', function(Request $request) use($app){
|
||||
|
||||
if($request->getMethod()=="POST"){
|
||||
return $app['data']->createRestoreToken($request->get('emailre'));
|
||||
$parts = $app['data']->createRestoreToken($request->get('emailre'));
|
||||
$parts = explode("-", $parts);
|
||||
$token = $parts[0];
|
||||
$timestamp = $parts[1];
|
||||
restorePassword(
|
||||
$request->get('emailre'),
|
||||
$app['data']->loadProfile($app['data']->loadIDU($request->get('emailre')))['nick'],
|
||||
$token,
|
||||
$timestamp
|
||||
);
|
||||
return "UPDATE";
|
||||
}
|
||||
$page = array("title"=>"Restore your password",
|
||||
"description"=>"None",
|
||||
@@ -464,6 +489,16 @@ $app->get('/restore/{nick}/{token}-{timestamp}', function(Request $request, $nic
|
||||
}
|
||||
})->bind('restorePass')->method('GET|POST');
|
||||
|
||||
$app->get('/confirm/{nick}-{token}', function(Request $request, $nick, $token) use($app){
|
||||
$idu=$app['data']->loadIDU($nick,'nick');
|
||||
$res = $app['data']->checkConfirmToken($idu,$token);
|
||||
if($res)
|
||||
$app['data']->setRole($idu);
|
||||
else
|
||||
$app->abort(401);
|
||||
return $app->redirect($app['url_generator']->generate('login'));
|
||||
})->bind('confirm');
|
||||
|
||||
/* Votes and saves */
|
||||
|
||||
$app->post('/vote-save',function(Request $request) use($app){
|
||||
@@ -474,15 +509,16 @@ $app->post('/vote-save',function(Request $request) use($app){
|
||||
|
||||
$data = str_replace('"','"',$request->getContent());
|
||||
$data = json_decode($data,true);
|
||||
$idu = $app['data']->loadIDU($user['nick'],'nick');
|
||||
switch($data['mode']){
|
||||
case "vote":
|
||||
return $app['data']->vote($user['idu'],$data['idc'],$data['lang']);
|
||||
return $app['data']->vote($idu,$data['idc'],$data['lang']);
|
||||
case "unvote":
|
||||
return $app['data']->unvote($user['idu'],$data['idc'],$data['lang']);
|
||||
return $app['data']->unvote($idu,$data['idc'],$data['lang']);
|
||||
case "save":
|
||||
return $app['data']->save($user['idu'],$data['idc'],$data['lang']);
|
||||
return $app['data']->save($idu,$data['idc'],$data['lang']);
|
||||
case "unsave":
|
||||
return $app['data']->unsave($user['idu'],$data['idc'],$data['lang']);
|
||||
return $app['data']->unsave($idu,$data['idc'],$data['lang']);
|
||||
}
|
||||
return 1;
|
||||
|
||||
|
||||
@@ -11,10 +11,16 @@
|
||||
* Methods to get an array to send to twig
|
||||
*/
|
||||
|
||||
function lastToArray(&$query,$supported){
|
||||
function lastToArray(&$query,$supported,$db,$idu=0){
|
||||
$last = array();
|
||||
$list = $query->fetchAll();
|
||||
foreach($list as $var){
|
||||
$like=0;
|
||||
$save=0;
|
||||
if($idu!=0){
|
||||
$like = $db->iVote($idu,$var['IDC'],$var['Lang']);
|
||||
$save = $db->iSave($idu,$var['IDC'],$var['Lang']);
|
||||
}
|
||||
$array = array
|
||||
( "idc" => $var["IDC"],
|
||||
"lang" => $var["Lang"],
|
||||
@@ -24,13 +30,21 @@ function lastToArray(&$query,$supported){
|
||||
"lLang" => $supported[$var["Lang"]][0],
|
||||
"description" => $var["Description"],
|
||||
"code" => html_entity_decode($var["Code"]),
|
||||
"like" => $like,
|
||||
"save" => $save
|
||||
);
|
||||
array_push($last,$array);
|
||||
}
|
||||
return $last;
|
||||
}
|
||||
|
||||
function allCodeToArray(&$query,$supported){
|
||||
function allCodeToArray(&$query,$supported,$db,$idu=0){
|
||||
$like=0;
|
||||
$save=0;
|
||||
if($idu!=0){
|
||||
$like = $db->iVote($idu,$query['IDC'],$query['Lang']);
|
||||
$save = $db->iSave($idu,$query['IDC'],$query['Lang']);
|
||||
}
|
||||
$code = array(
|
||||
"idc" => $query['IDC'],
|
||||
"lang" => $query['Lang'],
|
||||
@@ -46,6 +60,8 @@ function allCodeToArray(&$query,$supported){
|
||||
"rows" => substr_count($query['Code'],"\n"),
|
||||
"extlib" => $query['UseExtLib'],
|
||||
"extlibver" => $query['UseExtLibVer'],
|
||||
"like" => $like,
|
||||
"save" => $save
|
||||
);
|
||||
return $code;
|
||||
|
||||
@@ -65,6 +81,22 @@ function otherImplementationToArray(&$query,$supported){
|
||||
return $other;
|
||||
}
|
||||
|
||||
function savedToArray($query,$supported){
|
||||
$saved = array();
|
||||
foreach($query as $var){
|
||||
$array = array
|
||||
(
|
||||
"idc" => $var['IDC'],
|
||||
"lang" => $var['Lang'],
|
||||
"version" => $var['Version'],
|
||||
"lLang" => $supported[$var["Lang"]][0],
|
||||
"name" => $var['Name']
|
||||
);
|
||||
array_push($saved,$array);
|
||||
}
|
||||
return $saved;
|
||||
}
|
||||
|
||||
function otherVersionToArray(&$query,$supported){
|
||||
return lastToArray($query,$supported);
|
||||
}
|
||||
29
Source/src/domails.php
Normal file
29
Source/src/domails.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
function newUser($email,$nick,$token){
|
||||
global $app;
|
||||
|
||||
$header = 'From: CodeShare ' . "contacto@jkanetwork.com\r\n";
|
||||
$header .= "MIME-Version: 1.0\r\n";
|
||||
$header .= "Content-Type: text/html; charset=UTF-8";
|
||||
$to = $email;
|
||||
$url = $app['url_generator']->generate('confirm',array('nick'=>$nick,'token'=>$token));
|
||||
$correo = "<p>Wellcome to CodeShare $nick, the distribution platform for code fragments</p>
|
||||
<p>To confirm your account please, click in the next link: <a href='https://codeshare.jkanetwork.com/$url'>https://codeshare.jkanetwork.com/$url</a></p>";
|
||||
mail($to,"Confirm account to $nick",$correo,$header);
|
||||
}
|
||||
|
||||
function restorePassword($email,$nick,$token,$timestamp){
|
||||
global $app;
|
||||
|
||||
$header = 'From: CodeShare ' . "contacto@jkanetwork.com\r\n";
|
||||
$header .= "MIME-Version: 1.0\r\n";
|
||||
$header .= "Content-Type: text/html; charset=UTF-8";
|
||||
$to = $email;
|
||||
$url = $app['url_generator']->generate('restorePass',array('nick'=>$nick,'token'=>$token,'timestamp' => $timestamp));
|
||||
$correo = "<p>Someone requested that the password be reset for you</p>
|
||||
<p>If this was a mistake, just ignore this email and nothing will happen.</p>
|
||||
<p>To restore your password please, click in the next link: <a href='https://codeshare.jkanetwork.com/$url'>https://codeshare.jkanetwork.com/$url</a></p>";
|
||||
mail($to,"Restore password to $nick",$correo,$header);
|
||||
|
||||
}
|
||||
@@ -24,11 +24,13 @@ function checkInfo($request){
|
||||
* @param $pass user's input password
|
||||
* @return bool true if email-password combination is correct, false if not
|
||||
*/
|
||||
function checklogin($email,$pass,$db){
|
||||
function checklogin($email,$pass,DB $db){
|
||||
$bool = $db->checkPass($email,$pass);
|
||||
|
||||
if($bool){
|
||||
$idu = $db->loadIDU($email);
|
||||
$ROLE = $db->loadProfile($idu)['ROLE'];
|
||||
if($ROLE==0)
|
||||
return 'VALIDATE';
|
||||
$token = RandomString(50);
|
||||
$db->setToken($idu,$token);
|
||||
$_SESSION['token'] = $token;
|
||||
|
||||
Reference in New Issue
Block a user