/* * Copyright (C) 2017 Kevin Whitaker * * 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"); sqlSession.mapClass("tracks"); sqlSession.mapClass("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("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); }