RestApiv2/internal/restserver/userHendle.go

37 lines
855 B
Go
Raw Normal View History

package restserver
import (
"net/http"
2023-01-15 22:03:16 +03:00
2023-03-31 20:08:38 +03:00
"git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model"
)
func (r *RestServer) configureRouterUser() {
r.router.HandleFunc("/api/register", r.HandleFuncRegUser()).Methods("POST")
}
func (r *RestServer) HandleFuncRegUser() http.HandlerFunc {
return func(w http.ResponseWriter, res *http.Request) {
2023-01-15 22:03:16 +03:00
user := model.User{}
err := res.ParseForm()
if err != nil {
r.logger.Error(err)
}
2023-01-15 22:03:16 +03:00
user.Id = 1
user.Login = res.Form.Get("user")
user.Password = res.Form.Get("password")
user.Email = res.Form.Get("email")
user.PermisionLVL = 1
user.Token = "dasf2!23sfafaQWerq"
2023-01-15 22:03:16 +03:00
RetUser, err := r.db.User().Create(&user)
if err != nil {
r.logger.Errorln(err)
}
if RetUser != nil {
r.logger.Infoln("Create new user with id = ", RetUser.Id, " and with permissionLvl = ", RetUser.Id)
}
}
}