Finish adding user creation to admin screen.

This commit is contained in:
Kevin Whitaker
2017-02-21 01:31:07 -05:00
parent 5a602cddaa
commit 4f2a0c5d4d
5 changed files with 60 additions and 1 deletions

View File

@@ -18,8 +18,51 @@
*/
#include "AdminInterface.h"
#include "../db/UserAction.h"
AdminInterface::AdminInterface(WebInterface* app)
{
this->app = app;
this->setMaximumSize(Wt::WLength::Auto,Wt::WLength(175,Wt::WLength::Pixel));
this->setOverflow(OverflowHidden);
userLayout = new Wt::WHBoxLayout();
usernameField = new Wt::WLineEdit();
passwordField = new Wt::WLineEdit();
addBtn = new Wt::WPushButton("");
this->setLayout(userLayout);
userLayout->addWidget(usernameField);
userLayout->addWidget(passwordField);
userLayout->addWidget(addBtn);
passwordField->setEchoMode(Wt::WLineEdit::EchoMode::Password);
addBtn->setTextFormat(Wt::XHTMLText);
addBtn->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
addBtn->clicked().connect(this, &AdminInterface::addClicked);
}
void AdminInterface::addClicked()
{
Wt::Dbo::Session sqlSession;
sqlSession.setConnectionPool(*GroovePlayerMgr::getInstance()->connectionPool);
sqlSession.mapClass<User>("user");
sqlSession.mapClass<AudioTrack>("tracks");
sqlSession.mapClass<UserAction>("actions");
Wt::Dbo::Transaction addUserTransaction(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)
{
usernameField->setText("already exists");
return;
}
//Add user
app->createUser(&sqlSession, usernameField->text().toUTF8(), passwordField->text().toUTF8(), false);
}