mirror of
https://github.com/adanrsantos/ThePlaceHolders.git
synced 2024-12-16 12:20:37 -06:00
Removed unused dependencies
This commit is contained in:
parent
c0b826afa8
commit
73ce55047f
|
@ -7,6 +7,10 @@ within a restricted amount of time to make art.
|
||||||
2. Run the command `go run .` inside this folder
|
2. Run the command `go run .` inside this folder
|
||||||
3. View the website at [127.0.0.1:8080](http://127.0.0.1:8080/)
|
3. View the website at [127.0.0.1:8080](http://127.0.0.1:8080/)
|
||||||
|
|
||||||
|
## Go project structure
|
||||||
|
* [go.mod](go.mod) Go version and library dependencies
|
||||||
|
* [go.sum](go.sum) Checksums for libraries
|
||||||
|
|
||||||
## Backend Source
|
## Backend Source
|
||||||
Our back-end is written in [Go](https://go.dev/) using the standard library.
|
Our back-end is written in [Go](https://go.dev/) using the standard library.
|
||||||
* [Request handling](server.go)
|
* [Request handling](server.go)
|
||||||
|
|
1
db.json
1
db.json
|
@ -1 +0,0 @@
|
||||||
{"xterminate18181@gmail.com":{"email":"xterminate18181@gmail.com","password":"123","account-created":"2024-09-27T05:39:11.331520582-05:00","last-login":"2024-09-27T05:39:11.331520621-05:00"}}
|
|
8
go.mod
8
go.mod
|
@ -2,9 +2,9 @@ module github.com/adanrsantos/ThePlaceHolders
|
||||||
|
|
||||||
go 1.23
|
go 1.23
|
||||||
|
|
||||||
require github.com/gorilla/sessions v1.4.0
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gorilla/mux v1.8.1 // indirect
|
github.com/gorilla/sessions v1.4.0
|
||||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
golang.org/x/crypto v0.27.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require github.com/gorilla/securecookie v1.1.2 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1,8 +1,8 @@
|
||||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
|
||||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
|
||||||
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
||||||
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
||||||
github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ=
|
github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ=
|
||||||
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
|
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
|
||||||
|
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
||||||
|
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
)
|
)
|
||||||
|
|
53
users.go
53
users.go
|
@ -1,21 +1,36 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SESSION_COOKIE_NAME = "utsa-place-session"
|
const SESSION_COOKIE_NAME = "utsa-place-session"
|
||||||
const SESSION_AUTH = "auth"
|
const SESSION_AUTH = "auth"
|
||||||
|
|
||||||
|
const ENCRYPTION_STRENGTH = 14
|
||||||
|
|
||||||
type UserData struct {
|
type UserData struct {
|
||||||
Email string `json:"email"`
|
Email string
|
||||||
Password string `json:"password"`
|
Password string
|
||||||
AccountCreated time.Time `json:"account-created"`
|
AccountCreated time.Time
|
||||||
LastLogin time.Time `json:"last-login"`
|
LastLogin time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func validate_email(email string) (string, bool) {
|
||||||
|
email = strings.ToLower(email)
|
||||||
|
regex := regexp.MustCompile("^[a-z]+.[a-z]+@(my.)?utsa.edu")
|
||||||
|
ok := regex.MatchString(email)
|
||||||
|
return email, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func hash_password(password string) string {
|
||||||
|
bytes, _ := bcrypt.GenerateFromPassword([]byte(password), ENCRYPTION_STRENGTH)
|
||||||
|
return string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles requests to /login.html
|
// Handles requests to /login.html
|
||||||
|
@ -65,13 +80,19 @@ func (s *Server) handle_register(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "./static/register.html")
|
http.ServeFile(w, r, "./static/register.html")
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
// Get data from form
|
// Get data from form
|
||||||
email := r.FormValue("email")
|
email, ok := validate_email(r.FormValue("email"))
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, "Invalid email address", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
password := r.FormValue("password")
|
password := r.FormValue("password")
|
||||||
fmt.Println(r.Form)
|
if len(password) < 5 || len(password) >= 70 {
|
||||||
|
http.Error(w, "Invalid password length", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
// Check that this email is not already registered
|
// Check that this email is not already registered
|
||||||
if _, ok := s.Users[email]; ok {
|
if _, ok := s.Users[email]; ok {
|
||||||
fmt.Println("Already registered")
|
http.Error(w, "Already registered", http.StatusForbidden)
|
||||||
http.Error(w, "Forbidden", http.StatusForbidden)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Generate session
|
// Generate session
|
||||||
|
@ -94,7 +115,6 @@ func (s *Server) handle_register(w http.ResponseWriter, r *http.Request) {
|
||||||
// Send session token to browser
|
// Send session token to browser
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
// Redirect to index.html
|
// Redirect to index.html
|
||||||
s.save_state()
|
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "Forbidden", http.StatusForbidden)
|
http.Error(w, "Forbidden", http.StatusForbidden)
|
||||||
|
@ -114,12 +134,3 @@ func (s *Server) handle_logout(w http.ResponseWriter, r *http.Request) {
|
||||||
MaxAge: -1,
|
MaxAge: -1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) save_state() {
|
|
||||||
file, err := os.Create("db.json")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
json.NewEncoder(file).Encode(s.Users)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue