Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.4 KiB

  1. package Api
  2. import (
  3. "log"
  4. "net/http"
  5. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
  6. "github.com/gorilla/mux"
  7. )
  8. func loggingMiddleware(next http.Handler) http.Handler {
  9. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  10. log.Printf(
  11. "%s %s %s, Content Length: %d",
  12. r.RemoteAddr,
  13. r.Method,
  14. r.RequestURI,
  15. r.ContentLength,
  16. )
  17. next.ServeHTTP(w, r)
  18. })
  19. }
  20. func authenticationMiddleware(next http.Handler) http.Handler {
  21. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  22. var (
  23. //userSession Auth.Session
  24. //err error
  25. )
  26. http.Error(w, "Forbidden", http.StatusUnauthorized)
  27. return
  28. /**
  29. userSession, err = Auth.CheckCookie(r)
  30. if err != nil {
  31. http.Error(w, "Forbidden", http.StatusUnauthorized)
  32. return
  33. }
  34. log.Printf(
  35. "Authenticated user: %s (%s)",
  36. userSession.Email,
  37. userSession.UserID,
  38. )
  39. next.ServeHTTP(w, r)
  40. */
  41. })
  42. }
  43. func InitApiEndpoints(router *mux.Router) {
  44. var (
  45. api *mux.Router
  46. adminApi *mux.Router
  47. )
  48. log.Println("Initializing API routes...")
  49. api = router.PathPrefix("/api/v1/").Subrouter()
  50. api.Use(loggingMiddleware)
  51. // Define routes for authentication
  52. api.HandleFunc("/signup", Auth.Signup).Methods("POST")
  53. // api.HandleFunc("/login", Auth.Login).Methods("POST")
  54. // api.HandleFunc("/logout", Auth.Logout).Methods("GET")
  55. adminApi = api.PathPrefix("/message/").Subrouter()
  56. adminApi.Use(authenticationMiddleware)
  57. }