mirror of
https://gitlab.com/CodeSolutionsProject/CodeShare.git
synced 2026-02-25 06:13:48 +01:00
@@ -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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user