47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/kataras/iris/v12"
|
|
"main/jwtSet"
|
|
"main/utils"
|
|
)
|
|
|
|
func User(party iris.Party) {
|
|
party.Get("/", jwtSet.Jwt.Serve, userinfo)
|
|
party.Put("/", jwtSet.Jwt.Serve, updateUserinfo)
|
|
party.Post("/", func(context iris.Context) {
|
|
token, err := register(context)
|
|
if utils.ErrHandle(context, err) {
|
|
return
|
|
}
|
|
err = context.JSON(utils.FormatRes(iris.StatusOK, "", token))
|
|
if err != nil {
|
|
return
|
|
}
|
|
})
|
|
party.Get("/login", func(context iris.Context) {
|
|
user := context.URLParam("username")
|
|
pubKey, err := utils.GetPublicKey(user)
|
|
if utils.ErrHandle(context, err) {
|
|
return
|
|
}
|
|
err = context.JSON(utils.FormatRes(200, "", pubKey))
|
|
if err != nil {
|
|
return
|
|
}
|
|
})
|
|
party.Post("/login", func(ctx iris.Context) {
|
|
token, err := login(ctx)
|
|
if utils.ErrHandle(ctx, err) {
|
|
return
|
|
}
|
|
err = ctx.JSON(utils.FormatRes(200, "", token))
|
|
if err != nil {
|
|
return
|
|
}
|
|
})
|
|
party.Delete("/login", jwtSet.Jwt.Serve, logout)
|
|
party.Get("/reset", resetPwd)
|
|
party.Get("/auto", autoLogin)
|
|
}
|