Commit e2ec2f21 authored by Kevin Whitaker's avatar Kevin Whitaker

Worked changing password into admin.

parent d9ebd4fe
......@@ -19,25 +19,35 @@
#include "AdminInterface.h"
#include "../db/UserAction.h"
#include <Wt/Auth/HashFunction>
AdminInterface::AdminInterface(WebInterface* app)
{
this->app = app;
this->setMaximumSize(Wt::WLength::Auto,Wt::WLength(175,Wt::WLength::Pixel));
this->setOverflow(OverflowHidden);
pageLayout = new Wt::WVBoxLayout();
userLayout = new Wt::WHBoxLayout();
actionLayout = new Wt::WHBoxLayout();
usernameField = new Wt::WLineEdit();
passwordField = new Wt::WLineEdit();
addBtn = new Wt::WPushButton("&#61525;");
changeBtn = new Wt::WPushButton("&#61470;");
this->setLayout(userLayout);
this->setLayout(pageLayout);
pageLayout->addLayout(userLayout);
pageLayout->addLayout(actionLayout);
userLayout->addWidget(usernameField);
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);
addBtn->setTextFormat(Wt::XHTMLText);
addBtn->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
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()
......@@ -76,3 +86,36 @@ void AdminInterface::addClicked()
usernameField->setText("created user");
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 "../WebInterface.h"
#include <Wt/WHBoxLayout>
#include <Wt/WVBoxLayout>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
......@@ -33,12 +34,16 @@ public:
~AdminInterface();
WebInterface* app;
Wt::WVBoxLayout* pageLayout;
Wt::WHBoxLayout* userLayout;
Wt::WHBoxLayout* actionLayout;
Wt::WLineEdit* usernameField;
Wt::WLineEdit* passwordField;
Wt::WPushButton* addBtn;
Wt::WPushButton* changeBtn;
void addClicked();
void changeClicked();
};
#endif // ADMININTERFACE_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment