69 lines
2.5 KiB
C++
69 lines
2.5 KiB
C++
/*
|
|
* Copyright (C) 2017 Kevin Whitaker <eyecreate@gmail.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*
|
|
*/
|
|
|
|
#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);
|
|
}
|