Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Kevin Whitaker
Arbitrateor
Commits
4f2a0c5d
Commit
4f2a0c5d
authored
Feb 21, 2017
by
Kevin Whitaker
Browse files
Finish adding user creation to admin screen.
parent
5a602cdd
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/WebInterface.cpp
View file @
4f2a0c5d
...
...
@@ -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.
...
...
src/WebInterface.h
View file @
4f2a0c5d
...
...
@@ -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
;
...
...
src/ui/AdminInterface.cpp
View file @
4f2a0c5d
...
...
@@ -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
);
}
src/ui/AdminInterface.h
View file @
4f2a0c5d
...
...
@@ -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
src/ui/LoginInterface.h
View file @
4f2a0c5d
...
...
@@ -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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment