Add invite user feature for admin
This commit is contained in:
30
internal/routes/inviteuserpost.go
Normal file
30
internal/routes/inviteuserpost.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.artlef.fr/bibliomane/internal/appcontext"
|
||||
"git.artlef.fr/bibliomane/internal/createuser"
|
||||
"git.artlef.fr/bibliomane/internal/dto"
|
||||
"git.artlef.fr/bibliomane/internal/myvalidator"
|
||||
)
|
||||
|
||||
func InviteUserHandler(ac appcontext.AppContext) {
|
||||
var user dto.UserToInvite
|
||||
|
||||
err := ac.C.ShouldBindJSON(&user)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
|
||||
userDb, err := createuser.CreateUserToActivate(ac, user.Username)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
ac.C.JSON(http.StatusOK, dto.InviteUserPost{
|
||||
ID: userDb.ID,
|
||||
Token: userDb.InviteToken,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user