This commit is contained in:
yaya 2024-11-06 17:05:02 -06:00
commit b47ee31429
20 changed files with 549 additions and 27 deletions

View file

@ -7,6 +7,9 @@ within a restricted amount of time to make art.
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/)
You can choose a different IP address or port using the flags:
`go run . -ip=192.168.0.1 -port=3000`
## Go project structure
* [go.mod](go.mod) Go version and library dependencies
* [go.sum](go.sum) Checksums for libraries

BIN
cat.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

42
email.go Normal file
View file

@ -0,0 +1,42 @@
package main
import (
"crypto/tls"
"fmt"
"gopkg.in/gomail.v2"
"net/smtp"
)
func Send(body string) {
from := "xterminate18181@gmail.com"
pass := "nvzp fodm ihzw gter"
to := "joson.anthoney@frontdomain.org"
msg := "From: " + from + "\n" +
"To: " + to + "\n" +
"Subject: Hello there\n\n" +
body
err := smtp.SendMail("smtp.gmail.com:587",
smtp.PlainAuth("", from, pass, "smtp.gmail.com"),
from, []string{to}, []byte(msg))
if err != nil {
fmt.Printf("smtp error: %s", err)
return
}
fmt.Println("Successfully sended to " + to)
}
func MailTest() {
d := gomail.NewDialer("smtp.gmail.com", 587, "xterminate18181@gmail.com", "nvzp fodm ihzw gter")
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
m := gomail.NewMessage()
m.SetHeader("From", "xterminate18181@gmail.com")
m.SetHeader("To", "logan@gatlintc.com")
m.SetHeader("Subject", "Confirm Email")
m.SetBody("text/html", "Test body")
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}

6
go.mod
View file

@ -7,4 +7,8 @@ require (
golang.org/x/crypto v0.27.0
)
require github.com/gorilla/securecookie v1.1.2 // indirect
require (
github.com/gorilla/securecookie v1.1.2 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
)

4
go.sum
View file

@ -6,3 +6,7 @@ github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzq
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=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=

View file

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"log"
"net/http"
@ -8,8 +9,8 @@ import (
"github.com/gorilla/sessions"
)
const ADDRESS = "127.0.0.1"
const PORT = "8080"
const CANVAS_WIDTH = 1000
const CANVAS_HEIGHT = 1000
type Server struct {
// Registered user information
@ -19,12 +20,19 @@ type Server struct {
}
func main() {
// Grab command line arguments
ipFlag := flag.String("ip", "127.0.0.1", "IP address to receive traffic from")
portFlag := flag.String("port", "8080", "Port to receive traffic from")
flag.Parse()
address := *ipFlag
port := *portFlag
// Create server object
secret := []byte("super-secret-key")
server := Server{
Users: make(map[string]UserData),
Sessions: sessions.NewCookieStore(secret),
}
// Host static files
static_files := http.FileServer(http.Dir("static/"))
http.Handle("/", static_files)
@ -39,9 +47,10 @@ func main() {
http.Redirect(w, r, "/", http.StatusFound)
})
http.HandleFunc("/secret", server.secret)
http.HandleFunc("/confirm-email", server.handle_confirmation)
// Start web server at 127.0.0.1:8080
fmt.Printf("Listening to %s on port %s...\n", ADDRESS, PORT)
err := http.ListenAndServe(ADDRESS+":"+PORT, nil)
fmt.Printf("Listening to %s on port %s...\n", address, port)
err := http.ListenAndServe(address+":"+port, nil)
// Print any errors
if err != nil {
fmt.Println("Error starting server:")

70
static/canvas.css Normal file
View file

@ -0,0 +1,70 @@
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.navbarCont {
background-color: grey;
width: 100%;
text-align: center;
margin-bottom: 10px;
}
.canvasCont {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: yellow;
border: solid black;
border-radius: 20px;
}
.toolbar {
display: flex;
justify-content: space-around;
align-items: center;
border-top: solid black 1px;
width: 100%;
height: 60px;
z-index: 10;
}
.toolbarItems {
display: flex;
flex-direction: column;
justify-content: center;
font-weight: 900;
color: blue;
text-align: center;
height: 100%;
width: 100px;
}
.strokePicker {
padding: 0;
margin: 0;
width: 100%;
}
.strokePicker:hover {
cursor: pointer;
}
canvas {
background-color: lightblue;
margin: 20px;
image-rendering: pixelated;
}

View file

@ -7,8 +7,32 @@
<title>UTSA Placeholders</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<link rel="stylesheet" href="./canvas.css">
</head>
<canvas id="canvas" width="1250" height="550" style="border:1px solid #000000;" alt="canvaf"></canvas>
<body>
<div class="wrapper">
<div class="navbarCont">
<h1>ThePlaceHolders</h1>
</div>
<!--note to self: below IS the canvas-->
<div class="canvasCont">
<canvas id="canvas" width="500" height="500" style="border:1px solid #000000;" alt="canvas"></canvas>
<div id="toolbar" class="toolbar">
<div class="toolbarItems">
<button id="zoomOut">-</button>
</div>
<div class="toolbarItems">
<label for="stroke">Strokes</label>
<input id="stroke" name="stroke" type="color" class="strokePicker">
</div>
<div class="toolbarItems">
<button onclick="zoomIn"id="zoomIn">+</button>
</div>
</div>
</div>
<!--note to self: above IS the canvas-->
</div>
<script src="./canvas.js"></script>
</body>
</html>

107
static/canvas.js Normal file
View file

@ -0,0 +1,107 @@
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const CANVAS_SIZE = 500;
const DATA_SIZE = 200;
let scale = 1;
let offx = 0;
let offy = 0;
let clickx = 0;
let clicky = 0;
let mouseClicked = false;
// Array of [red, blue, green, transparency] * width * height
let image = new ImageData(DATA_SIZE, DATA_SIZE);
// Drawable image
let bitmap = null;
window.addEventListener("load", async (e) => {
// Create drawable image, update it every half second
await redraw();
setInterval(redraw, 500);
setInterval(draw, 500);
});
async function redraw() {
bitmap = await createImageBitmap(image);
}
// Color is an array of four numbers 0-255 (RGB + transparency)
function setPixel(data, x, y, color) {
let start = (y * DATA_SIZE + x) * 4;
for (let i = 0; i < 4; i++) {
data[start + i] = color[i];
}
}
function draw() {
ctx.fillStyle = "rgb(0 0 0 255)";
ctx.clearRect(0, 0, canvas.width, canvas.height);
let drawScale = CANVAS_SIZE / DATA_SIZE * scale;
ctx.imageSmoothingEnabled = false;
ctx.scale(drawScale, drawScale);
ctx.drawImage(bitmap, offx, offy);
ctx.setTransform(1, 0, 0, 1, 0, 0);
}
canvas.addEventListener("wheel", async (e) => {
let oldScale = scale;
if (e.deltaY < 0) {
scale += 0.1;
} else if (e.deltaY > 0) {
scale -= 0.1;
}
/*
offX += (DATA_SIZE * scale - DATA_SIZE * oldScale) / 2;
offY += (DATA_SIZE * scale - DATA_SIZE * oldScale) / 2;
*/
draw(image);
});
canvas.addEventListener("contextmenu", (e) => {
e.preventDefault();
})
canvas.addEventListener("mousedown", async (e) => {
// Left click
if (e.button == 0) {
mouseClicked = true;
setTimeout(() => {
mouseClicked = false;
}, 200);
}
});
canvas.addEventListener("mouseup", async (e) => {
if (e.button == 0 && mouseClicked) {
mouseClicked = false;
clickx = e.clientX;
clicky = e.clientY;
let x = e.clientX - canvas.getBoundingClientRect().left;
let y = e.clientY - canvas.getBoundingClientRect().top;
let cx = Math.round(x / (CANVAS_SIZE * scale) * DATA_SIZE - offx);
let cy = Math.round(y / (CANVAS_SIZE * scale) * DATA_SIZE - offy);
console.log(cx, cy);
if (cx < 0 || cx > CANVAS_SIZE || cy < 0 || cy > CANVAS_SIZE) {
return;
}
setPixel(image.data, cx, cy, [255, 0, 0, 255]);
await redraw();
draw();
}
});
canvas.addEventListener("mousemove", async (e) => {
// `buttons` is a bitflag for some dumb reason
if (e.buttons & 1) {
offx += e.movementX * (1.0 / scale) * 0.45;
offy += e.movementY * (1.0 / scale) * 0.45;
draw(image);
}
});

15
static/confirmation.css Normal file
View file

@ -0,0 +1,15 @@
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
html {
background-color: black;
}
/*
lol
*/

33
static/confirmation.html Normal file
View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en" class="bg-warning">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>UTSA Placeholders</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<link href="./confirmation.css" type="text/css "rel="stylesheet">
</head>
<body>
<form class="mt-5 bg-warning">
<div class="m-3 fs-4 d-block bg-transparent text-center">
Check your email for a 6-digit code and enter it below.
</div>
<div class="input-group input-group-lg d-flex justify-content-center">
<input class="input-group-text font-monospace" for="" required>
</div>
<div class="m-3 d-block text-center">
<!--button probably needs to check if the code is correct and then send user to canvas.html-->
<input id="submit" type="submit" value="Confirm" class="btn btn-secondary" action="">
</div>
<div class="mt-5 fs-6 text-center">
<!--add link below to href or something to send another email to the registered user-->
<a href="">Send again.</a>
</div>
</form>
</body>
</html>

47
static/forgotpassword.css Normal file
View file

@ -0,0 +1,47 @@
:root {
--utsa-orange: #f15a22;
--utsa-blue: #0c2340;
}
html {
background-color: var(--utsa-orange);
}
#rform {
border-radius: 10px;
border: solid var(--utsa-orange) 2px;
margin: 100px;
padding: 30px;
background-color: white;
}
#formbg {
background-color: var(--utsa-orange);
}
#h3bg {
background-color: var(--utsa-blue);
}
h3 {
border-radius: 10px;
padding: 20px;
margin: 10px;
background-color: var(--utsa-blue);
color: var(--utsa-orange);
font-size: 40px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.form-label {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.form-control {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.form-text {
padding: 3px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}

View file

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>UTSA Placeholders</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<link href="./forgotpassword.css" rel="stylesheet">
</head>
<body>
<div id="h3bg" class="d-flex justify-content-center"><h3 id="r">UTSA Place</h3></div>
<div id="formbg" class="d-flex p-2 justify-content-center align-items-center">
<form id="rform" method="post">
<div class="d-flex justify-content-center fs-3">
Forgot Password
</div>
<br><br>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" aria-describedby="emailHelp" required>
<div id="emailHelp" class="form-text">Enter your email and we will send you a 6-digit recovery code.</div>
</div>
<input id="submit" type="submit" class="btn btn-primary" value="Send Code">
<br>
<div class="d-flex mt-2">
<small>
Click <a href="login.html">here</a> to go back to login.
</small>
</div>
</form>
</div>
</body>
</html>

View file

@ -14,22 +14,27 @@
</h1>
<ul>
<li>
<a href="/register.html"> Register </a>
<a href="./register.html"> Register </a>
</li>
<li>
<a href="/login.html"> Login </a>
<a href="./login.html"> Login </a>
</li>
<li>
<a href="/logout"> Log Out </a>
<a href="./forgotpassword.html"> Forgot Password </a>
</li>
<li>
<a href="/secret"> Secret </a>
<a href="./confirmation.html"> Confirmation </a>
</li>
<li>
<a href="/canvas.html">Canvas </a>
<a href="./logout"> Log Out </a>
</li>
<li>
<a href="/secret"> Secret </a>
<a href="./secret"> Secret </a>
</li>
<li>
<a href="./canvas.html">Canvas </a>
</li>
<a href="./secret"> Secret </a>
</li>
<li>
<a href="/contact.html"> Contact </a>

51
static/login.css Normal file
View file

@ -0,0 +1,51 @@
:root {
--utsa-orange: #f15a22;
--utsa-blue: #0c2340;
}
html {
background-color: var(--utsa-orange);
}
#lform {
border-radius: 10px;
border: solid var(--utsa-orange) 2px;
margin: 100px;
padding: 30px;
background-color: white;
}
#formbg {
background-color: var(--utsa-orange);
}
#h3bg {
background-color: var(--utsa-blue);
}
h3 {
border-radius: 10px;
padding: 20px;
margin: 10px;
background-color: var(--utsa-blue);
color: var(--utsa-orange);
font-size: 40px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.form-label {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.form-control {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.form-text {
padding: 3px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.loginlinks {
font-size: 12px;
}

View file

@ -10,10 +10,9 @@
<link href="./login.css" rel="stylesheet">
</head>
<body>
<br>
<div class="d-flex justify-content-center"><h3>Login</h3></div>
<div class="d-flex p-2 justify-content-center align-items-center">
<form method = "post">
<div id="h3bg" class="d-flex justify-content-center"><h3>Login</h3></div>
<div id="formbg" class="d-flex p-2 justify-content-center align-items-center">
<form id="lform" method = "post">
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Email address</label>
<input type="email" name="email" class="form-control" id="email" aria-describedby="emailHelp">
@ -23,14 +22,17 @@
<label for="exampleInputPassword1" class="form-label">Password</label>
<input type="password" name="password" class="form-control" id="password">
</div>
<div class="loginlinks" class="fs-6">
<a href="./forgotpassword.html">Forgot Password?</a>
</div>
<div class="loginlinks" class="fs-6">
Don't have an account? Register <a href="./register.html">here</a>.
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1" onclick="showPass()">
<label class="form-check-label" for="exampleCheck1">Show Password</label>
</div>
<input type="submit" class="btn btn-primary" value="Submit">
<div class="fs-6">
Don't have an account? Register <a href="register.html">here</a>.
</div>
</form>
</div>
<script src="register.js"></script>

47
static/register.css Normal file
View file

@ -0,0 +1,47 @@
:root {
--utsa-orange: #f15a22;
--utsa-blue: #0c2340;
}
html {
background-color: var(--utsa-orange);
}
#rform {
border-radius: 10px;
border: solid var(--utsa-orange) 2px;
margin: 100px;
padding: 30px;
background-color: white;
}
#formbg {
background-color: var(--utsa-orange);
}
#h3bg {
background-color: var(--utsa-blue);
}
h3 {
border-radius: 10px;
padding: 20px;
margin: 10px;
background-color: var(--utsa-blue);
color: var(--utsa-orange);
font-size: 40px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.form-label {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.form-control {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.form-text {
padding: 3px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}

View file

@ -7,13 +7,12 @@
<title>UTSA Placeholders</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<link href="./register.css" rel="stylesheet">
</head>
<body>
<!-- <div class="d-flex justify-content-xxl-center" style="background-color: #0C2340; color:#f15a22; font-weight: 900; font: x-large;"><h1>UTSA PLACE</h1></div> -->
<br>
<div class="d-flex justify-content-center"><h3>Registration</h3></div>
<div class="d-flex p-2 justify-content-center align-items-center">
<form method="post">
<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">
<form id="rform" method="post">
<div class="mb-3">
<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>

View file

View file

@ -13,6 +13,8 @@ import (
const SESSION_COOKIE_NAME = "utsa-place-session"
const SESSION_AUTH = "auth"
const SESSION_STARTED = "age"
const SESSION_CONFIRMED = "confirmed"
const SESSION_CONFIRM_KEY = "confirm-key"
const ENCRYPTION_STRENGTH = 14
@ -126,16 +128,39 @@ func (s *Server) handle_register(w http.ResponseWriter, r *http.Request) {
// Make session valid
session.Values[SESSION_AUTH] = true
session.Values[SESSION_STARTED] = now.String()
session.Values[SESSION_CONFIRMED] = false
session.Values[SESSION_CONFIRM_KEY] = "asdf"
// Send session token to browser
session.Save(r, w)
// Redirect to index.html
fmt.Println("Registered user: ", email)
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/confirm-email", http.StatusFound)
default:
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
}
switch r.Method {
case http.MethodGet:
confirmed := session.Values[SESSION_CONFIRMED].(bool)
fmt.Println("User email confirmed: ", confirmed)
if confirmed {
http.Redirect(w, r, "/", http.StatusFound)
} else {
http.ServeFile(w, r, "./static/confirmation.html")
}
case http.MethodPost:
default:
}
}
func (s *Server) secret(w http.ResponseWriter, r *http.Request) {
session, _ := s.Sessions.Get(r, SESSION_COOKIE_NAME)