mirror of
https://github.com/pushbits/server.git
synced 2025-06-03 19:22:05 +02:00
Introduce middleware for parsing ID from URI
This commit is contained in:
parent
e1cd2d2f8e
commit
018ce2e537
8 changed files with 74 additions and 50 deletions
|
@ -29,8 +29,8 @@ type UserCredentials struct {
|
|||
Password string `json:"password,omitempty" form:"password" query:"password" binding:"required"`
|
||||
}
|
||||
|
||||
// ExternalUserWithCredentials represents a user for external purposes and includes the user's credentials in plaintext.
|
||||
type ExternalUserWithCredentials struct {
|
||||
// CreateUser is used to process queries for creating users.
|
||||
type CreateUser struct {
|
||||
ExternalUser
|
||||
UserCredentials
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ func NewUser(cm *credentials.Manager, name, password string, isAdmin bool, matri
|
|||
}
|
||||
}
|
||||
|
||||
// IntoInternalUser converts a ExternalUserWithCredentials into a User.
|
||||
func (u *ExternalUserWithCredentials) IntoInternalUser(cm *credentials.Manager) *User {
|
||||
// IntoInternalUser converts a CreateUser into a User.
|
||||
func (u *CreateUser) IntoInternalUser(cm *credentials.Manager) *User {
|
||||
return &User{
|
||||
Name: u.Name,
|
||||
PasswordHash: cm.CreatePasswordHash(u.Password),
|
||||
|
@ -67,18 +67,8 @@ func (u *User) IntoExternalUser() *ExternalUser {
|
|||
}
|
||||
}
|
||||
|
||||
type userIdentification struct {
|
||||
ID uint `uri:"id" binding:"required"`
|
||||
}
|
||||
|
||||
// DeleteUser is used to process queries for deleting users.
|
||||
type DeleteUser struct {
|
||||
userIdentification
|
||||
}
|
||||
|
||||
// UpdateUser is used to process queries for updating users.
|
||||
type UpdateUser struct {
|
||||
userIdentification
|
||||
Name string `json:"name"`
|
||||
Password string `json:"password"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue