action_first_user.go 974 B

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