portal/controller/account.go

36 lines
770 B
Go
Raw Normal View History

package controller
2023-04-29 17:38:21 +00:00
import (
"git.lumeweb.com/LumeWeb/portal/controller/request"
"git.lumeweb.com/LumeWeb/portal/service/account"
2023-04-29 17:38:21 +00:00
"github.com/kataras/iris/v12"
)
type AccountController struct {
Controller
2023-04-29 17:38:21 +00:00
}
func (a *AccountController) PostRegister() {
ri, success := tryParseRequest(request.RegisterRequest{}, a.Ctx)
if !success {
2023-04-29 17:38:21 +00:00
return
}
r, _ := ri.(*request.RegisterRequest)
err := account.Register(r.Email, r.Password, r.Pubkey)
if err != nil {
if err == account.ErrQueryingAcct || err == account.ErrFailedCreateAccount {
a.Ctx.StopWithError(iris.StatusInternalServerError, err)
} else {
a.Ctx.StopWithError(iris.StatusBadRequest, err)
}
2023-04-29 17:38:21 +00:00
return
}
// Return a success response to the client.
2023-04-30 07:29:24 +00:00
a.Ctx.StatusCode(iris.StatusCreated)
2023-04-29 17:38:21 +00:00
}