Skip to content

Commit

Permalink
Database Part 2 (#28)
Browse files Browse the repository at this point in the history
* changed userId from uuid to googleId

* Added role parameter to database

* fixed database testing, updated to google id

* removed original server code, placed in auth.go

* standardising

* Added admin model

* reorganised database.go, added CRUD operations for admin

* commented unneeded code

* Trying to fix conflict issues

* Delete config.json

* forgot to change firebase json
  • Loading branch information
APandamonium1 authored Jun 26, 2024
1 parent c78a5e9 commit 106a702
Show file tree
Hide file tree
Showing 6 changed files with 1,105 additions and 311 deletions.
52 changes: 52 additions & 0 deletions authHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,58 @@ import (
"github.com/markbates/goth/providers/google"
)

// AuthHandler sets up the authentication routes on the provided router
// func AuthHandler(router *pat.Router, config *Config) {
// maxAge := 86400 * 30 // 30 days
// isProd := true // Set to true when serving over https

// store := sessions.NewCookieStore([]byte(config.SessionSecret))
// store.MaxAge(maxAge)
// store.Options.Path = "/"
// store.Options.HttpOnly = true // HttpOnly should always be enabled
// store.Options.Secure = isProd

// gothic.Store = store

// goth.UseProviders(
// google.New(config.GoogleClientID, config.GoogleClientSecret, "https://localhost:8080/auth/google/callback", "email", "profile"),
// )

// router.Get("/auth/{provider}/callback", func(res http.ResponseWriter, req *http.Request) {
// user, err := gothic.CompleteUserAuth(res, req)
// if err != nil {
// fmt.Fprintln(res, err)
// return
// }

// // // Extract user details from the goth.User
// // googleID := user.UserID
// // name := user.Name
// // email := user.Email

// // // Example: Create or update a student with the extracted details
// // student := NewStudent(googleID, name, 18, 10.0, email, "91234567", "TE", "Mr. Smith", "Mrs. Doe", "Student")
// // err = createStudent(student.GoogleID, student)
// // if err != nil {
// // log.Println("Error creating student:", err)
// // } else {
// // log.Println("Student created/updated successfully!")
// // }

// t, _ := template.ParseFiles("templates/success.html")
// t.Execute(res, user)
// })

// router.Get("/auth/{provider}", func(res http.ResponseWriter, req *http.Request) {
// gothic.BeginAuthHandler(res, req)
// })

// router.Get("/", func(res http.ResponseWriter, req *http.Request) {
// t, _ := template.ParseFiles("templates/index.html")
// t.Execute(res, false)
// })
// }

func AuthHandler(router *mux.Router, config *Config) {
maxAge := 86400 * 30 // 30 days
isProd := true // Set to true when serving over https
Expand Down
5 changes: 0 additions & 5 deletions config.json

This file was deleted.

Loading

0 comments on commit 106a702

Please sign in to comment.