-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/APandamonium1/EduSync
- Loading branch information
Showing
17 changed files
with
731 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ on: | |
pull_request: | ||
branches: [main] | ||
|
||
env: | ||
DATABASE_URL: ${{secrets.DATABASE_URL}} | ||
# FIREBASE_ADMIN_PASSPHRASE: ${{secrets.FIREBASE_ADMIN_PASSPHRASE}} | ||
|
||
jobs: | ||
example: | ||
name: Create Ubuntu OS | ||
|
@@ -27,6 +31,20 @@ jobs: | |
go mod tidy | ||
go get github.com/franela/goblin | ||
ls | ||
# - name: Setup Firebase JSON file | ||
# run: echo "{${{ secrets.FIREBASE_JSON }}}" > edusync-7bd5e-firebase-adminsdk-x49uh-af084a6314.json | ||
|
||
# - name: Build and run JSON validator | ||
# run: | | ||
# go run json_validator.go edusync-7bd5e-firebase-adminsdk-x49uh-af084a6314.json | ||
|
||
- name: Decrypt Firebase JSON | ||
run: | | ||
chmod +x decrypt_secret.sh | ||
./decrypt_secret.sh | ||
env: | ||
FIREBASE_ADMIN_PASSPHRASE: ${{secrets.FIREBASE_ADMIN_PASSPHRASE}} | ||
|
||
- name: Go Test | ||
run: | | ||
|
@@ -36,30 +54,30 @@ jobs: | |
name: Success Message (Discord) | ||
uses: discord-actions/message@v2 | ||
with: | ||
webhookUrl: https://discord.com/api/webhooks/1237964301201965127/ZYe3gYTeweYEfA_Q0I-JWFVXA2dVMp7Pw7jeNNd2UlFCtvIS8ZvIN_CRQ-gUwSgl7eD2 | ||
webhookUrl: ${{secrets.DISCORD_WEBHOOK}} | ||
message: SUCCESSFULLLL in branch ${{github.ref}} by ${{github.actor}} | ||
|
||
- if: ${{success()}} | ||
name: Success Message (Telegram) | ||
uses: akeylimepie/[email protected] | ||
with: | ||
token: 6795256205:AAHm19-9zOM4jMtEtVOSDGExXAtg5J67rKc | ||
chat_id: -4244340354 | ||
token: ${{secrets.TELEGRAM_TOKEN}} | ||
chat_id: ${{secrets.TELEGRAM_CHAT_ID}} | ||
text: SUCCESSFULLLL in branch ${{github.ref}} by ${{github.actor}} | ||
|
||
- if: ${{failure()}} | ||
name: Failure Message (Discord) | ||
uses: discord-actions/message@v2 | ||
with: | ||
webhookUrl: https://discord.com/api/webhooks/1237964301201965127/ZYe3gYTeweYEfA_Q0I-JWFVXA2dVMp7Pw7jeNNd2UlFCtvIS8ZvIN_CRQ-gUwSgl7eD2 | ||
webhookUrl: ${{secrets.DISCORD_WEBHOOK}} | ||
message: FAILUREEEE in branch ${{github.ref}} by ${{github.actor}} | ||
|
||
- if: ${{failure()}} | ||
name: Failure Message (Telegram) | ||
uses: akeylimepie/[email protected] | ||
with: | ||
token: 6795256205:AAHm19-9zOM4jMtEtVOSDGExXAtg5J67rKc | ||
chat_id: -4244340354 | ||
token: ${{secrets.TELEGRAM_TOKEN}} | ||
chat_id: ${{secrets.TELEGRAM_CHAT_ID}} | ||
text: FAILUREEEE in branch ${{github.ref}} by ${{github.actor}} | ||
|
||
#- name: Setup Python | ||
|
@@ -73,4 +91,4 @@ jobs: | |
#python --version | ||
#ls | ||
#pip3 install pandas | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
"net/http" | ||
|
||
"github.com/gorilla/pat" | ||
"github.com/gorilla/sessions" | ||
"github.com/markbates/goth" | ||
"github.com/markbates/goth/gothic" | ||
"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 | ||
} | ||
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) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// Config struct to hold the configuration | ||
type Config struct { | ||
GoogleClientID string `json:"google_client_id"` | ||
GoogleClientSecret string `json:"google_client_secret"` | ||
SessionSecret string `json:"session_secret"` | ||
} | ||
|
||
// LoadConfig reads the configuration from a file | ||
func LoadConfig(file string) (*Config, error) { | ||
var config Config | ||
configFile, err := os.Open(file) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot open config file: %w", err) | ||
} | ||
defer configFile.Close() | ||
|
||
decoder := json.NewDecoder(configFile) | ||
err = decoder.Decode(&config) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot decode config JSON: %w", err) | ||
} | ||
|
||
return &config, nil | ||
} |
Oops, something went wrong.