Worked changing password into admin.
This commit is contained in:
@@ -19,25 +19,35 @@
|
|||||||
|
|
||||||
#include "AdminInterface.h"
|
#include "AdminInterface.h"
|
||||||
#include "../db/UserAction.h"
|
#include "../db/UserAction.h"
|
||||||
|
#include <Wt/Auth/HashFunction>
|
||||||
|
|
||||||
AdminInterface::AdminInterface(WebInterface* app)
|
AdminInterface::AdminInterface(WebInterface* app)
|
||||||
{
|
{
|
||||||
this->app = app;
|
this->app = app;
|
||||||
this->setMaximumSize(Wt::WLength::Auto,Wt::WLength(175,Wt::WLength::Pixel));
|
this->setMaximumSize(Wt::WLength::Auto,Wt::WLength(175,Wt::WLength::Pixel));
|
||||||
this->setOverflow(OverflowHidden);
|
this->setOverflow(OverflowHidden);
|
||||||
|
pageLayout = new Wt::WVBoxLayout();
|
||||||
userLayout = new Wt::WHBoxLayout();
|
userLayout = new Wt::WHBoxLayout();
|
||||||
|
actionLayout = new Wt::WHBoxLayout();
|
||||||
usernameField = new Wt::WLineEdit();
|
usernameField = new Wt::WLineEdit();
|
||||||
passwordField = new Wt::WLineEdit();
|
passwordField = new Wt::WLineEdit();
|
||||||
addBtn = new Wt::WPushButton("");
|
addBtn = new Wt::WPushButton("");
|
||||||
|
changeBtn = new Wt::WPushButton("");
|
||||||
|
|
||||||
this->setLayout(userLayout);
|
this->setLayout(pageLayout);
|
||||||
|
pageLayout->addLayout(userLayout);
|
||||||
|
pageLayout->addLayout(actionLayout);
|
||||||
userLayout->addWidget(usernameField);
|
userLayout->addWidget(usernameField);
|
||||||
userLayout->addWidget(passwordField);
|
userLayout->addWidget(passwordField);
|
||||||
userLayout->addWidget(addBtn);
|
actionLayout->addWidget(addBtn,0,Wt::AlignmentFlag::AlignLeft);
|
||||||
|
actionLayout->addWidget(changeBtn,0,Wt::AlignmentFlag::AlignLeft);
|
||||||
passwordField->setEchoMode(Wt::WLineEdit::EchoMode::Password);
|
passwordField->setEchoMode(Wt::WLineEdit::EchoMode::Password);
|
||||||
addBtn->setTextFormat(Wt::XHTMLText);
|
addBtn->setTextFormat(Wt::XHTMLText);
|
||||||
addBtn->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
|
addBtn->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
|
||||||
addBtn->clicked().connect(this, &AdminInterface::addClicked);
|
addBtn->clicked().connect(this, &AdminInterface::addClicked);
|
||||||
|
changeBtn->setTextFormat(Wt::XHTMLText);
|
||||||
|
changeBtn->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
|
||||||
|
changeBtn->clicked().connect(this, &AdminInterface::changeClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
AdminInterface::~AdminInterface()
|
AdminInterface::~AdminInterface()
|
||||||
@@ -76,3 +86,36 @@ void AdminInterface::addClicked()
|
|||||||
usernameField->setText("created user");
|
usernameField->setText("created user");
|
||||||
passwordField->setText("");
|
passwordField->setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AdminInterface::changeClicked()
|
||||||
|
{
|
||||||
|
Wt::Dbo::Session sqlSession;
|
||||||
|
sqlSession.setConnectionPool(*GroovePlayerMgr::getInstance()->connectionPool);
|
||||||
|
sqlSession.mapClass<User>("user");
|
||||||
|
sqlSession.mapClass<AudioTrack>("tracks");
|
||||||
|
sqlSession.mapClass<UserAction>("actions");
|
||||||
|
Wt::Dbo::Transaction changeUserTransaction(sqlSession);
|
||||||
|
|
||||||
|
//Make sure user is valid to add
|
||||||
|
if(usernameField->text().empty() || passwordField->text().empty())
|
||||||
|
{
|
||||||
|
usernameField->setText("");
|
||||||
|
passwordField->setText("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int usernameMatching = sqlSession.query<int>("select count(username) from user").where("username = ?").bind(usernameField->text().toUTF8());
|
||||||
|
if(usernameMatching > 0)
|
||||||
|
{
|
||||||
|
Wt::Dbo::ptr<User> user = sqlSession.find<User>().where("username = ?").bind(usernameField->text().toUTF8());
|
||||||
|
Wt::Auth::BCryptHashFunction hasher;
|
||||||
|
user.modify()->passwordHash = hasher.compute(passwordField->text().toUTF8(), user->passwordSalt);
|
||||||
|
usernameField->setText("User password changed.");
|
||||||
|
passwordField->setText("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
usernameField->setText("User doesn't exist");
|
||||||
|
passwordField->setText("");
|
||||||
|
}
|
||||||
|
changeUserTransaction.commit();
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <Wt/WContainerWidget>
|
#include <Wt/WContainerWidget>
|
||||||
#include "../WebInterface.h"
|
#include "../WebInterface.h"
|
||||||
#include <Wt/WHBoxLayout>
|
#include <Wt/WHBoxLayout>
|
||||||
|
#include <Wt/WVBoxLayout>
|
||||||
#include <Wt/WLineEdit>
|
#include <Wt/WLineEdit>
|
||||||
#include <Wt/WPushButton>
|
#include <Wt/WPushButton>
|
||||||
|
|
||||||
@@ -33,12 +34,16 @@ public:
|
|||||||
~AdminInterface();
|
~AdminInterface();
|
||||||
WebInterface* app;
|
WebInterface* app;
|
||||||
|
|
||||||
|
Wt::WVBoxLayout* pageLayout;
|
||||||
Wt::WHBoxLayout* userLayout;
|
Wt::WHBoxLayout* userLayout;
|
||||||
|
Wt::WHBoxLayout* actionLayout;
|
||||||
Wt::WLineEdit* usernameField;
|
Wt::WLineEdit* usernameField;
|
||||||
Wt::WLineEdit* passwordField;
|
Wt::WLineEdit* passwordField;
|
||||||
Wt::WPushButton* addBtn;
|
Wt::WPushButton* addBtn;
|
||||||
|
Wt::WPushButton* changeBtn;
|
||||||
|
|
||||||
void addClicked();
|
void addClicked();
|
||||||
|
void changeClicked();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADMININTERFACE_H
|
#endif // ADMININTERFACE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user