2
0

error.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. <h3>Furthermore, Admin has to approve your identity to have access to netmaker networks</h3>
  14. <p>Once your identity is approved, Non-Admins can access the netmaker networks using <a href="https://docs.netmaker.io/pro/rac.html" target="_blank" rel="noopener">RemoteAccessClient.</a></p>
  15. </body>
  16. </html>
  17. `
  18. const userNotFound = `<!DOCTYPE html><html>
  19. <body>
  20. <h3>User Not Found.</h3>
  21. </body>
  22. </html>`
  23. const somethingwentwrong = `<!DOCTYPE html><html>
  24. <body>
  25. <h3>Something went wrong. Contact Admin</h3>
  26. </body>
  27. </html>`
  28. const notallowedtosignup = `<!DOCTYPE html><html>
  29. <body>
  30. <h3>You are not allowed to SignUp.</h3>
  31. </body>
  32. </html>`
  33. func handleOauthUserNotFound(response http.ResponseWriter) {
  34. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  35. response.WriteHeader(http.StatusNotFound)
  36. response.Write([]byte(userNotFound))
  37. }
  38. func handleOauthUserNotAllowed(response http.ResponseWriter) {
  39. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  40. response.WriteHeader(http.StatusForbidden)
  41. response.Write([]byte(userNotAllowed))
  42. }
  43. func handleOauthUserNotAllowedToSignUp(response http.ResponseWriter) {
  44. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  45. response.WriteHeader(http.StatusForbidden)
  46. response.Write([]byte(notallowedtosignup))
  47. }
  48. // handleOauthNotConfigured - returns an appropriate html page when oauth is not configured on netmaker server but an oauth login was attempted
  49. func handleOauthNotConfigured(response http.ResponseWriter) {
  50. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  51. response.WriteHeader(http.StatusInternalServerError)
  52. response.Write([]byte(oauthNotConfigured))
  53. }
  54. func handleSomethingWentWrong(response http.ResponseWriter) {
  55. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  56. response.WriteHeader(http.StatusInternalServerError)
  57. response.Write([]byte(somethingwentwrong))
  58. }