Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Akamu
Game Server Go
Commits
5379acd1
Commit
5379acd1
authored
Oct 04, 2020
by
Julien Schröter
Committed by
Julien Schröter
Oct 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create repository method to fetch userdata incl an hash of the password
parent
53d71c6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
0 deletions
+35
-0
endpoint/user/query.go
endpoint/user/query.go
+24
-0
schemas/user.go
schemas/user.go
+7
-0
test/user_test.go
test/user_test.go
+4
-0
No files found.
endpoint/user/query.go
View file @
5379acd1
...
...
@@ -31,6 +31,7 @@ type UserQuery interface {
Insert
(
user
*
schemas
.
FullUserSchema
,
password
string
)
(
id
uint32
,
err
error
)
Select
(
id
uint32
)
([]
schemas
.
FullUserSchema
,
error
)
SelectByUsername
(
username
string
)
([]
schemas
.
InfoUserSchema
,
error
)
SelectCredentialsByField
(
field
UserField
,
value
interface
{})
(
*
schemas
.
CredentialsSchema
,
error
)
Authenticate
(
name
string
,
password
string
)
(
uint32
,
error
)
Update
(
userID
uint32
,
params
PatchUserRequest
,
titleRepository
title
.
TitleQuery
)
error
UpdatePassword
(
userID
uint32
,
password
string
)
error
...
...
@@ -38,6 +39,12 @@ type UserQuery interface {
VerifyUser
(
uint32
,
string
)
error
}
type
UserField
string
const
FieldID
UserField
=
"iduser"
const
FieldUsername
UserField
=
"username"
const
FieldEmail
UserField
=
"email"
type
MySQLUserQuery
struct
{}
/*
...
...
@@ -236,6 +243,23 @@ func (MySQLUserQuery) Select(id uint32) ([]schemas.FullUserSchema, error) {
return
users
,
nil
}
func
(
MySQLUserQuery
)
SelectCredentialsByField
(
field
UserField
,
value
interface
{})
(
*
schemas
.
CredentialsSchema
,
error
)
{
db
,
err
:=
dbhandler
.
GetDBConnection
()
if
err
!=
nil
{
return
nil
,
err
}
row
:=
db
.
QueryRow
(
fmt
.
Sprintf
(
"SELECT iduser, username, email, SHA2(password, 512) FROM `user` WHERE %s=?"
,
field
),
value
)
var
result
schemas
.
CredentialsSchema
if
err
:=
row
.
Scan
(
&
result
.
ID
,
&
result
.
Username
,
&
result
.
Email
,
&
result
.
PasswordCipher
);
err
!=
nil
{
return
nil
,
err
}
return
&
result
,
nil
}
func
(
MySQLUserQuery
)
SelectByUsername
(
username
string
)
([]
schemas
.
InfoUserSchema
,
error
)
{
db
,
err
:=
dbhandler
.
GetDBConnection
()
if
err
!=
nil
{
...
...
schemas/user.go
View file @
5379acd1
...
...
@@ -23,6 +23,13 @@ type FullUserSchema struct {
Verified
bool
`json:"verified,omitempty"`
}
type
CredentialsSchema
struct
{
ID
uint32
Username
string
Email
string
PasswordCipher
string
}
// InfoUserFromFullUser creates and returns an InfoUserSchema struct from a given FullUserSchema
func
InfoUserFromFullUser
(
user
FullUserSchema
)
InfoUserSchema
{
return
InfoUserSchema
{
...
...
test/user_test.go
View file @
5379acd1
...
...
@@ -107,6 +107,10 @@ var errBadRequest = user.ErrBadRequest
type
mockUser
struct
{
}
func
(
mockUser
)
SelectCredentialsByField
(
field
user
.
UserField
,
value
interface
{})
(
*
schemas
.
CredentialsSchema
,
error
)
{
return
nil
,
errors
.
New
(
"method SelectCredentialsByField not implemented"
)
}
func
(
mockUser
)
Insert
(
user
*
schemas
.
FullUserSchema
,
password
string
)
(
id
uint32
,
err
error
)
{
if
_
,
exists
:=
getMockUserByName
(
user
.
Username
);
exists
{
return
0
,
errors
.
New
(
"User already exists"
)
...
...
Write
Preview
Markdown
is supported
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