2023-01-07 14:19:53 +03:00
|
|
|
package restserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2023-01-15 22:03:16 +03:00
|
|
|
|
|
|
|
"git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model"
|
2023-01-07 14:19:53 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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{}
|
2023-01-07 14:19:53 +03:00
|
|
|
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-07 14:19:53 +03:00
|
|
|
|
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)
|
|
|
|
}
|
2023-01-07 14:19:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|