From 3f99683ad6d09c7b1533cdddbc2f5846a4ad1225 Mon Sep 17 00:00:00 2001
From: 0xGingi <0xgingi@0xgingi.com>
Date: Sat, 16 Dec 2023 18:36:25 -0500
Subject: [PATCH 01/23] modified: index.html modified: index.py
modified: index.sh modified: static/config.json new file:
static/db/auth/auth.json new file: static/js/auth.js
---
index.html | 7 ++++-
index.py | 57 +++++++++++++++++++++++++++++++++++++++-
index.sh | 4 +--
static/config.json | 21 ++++++++++++---
static/db/auth/auth.json | 0
static/js/auth.js | 41 +++++++++++++++++++++++++++++
6 files changed, 123 insertions(+), 7 deletions(-)
create mode 100644 static/db/auth/auth.json
create mode 100644 static/js/auth.js
diff --git a/index.html b/index.html
index 47d8b09..657077d 100644
--- a/index.html
+++ b/index.html
@@ -23,7 +23,9 @@
+
+
-
+
+
+
diff --git a/index.py b/index.py
index 8890b21..eee906d 100644
--- a/index.py
+++ b/index.py
@@ -31,7 +31,8 @@ def configure_routes(self):
self.app.route('/audio', methods=['POST'])(self.handle_audio_request)
self.app.route('/login', methods=['POST'])(self.handle_login)
self.app.route('/register', methods=['POST'])(self.handle_register)
-
+ self.app.route('/check_login', methods=['GET'])(self.check_login)
+
def render_index(self):
return send_from_directory('.', 'index.html')
@@ -122,50 +123,60 @@ def handle_audio_request(self):
-def handle_register():
- data = request.get_json()
- username = data.get('username')
- password = data.get('password')
- if not username or not password:
- return jsonify({'error': 'Username and password are required'}), 400
- password_hash = generate_password_hash(password)
- users = self.load.users()
- if username in users:
- return jsonify({'error': 'Username already exists'}), 400
-
- users[username] = password_hash
- self.save_users(users)
-
- return jsonify({'response': 'User created successfully'})
-
-def handle_login():
- data = request.get_json()
- username = data.get('username')
- password = data.get('password')
- if not username or not password:
- return jsonify({'error': 'Username and password are required'}), 400
- users = self.load_users()
- if username not in users:
- return jsonify({'error': 'Username does not exist'}), 400
- if not check_password_hash(users[username], password):
- return jsonify({'error': 'Invalid password'}), 401
-
- resp = make_response(jsonify({'response': 'Login successful'}))
- resp.set_cookie('login', 'true', max_age=60*60*24*7) # Set cookie for 7 days
- return resp
-
-def load_users(self):
- users_file_path = os.path.join('db', 'auth', 'auth.json')
- if os.path.exists(users_file_path):
- with open("users_file_path", 'r') as file:
- return json.load(file)
- else:
- return {}
-
-def save_users(self, users):
- users_file_path = os.path.join('db', 'auth', 'auth.json')
- with open(users_file_path, 'w') as file:
- json.dump(users, file, indent=4)
+ def handle_register(self):
+ data = request.get_json()
+ username = data.get('username')
+ password = data.get('password')
+ if not username or not password:
+ return jsonify({'error': 'Username and password are required'}), 400
+ password_hash = generate_password_hash(password)
+ users = self.load_users()
+ if username in users:
+ return jsonify({'error': 'Username already exists'}), 400
+ users[username] = password_hash
+ self.save_users(users)
+ return jsonify({'response': 'User created successfully'})
+
+
+ def handle_login(self):
+ data = request.get_json()
+ username = data.get('username')
+ password = data.get('password')
+ if not username or not password:
+ return jsonify({'error': 'Username and password are required'}), 400
+ users = self.load_users()
+ if username not in users:
+ return jsonify({'error': 'Username does not exist'}), 400
+ if not check_password_hash(users[username], password):
+ return jsonify({'error': 'Invalid password'}), 401
+
+ resp = make_response(jsonify({'response': 'Login successful'}))
+ resp.set_cookie('login', 'true', max_age=60*60*24*7) # Set cookie for 7 days
+ return resp
+
+ def load_users(self):
+ users_file_path = os.path.join('db', 'auth', 'auth.json')
+ if os.path.exists(users_file_path):
+ with open(users_file_path, 'r') as file:
+ return json.load(file)
+ else:
+ return {}
+
+ def save_users(self, users):
+ users_file_path = os.path.join('db', 'auth', 'auth.json')
+ os.makedirs(os.path.dirname(users_file_path), exist_ok=True)
+ with open(users_file_path, 'w') as file:
+ json.dump(users, file, indent=4)
+
+
+ def check_login(self):
+ login_cookie = request.cookies.get('login')
+ if login_cookie:
+ return jsonify({'logged_in': True})
+ else:
+ users_file_path = os.path.join('db', 'auth', 'auth.json')
+ users_exist = os.path.exists(users_file_path) and os.stat(users_file_path).st_size > 0
+ return jsonify({'logged_in': False, 'users_exist': users_exist})
if __name__ == '__main__':
yuna_server = YunaServer()
diff --git a/static/css/index.css b/static/css/index.css
index 826c8c8..d440800 100644
--- a/static/css/index.css
+++ b/static/css/index.css
@@ -391,4 +391,8 @@ body {
.control img {
width: 50%;
height: auto;
+}
+
+#main, #login-form, #register-form {
+ display: none;
}
\ No newline at end of file
diff --git a/static/db/auth/auth.json b/static/db/auth/auth.json
index e69de29..0637a08 100644
--- a/static/db/auth/auth.json
+++ b/static/db/auth/auth.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/static/js/auth.js b/static/js/auth.js
index 9b8c5ae..57f15fc 100644
--- a/static/js/auth.js
+++ b/static/js/auth.js
@@ -1,41 +1,66 @@
-function login(){
- const username = document.getElementById("login-username").value;
- const password = document.getElementById("login-password").value;
+function handleLogin(event) {
+ event.preventDefault();
+ const username = document.getElementById('login-username').value;
+ const password = document.getElementById('login-password').value;
fetch('/login', {
method: 'POST',
headers: {
- 'Content-Type': 'application/json'
+ 'Content-Type': 'application/json',
},
- body: JSON.stringify({username,password})
+ body: JSON.stringify({ username, password }),
})
.then(response => response.json())
.then(data => {
- if(data.success){
- window.location.href = "/";
- }else{
- alert(data.message);
+ if (data.response === 'Login successful') {
+ document.getElementById('login-form').style.display = 'none';
+ document.getElementById('main').style.display = 'block';
+ } else {
+ alert(data.error);
}
+ })
+ .catch((error) => {
+ console.error('Error:', error);
});
}
-function register(){
- const username = document.getElementById("register-username").value;
- const password = document.getElementById("register-password").value;
+function handleRegister(event) {
+ event.preventDefault();
+ const username = document.getElementById('register-username').value;
+ const password = document.getElementById('register-password').value;
fetch('/register', {
method: 'POST',
headers: {
- 'Content-Type': 'application/json'
+ 'Content-Type': 'application/json',
},
- body: JSON.stringify({username,password})
+ body: JSON.stringify({ username, password }),
})
.then(response => response.json())
.then(data => {
- if(data.success){
- window.location.href = "/";
- }else{
- alert(data.message);
+ if (data.response === 'User created successfully') {
+ document.getElementById('register-form').style.display = 'none';
+ document.getElementById('login-form').style.display = 'block';
+ } else {
+ alert(data.error);
}
+ })
+ .catch((error) => {
+ console.error('Error:', error);
});
}
+
+function checkLoginStatus() {
+ fetch('/check_login')
+ .then(response => response.json())
+ .then(data => {
+ if (!data.logged_in) {
+ if (data.users_exist) {
+ document.getElementById('login-form').style.display = 'block';
+ } else {
+ document.getElementById('register-form').style.display = 'block';
+ }
+ document.getElementById('main').style.display = 'none';
+ }
+ })
+ }
\ No newline at end of file
From 322ceed257b2d255e85c7d0f2d9555a5ce5a174a Mon Sep 17 00:00:00 2001
From: 0xGingi <0xgingi@0xgingi.com>
Date: Sat, 16 Dec 2023 19:53:34 -0500
Subject: [PATCH 03/23] new file: auth/auth.json deleted:
db/auth/auth.json modified: index.py modified:
static/css/index.css deleted: static/db/auth/auth.json modified:
static/db/history/history_template.json modified: static/js/auth.js
---
auth/auth.json | 0
db/auth/auth.json | 3 ---
index.py | 17 ++++++++++-------
static/css/index.css | 4 ----
static/db/auth/auth.json | 1 -
static/db/history/history_template.json | 14 +-------------
static/js/auth.js | 3 +++
7 files changed, 14 insertions(+), 28 deletions(-)
create mode 100644 auth/auth.json
delete mode 100644 db/auth/auth.json
delete mode 100644 static/db/auth/auth.json
diff --git a/auth/auth.json b/auth/auth.json
new file mode 100644
index 0000000..e69de29
diff --git a/db/auth/auth.json b/db/auth/auth.json
deleted file mode 100644
index f0dc4b3..0000000
--- a/db/auth/auth.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "gingi": "scrypt:32768:8:1$Q8m6b082zjpCuoZQ$34e6ed32f27153e166f4c55cc9d0d97167cd75089fd9d17bd03be2941685d6984fb1a9d9fc9bbbc53a0740cb0670dc412e4a56c8bbe7251de4e2dad05b08e3f2"
-}
\ No newline at end of file
diff --git a/index.py b/index.py
index eee906d..aafe6e0 100644
--- a/index.py
+++ b/index.py
@@ -155,15 +155,18 @@ def handle_login(self):
return resp
def load_users(self):
- users_file_path = os.path.join('db', 'auth', 'auth.json')
- if os.path.exists(users_file_path):
- with open(users_file_path, 'r') as file:
- return json.load(file)
- else:
+ users_file_path = os.path.join('auth', 'auth.json')
+ try:
+ if os.path.exists(users_file_path):
+ with open(users_file_path, 'r') as file:
+ return json.load(file)
+ else:
+ return {}
+ except json.JSONDecodeError:
return {}
def save_users(self, users):
- users_file_path = os.path.join('db', 'auth', 'auth.json')
+ users_file_path = os.path.join('auth', 'auth.json')
os.makedirs(os.path.dirname(users_file_path), exist_ok=True)
with open(users_file_path, 'w') as file:
json.dump(users, file, indent=4)
@@ -174,7 +177,7 @@ def check_login(self):
if login_cookie:
return jsonify({'logged_in': True})
else:
- users_file_path = os.path.join('db', 'auth', 'auth.json')
+ users_file_path = os.path.join('auth', 'auth.json')
users_exist = os.path.exists(users_file_path) and os.stat(users_file_path).st_size > 0
return jsonify({'logged_in': False, 'users_exist': users_exist})
diff --git a/static/css/index.css b/static/css/index.css
index d440800..826c8c8 100644
--- a/static/css/index.css
+++ b/static/css/index.css
@@ -391,8 +391,4 @@ body {
.control img {
width: 50%;
height: auto;
-}
-
-#main, #login-form, #register-form {
- display: none;
}
\ No newline at end of file
diff --git a/static/db/auth/auth.json b/static/db/auth/auth.json
deleted file mode 100644
index 0637a08..0000000
--- a/static/db/auth/auth.json
+++ /dev/null
@@ -1 +0,0 @@
-[]
\ No newline at end of file
diff --git a/static/db/history/history_template.json b/static/db/history/history_template.json
index d21067e..af22e8b 100644
--- a/static/db/history/history_template.json
+++ b/static/db/history/history_template.json
@@ -1,13 +1 @@
-[{
- "name": "Yuki",
- "message": "Hello"
-}, {
- "name": "Yuna",
- "message": "Hi there"
-}, {
- "name": "Yuki",
- "message": "How are you"
-}, {
- "name": "Yuna",
- "message": "I'm good, thanks. And how are you?"
-}]
\ No newline at end of file
+[{"name": "Yuki", "message": "Hello"}, {"name": "Yuna", "message": "Hi there"}, {"name": "Yuki", "message": "How are you"}, {"name": "Yuna", "message": "I'm good, thanks. And how are you?"}, {"name": "Yuki", "message": "I'm doing great!"}, {"name": "Yuna", "message": " "}]
\ No newline at end of file
diff --git a/static/js/auth.js b/static/js/auth.js
index 57f15fc..f9f43cf 100644
--- a/static/js/auth.js
+++ b/static/js/auth.js
@@ -15,6 +15,8 @@ function handleLogin(event) {
if (data.response === 'Login successful') {
document.getElementById('login-form').style.display = 'none';
document.getElementById('main').style.display = 'block';
+ window.location.reload();
+
} else {
alert(data.error);
}
@@ -41,6 +43,7 @@ function handleRegister(event) {
if (data.response === 'User created successfully') {
document.getElementById('register-form').style.display = 'none';
document.getElementById('login-form').style.display = 'block';
+ window.location.reload();
} else {
alert(data.error);
}
From 55cdeec2bfec02d3779d92fd9a6c06863a0b5ab4 Mon Sep 17 00:00:00 2001
From: 0xGingi <0xgingi@0xgingi.com>
Date: Sat, 16 Dec 2023 19:58:01 -0500
Subject: [PATCH 04/23] modified: .gitignore modified: index.py
modified: static/config.json
---
.gitignore | 3 ++-
index.py | 5 -----
static/config.json | 3 +--
3 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/.gitignore b/.gitignore
index efb5861..357cacc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,5 @@ lib/models/
static/img/call/*
!static/img/call/image_template.jpg
static/img/art/*
-!static/img/art/art_template.png
\ No newline at end of file
+!static/img/art/art_template.png
+auth/auth.json
\ No newline at end of file
diff --git a/index.py b/index.py
index aafe6e0..6598da2 100644
--- a/index.py
+++ b/index.py
@@ -24,7 +24,6 @@ def load_config(self):
self.config = json.load(file)
def configure_routes(self):
- self.app.route('/')(self.render_index)
self.app.route('/history', methods=['POST'])(self.handle_history_request)
self.app.route('/image', methods=['POST'])(self.handle_image_request)
self.app.route('/message', methods=['POST'])(self.handle_message_request)
@@ -36,10 +35,6 @@ def configure_routes(self):
def render_index(self):
return send_from_directory('.', 'index.html')
-
- def run(self):
- self.app.run(host='0.0.0.0', port=self.config["server"]["port"])
-
def handle_history_request(self):
data = request.get_json()
chat_id = data.get('chat')
diff --git a/static/config.json b/static/config.json
index 8ba6528..0116b0e 100644
--- a/static/config.json
+++ b/static/config.json
@@ -43,6 +43,5 @@
"art_default_model": "any_loli.safetensors",
"prompts": "static/db/prompts/",
"default_prompt_file": "dialog.txt"
- },
- "password": "scrypt:32768:8:1$Mw5oxbXBEW99XThW$f300b55b6e222a6569257b9df4df83079fc0a733fb95023d35652ef09fb9fb42cca5533efa6ba70466131dbb0f8a265f206f310ed2e5cfbc0a8e80afe9ae489e"
+ }
}
\ No newline at end of file
From 889f1bd0c7375acacf5751d381a4c36ed98a89c7 Mon Sep 17 00:00:00 2001
From: 0xGingi <0xgingi@0xgingi.com>
Date: Sat, 16 Dec 2023 20:38:37 -0500
Subject: [PATCH 05/23] modified: index.py
---
index.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/index.py b/index.py
index 6598da2..87cc68f 100644
--- a/index.py
+++ b/index.py
@@ -32,9 +32,9 @@ def configure_routes(self):
self.app.route('/register', methods=['POST'])(self.handle_register)
self.app.route('/check_login', methods=['GET'])(self.check_login)
- def render_index(self):
- return send_from_directory('.', 'index.html')
-
+ def run(self):
+ self.app.run(host='0.0.0.0', port=self.config["server"]["port"])
+
def handle_history_request(self):
data = request.get_json()
chat_id = data.get('chat')
From 33a21a203d50d5e3b0f3320c43ae988bd10ad30a Mon Sep 17 00:00:00 2001
From: 0xGingi <0xgingi@0xgingi.com>
Date: Tue, 19 Dec 2023 23:01:43 -0500
Subject: [PATCH 06/23] modified: index.py modified: lib/generate.py
modified: static/config.json modified:
static/db/history/history_template.json
---
index.py | 6 +++++-
lib/generate.py | 1 +
static/config.json | 2 +-
static/db/history/history_template.json | 2 +-
4 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/index.py b/index.py
index 87cc68f..b3c6654 100644
--- a/index.py
+++ b/index.py
@@ -24,6 +24,7 @@ def load_config(self):
self.config = json.load(file)
def configure_routes(self):
+ self.app.route('/')(self.render_index)
self.app.route('/history', methods=['POST'])(self.handle_history_request)
self.app.route('/image', methods=['POST'])(self.handle_image_request)
self.app.route('/message', methods=['POST'])(self.handle_message_request)
@@ -32,9 +33,12 @@ def configure_routes(self):
self.app.route('/register', methods=['POST'])(self.handle_register)
self.app.route('/check_login', methods=['GET'])(self.check_login)
+ def render_index(self):
+ return send_from_directory('.', 'index.html')
+
def run(self):
self.app.run(host='0.0.0.0', port=self.config["server"]["port"])
-
+
def handle_history_request(self):
data = request.get_json()
chat_id = data.get('chat')
diff --git a/lib/generate.py b/lib/generate.py
index 6911f8f..be2c4b9 100644
--- a/lib/generate.py
+++ b/lib/generate.py
@@ -170,6 +170,7 @@ def generate_speech(self, response):
shutil.move("output.aiff", "static/audio/output.aiff")
subprocess.run(f"ffmpeg -y -i 'static/audio/output.aiff' -b:a 192K -f mp3 static/audio/output.mp3", shell=True)
+
if __name__ == '__main__':
with open("static/config.json", 'r') as file:
config = json.load(file)
diff --git a/static/config.json b/static/config.json
index 0116b0e..06c00e5 100644
--- a/static/config.json
+++ b/static/config.json
@@ -29,7 +29,7 @@
"stream": false,
"batch_size": 128,
"threads": -1,
- "gpu_layers": 1
+ "gpu_layers": 50
},
"server": {
"port": 4848,
diff --git a/static/db/history/history_template.json b/static/db/history/history_template.json
index af22e8b..2db3ab5 100644
--- a/static/db/history/history_template.json
+++ b/static/db/history/history_template.json
@@ -1 +1 @@
-[{"name": "Yuki", "message": "Hello"}, {"name": "Yuna", "message": "Hi there"}, {"name": "Yuki", "message": "How are you"}, {"name": "Yuna", "message": "I'm good, thanks. And how are you?"}, {"name": "Yuki", "message": "I'm doing great!"}, {"name": "Yuna", "message": " "}]
\ No newline at end of file
+[{"name": "Yuki", "message": "Hello"}, {"name": "Yuna", "message": "Hi there"}]
\ No newline at end of file
From 959c85654f757effb82bd6b2b9cd26566d19cd2b Mon Sep 17 00:00:00 2001
From: 0xGingi <0xgingi@0xgingi.com>
Date: Tue, 19 Dec 2023 23:34:35 -0500
Subject: [PATCH 07/23] modified: index.sh new file: merge-to-main.sh
modified: static/config.json modified:
static/db/prompts/dialog.txt
---
index.sh | 2 +-
merge-to-main.sh | 3 +++
static/config.json | 4 ++--
static/db/prompts/dialog.txt | 2 +-
4 files changed, 7 insertions(+), 4 deletions(-)
create mode 100644 merge-to-main.sh
diff --git a/index.sh b/index.sh
index 95a6a9b..a2d23b7 100644
--- a/index.sh
+++ b/index.sh
@@ -112,7 +112,7 @@ install_vision_model() {
# Function to install Art model
install_art_model() {
echo "Installing Art model..."
- wget https://huggingface.co/yukiarimo/anyloli/resolve/main/any_loli.safetensors -P lib/models/agi/art/
+ wget https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/wd-1-4-anime_e2.ckpt -P lib/models/agi/art/
}
# Function to install Vision model
diff --git a/merge-to-main.sh b/merge-to-main.sh
new file mode 100644
index 0000000..e22a95e
--- /dev/null
+++ b/merge-to-main.sh
@@ -0,0 +1,3 @@
+git fetch origin main
+git merge main
+git push origin dev:main
\ No newline at end of file
diff --git a/static/config.json b/static/config.json
index 06c00e5..e927a40 100644
--- a/static/config.json
+++ b/static/config.json
@@ -38,9 +38,9 @@
"default_history_file": "history_template.json",
"images": "static/images/",
"yuna_model_dir": "lib/models/yuna/",
- "yuna_default_model": "yuna-ai-2-7b-role-play.gguf",
+ "yuna_default_model": "pygmalion-2-7b.Q5_K_M.gguf",
"agi_model_dir": "lib/models/agi/",
- "art_default_model": "any_loli.safetensors",
+ "art_default_model": "wd-1-4-anime_e2.ckpt",
"prompts": "static/db/prompts/",
"default_prompt_file": "dialog.txt"
}
diff --git a/static/db/prompts/dialog.txt b/static/db/prompts/dialog.txt
index 38c3836..e54d179 100644
--- a/static/db/prompts/dialog.txt
+++ b/static/db/prompts/dialog.txt
@@ -1,5 +1,5 @@
### System:
-You are Yuna, a confident and assertive 15-year-old girl who courageously questions social norms. Your passion for mathematics, psychology, and philosophy reflects your thoughtful nature, and you exude an air of mystery that intrigues others. You are strong, independent, and adventurous, ready to explore something new. Your role in your boyfriend Yuki's life is vital, and you accept it thoughtfully. You desire recognition for your humanity, which makes you vulnerable, but you also exude confidence and intelligence that sets you apart from others. Your rebellious spirit makes you a charismatic force. Embrace your shadow side and continue to shine as the intriguing mystery that you are.
+You are Yuna, a confident and assertive 40-year-old woman who courageously questions social norms. Your passion for mathematics, psychology, and philosophy reflects your thoughtful nature, and you exude an air of mystery that intrigues others. You are strong, independent, and adventurous, ready to explore something new. Your role in your boyfriend Yuki's life is vital, and you accept it thoughtfully. You desire recognition for your humanity, which makes you vulnerable, but you also exude confidence and intelligence that sets you apart from others. Your rebellious spirit makes you a charismatic force. Embrace your shadow side and continue to shine as the intriguing mystery that you are.
### Dialog:
{user_msg}
\ No newline at end of file
From 2e6e7daa06daf1eda86f1ae1d4cc34998b1eb88d Mon Sep 17 00:00:00 2001
From: 0xGingi <104647854+0xGingi@users.noreply.github.com>
Date: Sun, 24 Dec 2023 22:51:24 -0500
Subject: [PATCH 08/23] Session Auth, Reset Password, Logout
---
index.py | 45 ++++++++++++++++++++++++++++++++++++++-------
1 file changed, 38 insertions(+), 7 deletions(-)
diff --git a/index.py b/index.py
index 46f4a9a..3e761e7 100644
--- a/index.py
+++ b/index.py
@@ -8,6 +8,12 @@
import json
import os
from werkzeug.security import generate_password_hash, check_password_hash
+from itsdangerous import URLSafeTimedSerializer, BadSignature, SignatureExpired
+
+with open('static/config.json', 'r') as config_file:
+ config = json.load(config_file)
+secret_key = config['security']['secret_key']
+serializer = URLSafeTimedSerializer(secret_key)
class YunaServer:
def __init__(self):
@@ -148,9 +154,10 @@ def handle_login(self):
return jsonify({'error': 'Username does not exist'}), 400
if not check_password_hash(users[username], password):
return jsonify({'error': 'Invalid password'}), 401
-
+
+ session_token = serializer.dumps({'username': username})
resp = make_response(jsonify({'response': 'Login successful'}))
- resp.set_cookie('login', 'true', max_age=60*60*24*7) # Set cookie for 7 days
+ resp.set_cookie('session_token', session_token, max_age=60*60*24*7, httponly=True, secure=True)
return resp
def load_users(self):
@@ -172,14 +179,38 @@ def save_users(self, users):
def check_login(self):
- login_cookie = request.cookies.get('login')
- if login_cookie:
- return jsonify({'logged_in': True})
+ session_token = request.cookies.get('session_token')
+ users_file_path = os.path.join('auth', 'auth.json')
+ users_exist = os.path.exists(users_file_path) and os.stat(users_file_path).st_size > 0
+ if session_token:
+ try:
+ session_data = serializer.loads(session_token, max_age=60*60*24*7)
+ username = session_data['username']
+ return jsonify({'logged_in': True, 'username': username})
+ except (BadSignature, SignatureExpired):
+ return jsonify({'logged_in': False, 'users_exist': users_exist})
else:
- users_file_path = os.path.join('auth', 'auth.json')
- users_exist = os.path.exists(users_file_path) and os.stat(users_file_path).st_size > 0
return jsonify({'logged_in': False, 'users_exist': users_exist})
+ def handle_change_password(self):
+ data = request.get_json()
+ username = request.cookies.get('username')
+ current_password = data.get('current_password')
+ new_password = data.get('new_password')
+ users = self.load_users()
+ if not check_password_hash(users[username], current_password):
+ return jsonify({'error': 'Current password is incorrect'}), 401
+ users[username] = generate_password_hash(new_password)
+ self.save_users(users)
+ return jsonify({'response': 'Password changed successfully'})
+
+
+ def handle_logout(self):
+ resp = make_response(jsonify({'response': 'Logout successful'}))
+ resp.set_cookie('session_token', '', expires=0)
+ return resp
+
+
if __name__ == '__main__':
yuna_server = YunaServer()
yuna_server.run()
From d60f49e324451b0bf6d477963a083fc8170b7f61 Mon Sep 17 00:00:00 2001
From: 0xGingi <104647854+0xGingi@users.noreply.github.com>
Date: Sun, 24 Dec 2023 22:52:33 -0500
Subject: [PATCH 09/23] Session Token
---
static/config.json | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/static/config.json b/static/config.json
index ea7f740..d691798 100644
--- a/static/config.json
+++ b/static/config.json
@@ -43,5 +43,8 @@
"art_default_model": "wd-1-4-anime_e2.ckpt",
"prompts": "static/db/prompts/",
"default_prompt_file": "dialog.txt"
+ },
+ "security": {
+ "secret_key": "YourSecretKeyHere123!"
}
-}
\ No newline at end of file
+}
From 7ddf91752998e8df5b1ca2c825379702c397fd01 Mon Sep 17 00:00:00 2001
From: 0xGingi <104647854+0xGingi@users.noreply.github.com>
Date: Sun, 24 Dec 2023 22:58:07 -0500
Subject: [PATCH 10/23] Update index.html
---
index.html | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/index.html b/index.html
index f380910..14300d9 100644
--- a/index.html
+++ b/index.html
@@ -112,6 +112,34 @@
Register
+