error.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 administrators can access the Dashboard. Please contact your administrator to elevate your account.</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 userFirstTimeSignUp = `<!DOCTYPE html><html>
  18. <body>
  19. <h3>Thank you for signing up. Please contact your administrator for access.</h3>
  20. </body>
  21. </html>
  22. `
  23. const userSignUpApprovalPending = `<!DOCTYPE html><html>
  24. <body>
  25. <h3>Your account is yet to be approved. Please contact your administrator for access.</h3>
  26. </body>
  27. </html>
  28. `
  29. const userNotFound = `<!DOCTYPE html><html>
  30. <body>
  31. <h3>User Not Found.</h3>
  32. </body>
  33. </html>`
  34. const somethingwentwrong = `<!DOCTYPE html><html>
  35. <body>
  36. <h3>Something went wrong. Contact Admin.</h3>
  37. </body>
  38. </html>`
  39. const notallowedtosignup = `<!DOCTYPE html><html>
  40. <body>
  41. <h3>Your email is not allowed. Please contact your administrator.</h3>
  42. </body>
  43. </html>`
  44. func handleOauthUserNotFound(response http.ResponseWriter) {
  45. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  46. response.WriteHeader(http.StatusNotFound)
  47. response.Write([]byte(userNotFound))
  48. }
  49. func handleOauthUserNotAllowed(response http.ResponseWriter) {
  50. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  51. response.WriteHeader(http.StatusForbidden)
  52. response.Write([]byte(userNotAllowed))
  53. }
  54. func handleFirstTimeOauthUserSignUp(response http.ResponseWriter) {
  55. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  56. response.WriteHeader(http.StatusForbidden)
  57. response.Write([]byte(userFirstTimeSignUp))
  58. }
  59. func handleOauthUserSignUpApprovalPending(response http.ResponseWriter) {
  60. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  61. response.WriteHeader(http.StatusForbidden)
  62. response.Write([]byte(userSignUpApprovalPending))
  63. }
  64. func handleOauthUserNotAllowedToSignUp(response http.ResponseWriter) {
  65. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  66. response.WriteHeader(http.StatusForbidden)
  67. response.Write([]byte(notallowedtosignup))
  68. }
  69. // handleOauthNotConfigured - returns an appropriate html page when oauth is not configured on netmaker server but an oauth login was attempted
  70. func handleOauthNotConfigured(response http.ResponseWriter) {
  71. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  72. response.WriteHeader(http.StatusInternalServerError)
  73. response.Write([]byte(oauthNotConfigured))
  74. }
  75. func handleSomethingWentWrong(response http.ResponseWriter) {
  76. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  77. response.WriteHeader(http.StatusInternalServerError)
  78. response.Write([]byte(somethingwentwrong))
  79. }