error.go 3.4 KB

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