2023-05-10 11:07:56 +00:00
|
|
|
package controller
|
2023-04-29 17:38:21 +00:00
|
|
|
|
|
|
|
import (
|
2023-06-07 17:04:38 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/controller/request"
|
2023-06-09 08:03:29 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/service/account"
|
2023-04-29 17:38:21 +00:00
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
)
|
|
|
|
|
2023-05-10 11:07:56 +00:00
|
|
|
type AccountController struct {
|
2023-06-09 08:03:29 +00:00
|
|
|
Controller
|
2023-04-29 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 11:07:56 +00:00
|
|
|
func (a *AccountController) PostRegister() {
|
2023-06-07 17:04:38 +00:00
|
|
|
ri, success := tryParseRequest(request.RegisterRequest{}, a.Ctx)
|
|
|
|
if !success {
|
2023-04-29 17:38:21 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-06-07 17:04:38 +00:00
|
|
|
r, _ := ri.(*request.RegisterRequest)
|
|
|
|
|
2023-06-09 08:03:29 +00:00
|
|
|
err := account.Register(r.Email, r.Password, r.Pubkey)
|
2023-04-30 08:48:56 +00:00
|
|
|
|
2023-06-09 08:03:29 +00:00
|
|
|
if err != nil {
|
|
|
|
if err == account.ErrQueryingAcct || err == account.ErrFailedCreateAccount {
|
2023-04-30 08:48:56 +00:00
|
|
|
a.Ctx.StopWithError(iris.StatusInternalServerError, err)
|
2023-06-09 08:03:29 +00:00
|
|
|
} else {
|
|
|
|
a.Ctx.StopWithError(iris.StatusBadRequest, err)
|
2023-04-30 08:48:56 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|