Commit 4f2a0c5d authored by Kevin Whitaker's avatar Kevin Whitaker

Finish adding user creation to admin screen.

parent 5a602cdd
......@@ -57,6 +57,11 @@ WebInterface::~WebInterface()
delete priv_int;
}
void WebInterface::createUser(Wt::Dbo::Session* session, std::string username, std::string rawPassword, bool isAdmin)
{
priv_int->loginUI->createUser(session, username, rawPassword, isAdmin);
}
void WebInterface::loginCompleted()
{
//Login completed, now bring up main inteface.
......
......@@ -39,6 +39,7 @@ public:
void skipVoteUpdateFromServer(User userVoting, bool forSkip);
void voteNextSongFromServer(User userVoting, AudioTrack trackVoted);
void voteNextPollClosedFromServer(AudioTrack winner);
void createUser(Wt::Dbo::Session* session, std::string username, std::string rawPassword, bool isAdmin);
User currentUser;
private:
struct internal;
......
......@@ -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);
}
......@@ -22,12 +22,22 @@
#include <Wt/WContainerWidget>
#include "../WebInterface.h"
#include <Wt/WHBoxLayout>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
class AdminInterface : public Wt::WContainerWidget
{
public:
AdminInterface(WebInterface* app);
WebInterface* app;
Wt::WHBoxLayout* userLayout;
Wt::WLineEdit* usernameField;
Wt::WLineEdit* passwordField;
Wt::WPushButton* addBtn;
void addClicked();
};
#endif // ADMININTERFACE_H
......@@ -34,6 +34,7 @@ class LoginInterface : public Wt::WContainerWidget
public:
LoginInterface(WebInterface* app);
void checkSessionValidity();
void createUser(Wt::Dbo::Session* session, std::string username, std::string rawPassword, bool isAdmin);
private:
Wt::WPushButton* loginButton;
Wt::WVBoxLayout* loginLayout;
......@@ -47,7 +48,6 @@ private:
Wt::WText* loginMessage;
WebInterface* app;
void loginCheck();
void createUser(Wt::Dbo::Session* session, std::string username, std::string rawPassword, bool isAdmin);
int getUserCount(Wt::Dbo::Session* session);
User getUserForLoginCookie(Wt::Dbo::Session* session, std::string cookie);
User getUserForLoginAuth(Wt::Dbo::Session* session, std::string username, std::string rawPassword);
......
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