Skip to content

Commit

Permalink
basics for user management
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-Duduf committed Jul 12, 2017
1 parent 603c6f0 commit 232cc1f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
2 changes: 2 additions & 0 deletions REST server/index.php
Expand Up @@ -52,6 +52,8 @@
{
if (isset($_SESSION["login"]) AND $_SESSION["login"])//if logged in
{
//users
include ("users.php");
//statuses
include ("statuses.php");
//stages
Expand Down
12 changes: 8 additions & 4 deletions REST server/login.php
Expand Up @@ -23,16 +23,15 @@
$data = json_decode(file_get_contents('php://input'));
if ($data)
{
$username = $data->{'username'};
$password = $data->{'password'};
if (isset($data->{'username'})) $username = $data->{'username'};
if (isset($data->{'password'})) $password = $data->{'password'};
}
}

//get login informations from URL
if (strlen($username) > 0 AND strlen($password) > 0)
{
//query the database
$rep = $bdd->prepare("SELECT password FROM " . $tablePrefix . "users WHERE username = :username ;");
$rep = $bdd->prepare("SELECT password,firstName,lastName,uuid FROM " . $tablePrefix . "users WHERE username = :username ;");
$rep->execute(array('username' => $username));
$testPass = $rep->fetch();
$rep->closeCursor();
Expand All @@ -41,6 +40,11 @@
if ($testPass["password"] == $password)
{
$_SESSION["login"] = true;
$content = array();
$content["firstName"] = $testPass["firstName"];
$content["lastName"] = $testPass["lastName"];
$content["uuid"] = $testPass["uuid"];
$reply["content"] = $content;
$reply["message"] = "Successful login. Welcome " . $username . "!";
$reply["success"] = true;
echo json_encode($reply);
Expand Down
47 changes: 47 additions & 0 deletions REST server/users.php
@@ -0,0 +1,47 @@
<?php
/*
Rainbox Asset Manager
User Management
*/
// ========= UPDATE STATUS ==========
if ($reply["type"] == "updateUser")
{
$reply["accepted"] = true;

$userName = "";
$firstName = "";
$lastName = "";
$password = "";
$uuid = "";

$data = json_decode(file_get_contents('php://input'));
if ($data)
{
if(isset($data->{'userName'})) $userName = $data->{'userName'};
if(isset($data->{'firstName'})) $firstName = $data->{'firstName'};
if(isset($data->{'lastName'})) $lastName = $data->{'lastName'};
if(isset($data->{'password'})) $password = $data->{'password'};
if(isset($data->{'uuid'})) $uuid = $data->{'uuid'};

}

if (strlen($userName) > 0 AND strlen($uuid) > 0 AND strlen($password) > 0)
{
$qString = "UPDATE " . $tablePrefix . "users SET userName= :userName ,firstName= :firstName ,lastName= :lastName ,password= :password WHERE uuid= :uuid ;";

$rep = $bdd->prepare($qString);
$rep->execute(array('userName' => $userName, 'firstName' => $firstName, 'lastName' => $lastName, 'password' => $password, 'uuid' => $uuid));
$rep->closeCursor();

$reply["message"] = "User " . $userName . " updated.";
$reply["success"] = true;
}
else
{
$reply["message"] = "Invalid request, missing values";
$reply["success"] = false;
}

}

?>
16 changes: 16 additions & 0 deletions Ramses/dbinterface.cpp
Expand Up @@ -284,6 +284,22 @@ void DBInterface::sslError(QNetworkReply *rep, QList<QSslError> errs)
emit message("SSL Error. Connection may not be secured.","warning");
}

//USERS
void DBInterface::updateUser(QString uuid, QString userName, QString firstName, QString lastName, QString password)
{
QString q = "?type=updateUser";
QJsonObject obj;
obj.insert("uuid",uuid);
obj.insert("userName",userName);
obj.insert("firstName",firstName);
obj.insert("lastName",lastName);
obj.insert("password",password);
QJsonDocument json(obj);

emit message("Submitting user","remote");
sendRequest(q,json);
}

//STATUS
void DBInterface::addStatus(QString name,QString shortName,QString color,QString description,QString uuid)
{
Expand Down
2 changes: 2 additions & 0 deletions Ramses/dbinterface.h
Expand Up @@ -25,6 +25,8 @@ class DBInterface : public QObject
//connection
void connection(QString user,QString passHash);
void sendRequest(QString request, QJsonDocument content = QJsonDocument());
//Users
void updateUser(QString uuid, QString userName, QString firstName, QString lastName, QString password);
//Status
void addStatus(QString name = "New status", QString shortName = "New", QString color = "6d6d6d", QString description = "", QString uuid = "");
void getStatuses();
Expand Down

0 comments on commit 232cc1f

Please sign in to comment.