mirror of
https://github.com/adanrsantos/ThePlaceHolders.git
synced 2024-12-16 14:20:39 -06:00
Compare commits
No commits in common. "34544c8bdff0134e29fc9d1c9cf9accdf21fec6b" and "b47ee31429600b18ed9faf70ee6bfac47f8a84db" have entirely different histories.
34544c8bdf
...
b47ee31429
|
@ -1,8 +1,3 @@
|
||||||
:root {
|
|
||||||
--utsa-orange: #f15a22;
|
|
||||||
--utsa-blue: #0c2340;
|
|
||||||
}
|
|
||||||
|
|
||||||
* {
|
* {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
@ -17,49 +12,15 @@ html, body {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: var(--utsa-orange);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbarCont {
|
.navbarCont {
|
||||||
position: relative;
|
background-color: grey;
|
||||||
background-color: var(--utsa-blue);
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbarCont a {
|
|
||||||
float: left;
|
|
||||||
text-align: center;
|
|
||||||
padding: 12px;
|
|
||||||
text-decoration: none;
|
|
||||||
color: #e67e22;
|
|
||||||
}
|
|
||||||
|
|
||||||
.navbarCont a.icon {
|
|
||||||
padding: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.navbarCont a.title {
|
|
||||||
font-size: 26.5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.navbarCont a.rightB {
|
|
||||||
float: right;
|
|
||||||
display: inline-block;
|
|
||||||
padding: 20px;
|
|
||||||
margin: 0;
|
|
||||||
color: #ecf0f1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.navbarCont a.rightB:hover {
|
|
||||||
background-color: #34495e
|
|
||||||
}
|
|
||||||
|
|
||||||
.navbarCont img {
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
.canvasCont {
|
.canvasCont {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
@ -75,9 +36,9 @@ html, body {
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-top: solid black 1px;
|
border-top: solid black 1px;
|
||||||
background-color: var(--utsa-blue);
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height:auto;
|
height: 60px;
|
||||||
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toolbarItems {
|
.toolbarItems {
|
||||||
|
@ -85,7 +46,7 @@ html, body {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
color: white;
|
color: blue;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100px;
|
width: 100px;
|
||||||
|
@ -103,14 +64,7 @@ html, body {
|
||||||
|
|
||||||
|
|
||||||
canvas {
|
canvas {
|
||||||
background-color: white;
|
background-color: lightblue;
|
||||||
margin: 20px;
|
margin: 20px;
|
||||||
image-rendering: pixelated;
|
image-rendering: pixelated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 600px) {
|
|
||||||
.navbarCont a {
|
|
||||||
/* possible hamburger menu for moblie users*/
|
|
||||||
position: absolute
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,16 +13,12 @@
|
||||||
<body>
|
<body>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<div class="navbarCont">
|
<div class="navbarCont">
|
||||||
<a class="icon" href="./index.html"><img src="navbarlogo.png"></img></a>
|
<h1>ThePlaceHolders</h1>
|
||||||
<a class="title" href="./index.html">ThePlaceHolders</a>
|
|
||||||
<a class="rightB" href="./contact.html">Contact</a>
|
|
||||||
<a class="rightB">Login</a>
|
|
||||||
<a class="rightB">Settings</a>
|
|
||||||
</div>
|
</div>
|
||||||
<!--note to self: below IS the canvas-->
|
<!--note to self: below IS the canvas-->
|
||||||
<!--<div class="canvasCont">-->
|
<div class="canvasCont">
|
||||||
<canvas id="canvas" width="1000" height="500" style="border:1px solid #000000;" alt="canvas"></canvas>
|
<canvas id="canvas" width="500" height="500" style="border:1px solid #000000;" alt="canvas"></canvas>
|
||||||
<div id="toolbar" class="d-flex align-items-center toolbar">
|
<div id="toolbar" class="toolbar">
|
||||||
<div class="toolbarItems">
|
<div class="toolbarItems">
|
||||||
<button id="zoomOut">-</button>
|
<button id="zoomOut">-</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -34,7 +30,7 @@
|
||||||
<button onclick="zoomIn"id="zoomIn">+</button>
|
<button onclick="zoomIn"id="zoomIn">+</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--</div>-->
|
</div>
|
||||||
<!--note to self: above IS the canvas-->
|
<!--note to self: above IS the canvas-->
|
||||||
</div>
|
</div>
|
||||||
<script src="./canvas.js"></script>
|
<script src="./canvas.js"></script>
|
||||||
|
|
|
@ -17,9 +17,6 @@ let image = new ImageData(DATA_SIZE, DATA_SIZE);
|
||||||
let bitmap = null;
|
let bitmap = null;
|
||||||
|
|
||||||
window.addEventListener("load", async (e) => {
|
window.addEventListener("load", async (e) => {
|
||||||
for (let x = 0; x < DATA_SIZE * DATA_SIZE * 4; x++) {
|
|
||||||
image.data[x] = 255;
|
|
||||||
}
|
|
||||||
// Create drawable image, update it every half second
|
// Create drawable image, update it every half second
|
||||||
await redraw();
|
await redraw();
|
||||||
setInterval(redraw, 500);
|
setInterval(redraw, 500);
|
||||||
|
@ -49,28 +46,17 @@ function draw() {
|
||||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mousePosition(e) {
|
|
||||||
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 - 0.5);
|
|
||||||
let cy = Math.round(y / (CANVAS_SIZE * scale) * DATA_SIZE - offy - 0.5);
|
|
||||||
return {x: cx, y: cy};
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas.addEventListener("wheel", async (e) => {
|
canvas.addEventListener("wheel", async (e) => {
|
||||||
let mouse = mousePosition(e);
|
|
||||||
console.log(mouse);
|
|
||||||
let oldScale = scale;
|
let oldScale = scale;
|
||||||
if (e.deltaY < 0) {
|
if (e.deltaY < 0) {
|
||||||
scale += 0.1;
|
scale += 0.1;
|
||||||
} else if (e.deltaY > 0) {
|
} else if (e.deltaY > 0) {
|
||||||
scale -= 0.1;
|
scale -= 0.1;
|
||||||
}
|
}
|
||||||
let diff = (CANVAS_SIZE / oldScale) - (CANVAS_SIZE / scale);
|
/*
|
||||||
let ratiox = (mouse.x - (CANVAS_SIZE / 2)) / CANVAS_SIZE;
|
offX += (DATA_SIZE * scale - DATA_SIZE * oldScale) / 2;
|
||||||
let ratioy = (mouse.y - (CANVAS_SIZE / 2)) / CANVAS_SIZE;
|
offY += (DATA_SIZE * scale - DATA_SIZE * oldScale) / 2;
|
||||||
offx += diff * ratiox;
|
*/
|
||||||
offy += diff * ratioy;
|
|
||||||
draw(image);
|
draw(image);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -91,12 +77,17 @@ canvas.addEventListener("mousedown", async (e) => {
|
||||||
canvas.addEventListener("mouseup", async (e) => {
|
canvas.addEventListener("mouseup", async (e) => {
|
||||||
if (e.button == 0 && mouseClicked) {
|
if (e.button == 0 && mouseClicked) {
|
||||||
mouseClicked = false;
|
mouseClicked = false;
|
||||||
|
|
||||||
clickx = e.clientX;
|
clickx = e.clientX;
|
||||||
clicky = e.clientY;
|
clicky = e.clientY;
|
||||||
let mouse = mousePosition(e);
|
|
||||||
let cx = mouse.x;
|
|
||||||
let cy = mouse.y;
|
|
||||||
|
|
||||||
|
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) {
|
if (cx < 0 || cx > CANVAS_SIZE || cy < 0 || cy > CANVAS_SIZE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1,020 B |
37
users.go
37
users.go
|
@ -11,9 +11,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const SESSION_COOKIE_NAME = "utsa-place-session"
|
const SESSION_COOKIE_NAME = "utsa-place-session"
|
||||||
const SESSION_EMAIL = "email"
|
|
||||||
const SESSION_AUTH = "auth"
|
const SESSION_AUTH = "auth"
|
||||||
const SESSION_STARTED = "age"
|
const SESSION_STARTED = "age"
|
||||||
|
const SESSION_CONFIRMED = "confirmed"
|
||||||
|
const SESSION_CONFIRM_KEY = "confirm-key"
|
||||||
|
|
||||||
const ENCRYPTION_STRENGTH = 14
|
const ENCRYPTION_STRENGTH = 14
|
||||||
|
|
||||||
|
@ -22,13 +23,11 @@ type UserData struct {
|
||||||
Password string
|
Password string
|
||||||
AccountCreated time.Time
|
AccountCreated time.Time
|
||||||
LastLogin time.Time
|
LastLogin time.Time
|
||||||
EmailCode string
|
|
||||||
Verified bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validate_email(email string) (string, bool) {
|
func validate_email(email string) (string, bool) {
|
||||||
email = strings.ToLower(email)
|
email = strings.ToLower(email)
|
||||||
regex := regexp.MustCompile("^[a-z0-9]+.[a-z0-9]+@(my.)?utsa.edu")
|
regex := regexp.MustCompile("^[a-z]+.[a-z]+@(my.)?utsa.edu")
|
||||||
ok := regex.MatchString(email)
|
ok := regex.MatchString(email)
|
||||||
return email, ok
|
return email, ok
|
||||||
}
|
}
|
||||||
|
@ -52,7 +51,7 @@ func (s *Server) handle_login(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "./static/login.html")
|
http.ServeFile(w, r, "./static/login.html")
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
// Get data from form
|
// Get data from form
|
||||||
email := strings.ToLower(r.FormValue("email"))
|
email := r.FormValue("email")
|
||||||
password := r.FormValue("password")
|
password := r.FormValue("password")
|
||||||
// Get user from database
|
// Get user from database
|
||||||
user, ok := s.Users[email]
|
user, ok := s.Users[email]
|
||||||
|
@ -76,15 +75,9 @@ func (s *Server) handle_login(w http.ResponseWriter, r *http.Request) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
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_EMAIL] = user.Email
|
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
// Update last-login on DB
|
// Update last-login on DB
|
||||||
user.LastLogin = now
|
user.LastLogin = now
|
||||||
// If email not verified, go to verified page
|
|
||||||
if user.Verified {
|
|
||||||
s.handle_confirmation(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s.Users[email] = user
|
s.Users[email] = user
|
||||||
// Redirect to index.html
|
// Redirect to index.html
|
||||||
fmt.Println("Logged in user: ", email)
|
fmt.Println("Logged in user: ", email)
|
||||||
|
@ -131,13 +124,12 @@ func (s *Server) handle_register(w http.ResponseWriter, r *http.Request) {
|
||||||
Password: hash_password(password),
|
Password: hash_password(password),
|
||||||
AccountCreated: now,
|
AccountCreated: now,
|
||||||
LastLogin: now,
|
LastLogin: now,
|
||||||
EmailCode: "123456",
|
|
||||||
Verified: false,
|
|
||||||
}
|
}
|
||||||
// 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_EMAIL] = email
|
session.Values[SESSION_CONFIRMED] = false
|
||||||
|
session.Values[SESSION_CONFIRM_KEY] = "asdf"
|
||||||
// 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
|
||||||
|
@ -155,26 +147,17 @@ func (s *Server) handle_confirmation(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/register", http.StatusFound)
|
http.Redirect(w, r, "/register", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
email := session.Values[SESSION_EMAIL].(string)
|
|
||||||
user, ok := s.Users[email]
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
fmt.Println("User email confirmed: ", user.Verified)
|
confirmed := session.Values[SESSION_CONFIRMED].(bool)
|
||||||
if user.Verified {
|
fmt.Println("User email confirmed: ", confirmed)
|
||||||
|
if confirmed {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
} else {
|
} else {
|
||||||
http.ServeFile(w, r, "./static/confirmation.html")
|
http.ServeFile(w, r, "./static/confirmation.html")
|
||||||
}
|
}
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
code := r.FormValue("code")
|
default:
|
||||||
if user.EmailCode == code {
|
|
||||||
http.Redirect(w, r, "/", http.StatusAccepted)
|
|
||||||
} else {
|
|
||||||
http.Redirect(w, r, "/confirm-email", http.StatusForbidden)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue