action_first_user.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package actions
  2. import (
  3. utils "golang-fave/engine/wrapper/utils"
  4. )
  5. func (this *Action) Action_first_user() {
  6. if err := this.use_database(); err != nil {
  7. this.msg_error(err.Error())
  8. return
  9. } else {
  10. defer this.db.Close()
  11. }
  12. pf_first_name := this.wrapper.R.FormValue("first_name")
  13. pf_last_name := this.wrapper.R.FormValue("last_name")
  14. pf_email := this.wrapper.R.FormValue("email")
  15. pf_password := this.wrapper.R.FormValue("password")
  16. if pf_email == "" {
  17. this.msg_error(`Please specify user email`)
  18. return
  19. }
  20. if !utils.EmailIsValid(pf_email) {
  21. this.msg_error(`Please specify correct user email`)
  22. return
  23. }
  24. if pf_password == "" {
  25. this.msg_error(`Please specify user password`)
  26. return
  27. }
  28. _, err := this.db.Query(
  29. "INSERT INTO `users` SET `first_name` = ?, `last_name` = ?, `email` = ?, `password` = MD5(?);",
  30. pf_first_name, pf_last_name, pf_email, pf_password)
  31. if err != nil {
  32. this.msg_error(err.Error())
  33. return
  34. }
  35. // Reload current page
  36. this.write(`window.location.reload(false);`)
  37. }