error.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package auth
  2. import "net/http"
  3. // == define error HTML here ==
  4. const oauthNotConfigured = `<!DOCTYPE html><html>
  5. <body>
  6. <h3>Your Netmaker server does not have OAuth configured.</h3>
  7. <p>Please visit the docs <a href="https://docs.netmaker.org/oauth.html" target="_blank" rel="noopener">here</a> to learn how to.</p>
  8. </body>
  9. </html>`
  10. const userNotAllowed = `<!DOCTYPE html><html>
  11. <body>
  12. <h3>Only Admins are allowed to access Dashboard.</h3>
  13. <p>Non-Admins can access the netmaker networks using <a href="https://docs.netmaker.io/pro/rac.html" target="_blank" rel="noopener">RemoteAccessClient.</a></p>
  14. </body>
  15. </html>
  16. `
  17. const userNotFound = `<!DOCTYPE html><html>
  18. <body>
  19. <h3>User Not Found.</h3>
  20. </body>
  21. </html>`
  22. func handleOauthUserNotFound(response http.ResponseWriter) {
  23. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  24. response.WriteHeader(http.StatusNotFound)
  25. response.Write([]byte(userNotFound))
  26. }
  27. func handleOauthUserNotAllowed(response http.ResponseWriter) {
  28. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  29. response.WriteHeader(http.StatusForbidden)
  30. response.Write([]byte(userNotAllowed))
  31. }
  32. // handleOauthNotConfigured - returns an appropriate html page when oauth is not configured on netmaker server but an oauth login was attempted
  33. func handleOauthNotConfigured(response http.ResponseWriter) {
  34. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  35. response.WriteHeader(http.StatusInternalServerError)
  36. response.Write([]byte(oauthNotConfigured))
  37. }