mirror of
https://github.com/adanrsantos/ThePlaceHolders.git
synced 2024-12-16 08:00:39 -06:00
Prototype for backend email confirmaion
This commit is contained in:
parent
8e6ff08eb4
commit
3462fc966c
21
server.go
21
server.go
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
@ -13,22 +12,11 @@ import (
|
||||||
const CANVAS_WIDTH = 1000
|
const CANVAS_WIDTH = 1000
|
||||||
const CANVAS_HEIGHT = 1000
|
const CANVAS_HEIGHT = 1000
|
||||||
|
|
||||||
type Canvas struct {
|
|
||||||
Data [CANVAS_WIDTH * CANVAS_HEIGHT]byte `json:"data"`
|
|
||||||
Width int `json:"width"`
|
|
||||||
Height int `json:"height"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
// Registered user information
|
// Registered user information
|
||||||
Users map[string]UserData
|
Users map[string]UserData
|
||||||
// Login sessions
|
// Login sessions
|
||||||
Sessions *sessions.CookieStore
|
Sessions *sessions.CookieStore
|
||||||
Canvas Canvas
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) canvas(w http.ResponseWriter, r *http.Request) {
|
|
||||||
json.NewEncoder(w).Encode(s.canvas)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -43,13 +31,6 @@ func main() {
|
||||||
server := Server{
|
server := Server{
|
||||||
Users: make(map[string]UserData),
|
Users: make(map[string]UserData),
|
||||||
Sessions: sessions.NewCookieStore(secret),
|
Sessions: sessions.NewCookieStore(secret),
|
||||||
Canvas: Canvas{},
|
|
||||||
}
|
|
||||||
|
|
||||||
for x := 0; x < CANVAS_WIDTH; x++ {
|
|
||||||
for y := 0; y < CANVAS_HEIGHT; y++ {
|
|
||||||
server.Canvas.Data[y*CANVAS_HEIGHT+x] = byte(CANVAS_WIDTH / x)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Host static files
|
// Host static files
|
||||||
|
@ -66,7 +47,7 @@ func main() {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
})
|
})
|
||||||
http.HandleFunc("/secret", server.secret)
|
http.HandleFunc("/secret", server.secret)
|
||||||
http.HandleFunc("/canvas", canvas)
|
http.HandleFunc("/confirm-email", server.handle_confirmation)
|
||||||
// Start web server at 127.0.0.1:8080
|
// Start web server at 127.0.0.1:8080
|
||||||
fmt.Printf("Listening to %s on port %s...\n", address, port)
|
fmt.Printf("Listening to %s on port %s...\n", address, port)
|
||||||
err := http.ListenAndServe(address+":"+port, nil)
|
err := http.ListenAndServe(address+":"+port, nil)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="h3bg" class="d-flex justify-content-center"><h3 id="r">Registration</h3></div>
|
<div id="h3bg" class="d-flex justify-content-center"><h3 id="r">Registration</h3></div>
|
||||||
<div id="formbg" class="d-flex p-2 justify-content-center align-items-center">
|
<div id="formbg" class="d-flex p-2 justify-content-center align-items-center">
|
||||||
<form id="rform" method="post" action="./confirmation.html">
|
<form id="rform" method="post">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="email" class="form-label">Email address</label>
|
<label for="email" class="form-label">Email address</label>
|
||||||
<input type="email" class="form-control" id="email" name="email" aria-describedby="emailHelp" pattern="^[^\s@]+@my\.utsa\.edu$" oninput="emailCheck()" required>
|
<input type="email" class="form-control" id="email" name="email" aria-describedby="emailHelp" pattern="^[^\s@]+@my\.utsa\.edu$" oninput="emailCheck()" required>
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
</small>
|
</small>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
<input id="submit" type="submit" class="btn btn-primary" value="Submit"></a>
|
<input id="submit" type="submit" class="btn btn-primary" value="Submit">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<script src="register.js"></script>
|
<script src="register.js"></script>
|
||||||
|
|
16
users.go
16
users.go
|
@ -13,6 +13,7 @@ import (
|
||||||
const SESSION_COOKIE_NAME = "utsa-place-session"
|
const SESSION_COOKIE_NAME = "utsa-place-session"
|
||||||
const SESSION_AUTH = "auth"
|
const SESSION_AUTH = "auth"
|
||||||
const SESSION_STARTED = "age"
|
const SESSION_STARTED = "age"
|
||||||
|
const SESSION_CONFIRMED = "confirmed"
|
||||||
|
|
||||||
const ENCRYPTION_STRENGTH = 14
|
const ENCRYPTION_STRENGTH = 14
|
||||||
|
|
||||||
|
@ -126,16 +127,29 @@ func (s *Server) handle_register(w http.ResponseWriter, r *http.Request) {
|
||||||
// Make session valid
|
// Make session valid
|
||||||
session.Values[SESSION_AUTH] = true
|
session.Values[SESSION_AUTH] = true
|
||||||
session.Values[SESSION_STARTED] = now.String()
|
session.Values[SESSION_STARTED] = now.String()
|
||||||
|
session.Values[SESSION_CONFIRMED] = false
|
||||||
// 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
|
||||||
fmt.Println("Registered user: ", email)
|
fmt.Println("Registered user: ", email)
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/confirm-email", http.StatusFound)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "Forbidden", http.StatusForbidden)
|
http.Error(w, "Forbidden", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) handle_confirmation(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := s.Sessions.Get(r, SESSION_COOKIE_NAME)
|
||||||
|
if err != nil {
|
||||||
|
s.handle_logout(w, r)
|
||||||
|
http.Redirect(w, r, "/register", http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
confirmed := session.Values[SESSION_CONFIRMED]
|
||||||
|
fmt.Println("Session confirmed: ", confirmed)
|
||||||
|
http.ServeFile(w, r, "./static/confirmation.html")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) secret(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) secret(w http.ResponseWriter, r *http.Request) {
|
||||||
session, _ := s.Sessions.Get(r, SESSION_COOKIE_NAME)
|
session, _ := s.Sessions.Get(r, SESSION_COOKIE_NAME)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue