diff --git a/README.md b/README.md
index 12aff0a..9de02d5 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@ Start the application by running `app.py` in the `Exam_code` folder.
* If a user tries to register and fails a specification e.g. password too short or etc., the server sends a JSON with all errors that the user must fix to register.
* Users may be choose to delete their account and subsequently all information about this user will be deleted.
* Users can change their username and Bio, Changes still gets checked for the same criteria as when a user is created.
+ * Users can change the color of elements in their own page.
- Projects:
* Users that register with a github username will automatically get all their public repos' information into the application. The app will update the information if their userpage is visited and it has been at least 10 minutes since last time the information was updated. This is done by using the github API.
diff --git a/app.py b/app.py
index 02a0189..a5cb9af 100644
--- a/app.py
+++ b/app.py
@@ -101,7 +101,13 @@ def users():
username = request.form.get("username","").strip().lower()
password = request.form.get("password","")
bio = request.form.get("bio","").strip()
- github = request.form.get("github","")
+ github = request.form.get("github","").strip()
+ email = request.form.get("email","").strip()
+ twitter = request.form.get("twitter","").strip()
+
+ print(email)
+ print(twitter)
+
errors = validate_input(username, password)
@@ -113,7 +119,7 @@ def users():
try:
# Insert user
hash = generate_password_hash(password)
- query_db("INSERT INTO users (username, passwordhash, bio, github, timestamp) VALUES (?,?,?,?, datetime('now', 'localtime'))", get_db(), username, hash, bio, github)
+ query_db("INSERT INTO users (username, passwordhash, bio, github, twitter, email, timestamp) VALUES (?,?,?,?, ?, ?,datetime('now', 'localtime'))", get_db(), username, hash, bio, github, twitter, email)
userid = query_db("SELECT MAX(ID) FROM users", get_db(), one=True)[0]
except sqlite3.IntegrityError:
errors.append("Username is already taken")
@@ -175,17 +181,19 @@ def user(userid):
for error in validate_bio(bio):
errors.append(error)
+ color = request.form.get("color")
+
if len(errors) == 0:
# Check if different username
if username != query_db("select username from users WHERE id=?", get_db(), session.get("userid"), one=True)[0]:
# Check if username is taken
taken = query_db("select count(username) FROM users WHERE username=?;", get_db(), username, one=True)
if taken[0] == 0:
- query_db("UPDATE users SET username=?, bio=? WHERE id = ?;", get_db(), username, bio, userid, one=True)
+ query_db("UPDATE users SET username=?, bio=?, color=? WHERE id = ?;", get_db(), username, bio, color, userid, one=True)
else:
errors.append("Username is taken")
else:
- query_db("UPDATE users SET username=?, bio=? WHERE id = ?;", get_db(), username, bio, userid, one=True)
+ query_db("UPDATE users SET bio=?, color=? WHERE id = ?;", get_db(), bio, color, userid, one=True)
response["errors"] = errors
return json.dumps(response)
@@ -263,7 +271,6 @@ def serve(userid):
github = user[1]
repos = db_update(github)
update_insert(repos, userid)
- # TODO check if ovveride or not :/
update_timestamp(userid)
diff --git a/schema.sql b/schema.sql
index 37bf1d7..ed24865 100644
--- a/schema.sql
+++ b/schema.sql
@@ -7,7 +7,6 @@ CREATE TABLE users(
id INTEGER,
username VARCHAR(20) NOT NULL UNIQUE,
passwordhash VARCHAR(120) NOT NULL,
- token text,
bio VARCHAR(250),
color text,
email text,
@@ -28,7 +27,6 @@ CREATE TABLE projects(
website TEXT,
link TEXT,
private BOOLEAN,
- override BOOLEAN,
FOREIGN KEY(userid) REFERENCES users(id) ON DELETE CASCADE
);
diff --git a/static/components.js b/static/components.js
index 03ff0f2..bd59395 100644
--- a/static/components.js
+++ b/static/components.js
@@ -1,12 +1,3 @@
-let state = {
- user: Vue.reactive({
- username: "",
- userid: "",
- })
-};
-
-
-
let homeC = {
template: /*html*/ `
@@ -198,7 +189,7 @@ let userC = {
-
+
@@ -214,7 +205,8 @@ let userC = {
-
+
+
@@ -223,8 +215,9 @@ let userC = {
-
-
+
+
+
@@ -233,7 +226,7 @@ let userC = {
-
+ User has yet to post
@@ -243,11 +236,11 @@ let userC = {
-
+ User has no projects
-
+
@@ -270,6 +263,9 @@ let userC = {
showEditUser: false,
editbio: "",
editUsername: "",
+ color: "#15181c",
+ prevcolor: "#15181c",
+ user: {github: "", twitter: "", email:""}
}
},
created: async function() {
@@ -289,6 +285,7 @@ let userC = {
},
methods: {
get_data: async function() {
+ // Get userid from params
let response2 = await fetch("/api/userid/" + this.$route.params.id);
if (response2.status == 200){
result = await response2.json();
@@ -320,6 +317,10 @@ let userC = {
if (response1.status == 200){
let result = await response1.json();
this.bio = result.bio;
+ this.color = result.color;
+ this.user.github = result.github;
+ this.user.twitter = result.twitter;
+ this.user.email = result.email;
}
},
@@ -461,11 +462,10 @@ let userC = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
- body: "bio=" + this.editbio + "&username=" + this.editUsername
+ body: "bio=" + this.editbio + "&username=" + this.editUsername + "&color=" + this.color
});
if (response.status == 200){
result = await response.json();
-
if (result.errors.length != 0){
let text = ""
for (i in result.errors) {
@@ -478,6 +478,7 @@ let userC = {
this.bio = this.editbio;
this.$route.params.id = this.editUsername;
state.user.username = this.editUsername;
+ this.prevcolor = this.color;
}
}
diff --git a/static/formcomponents.js b/static/formcomponents.js
index 4f908eb..f6ce160 100644
--- a/static/formcomponents.js
+++ b/static/formcomponents.js
@@ -236,7 +236,10 @@ let registerC = {