maryna7679 commited on
Commit
3c6f1cc
·
1 Parent(s): 6cc88fe

Registration functionality

Browse files
.idea/CaptionProject.iml CHANGED
@@ -7,4 +7,11 @@
7
  <orderEntry type="inheritedJdk" />
8
  <orderEntry type="sourceFolder" forTests="false" />
9
  </component>
 
 
 
 
 
 
 
10
  </module>
 
7
  <orderEntry type="inheritedJdk" />
8
  <orderEntry type="sourceFolder" forTests="false" />
9
  </component>
10
+ <component name="PyNamespacePackagesService">
11
+ <option name="namespacePackageFolders">
12
+ <list>
13
+ <option value="$MODULE_DIR$/Pages" />
14
+ </list>
15
+ </option>
16
+ </component>
17
  </module>
Pages/Functions/auth_functions.py CHANGED
@@ -1,6 +1,6 @@
1
  from ..Resources.salt import salt
2
  import hashlib
3
- from db_connection import users_ref
4
 
5
 
6
  def encrypt(password):
@@ -8,11 +8,26 @@ def encrypt(password):
8
  return result.hex()
9
 
10
 
11
- def auth_function(username, password):
12
  user_password = users_ref.child(username).get()
 
 
 
 
 
13
  if user_password is None:
14
  return False
15
  pass_input = encrypt(password)
16
  if user_password == pass_input:
17
  return True
18
  return False
 
 
 
 
 
 
 
 
 
 
 
1
  from ..Resources.salt import salt
2
  import hashlib
3
+ from .db_connection import users_ref, get_user_ref
4
 
5
 
6
  def encrypt(password):
 
8
  return result.hex()
9
 
10
 
11
+ def get_password_by_username(username):
12
  user_password = users_ref.child(username).get()
13
+ return user_password
14
+
15
+
16
+ def auth_function(username, password):
17
+ user_password = get_password_by_username(username)
18
  if user_password is None:
19
  return False
20
  pass_input = encrypt(password)
21
  if user_password == pass_input:
22
  return True
23
  return False
24
+
25
+
26
+ def register(username, password):
27
+ if get_password_by_username(username) is not None:
28
+ return "Registration error: Username already exists"
29
+ user_ref = get_user_ref(username)
30
+ pass_hash = encrypt(password)
31
+ user_ref.set(pass_hash)
32
+ return "Registration successful!"
33
+
Pages/Functions/caption_editor_functions.py CHANGED
@@ -1,7 +1,7 @@
1
  import pandas as pd
2
  import json
3
 
4
- FILE_PATH = "../Resources/captions.jsonl"
5
 
6
 
7
  def get_captions_by_video_id(video_id):
 
1
  import pandas as pd
2
  import json
3
 
4
+ FILE_PATH = "Pages/Resources/captions.jsonl"
5
 
6
 
7
  def get_captions_by_video_id(video_id):
Pages/Functions/db_connection.py CHANGED
@@ -1,7 +1,7 @@
1
  import firebase_admin
2
  from firebase_admin import db
3
 
4
- KEY_PATH = '../Resources/key.json'
5
 
6
  cred_obj = firebase_admin.credentials.Certificate(KEY_PATH)
7
  default_app = firebase_admin.initialize_app(cred_obj, {
@@ -9,3 +9,7 @@ default_app = firebase_admin.initialize_app(cred_obj, {
9
  })
10
  videos_ref = db.reference("/Videos")
11
  users_ref = db.reference("/Users")
 
 
 
 
 
1
  import firebase_admin
2
  from firebase_admin import db
3
 
4
+ KEY_PATH = 'Pages/Resources/key.json'
5
 
6
  cred_obj = firebase_admin.credentials.Certificate(KEY_PATH)
7
  default_app = firebase_admin.initialize_app(cred_obj, {
 
9
  })
10
  videos_ref = db.reference("/Videos")
11
  users_ref = db.reference("/Users")
12
+
13
+
14
+ def get_user_ref(user):
15
+ return db.reference("/Users/" + user)
Pages/Functions/video_player_functions.py CHANGED
@@ -1,5 +1,5 @@
1
  import re
2
- from db_connection import videos_ref
3
 
4
 
5
  def youtube_link_to_id(link):
 
1
  import re
2
+ from .db_connection import videos_ref
3
 
4
 
5
  def youtube_link_to_id(link):
Pages/main_page.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
- from Functions.video_player_functions import youtube_link_to_id, get_video_embed_by_id, get_video_link_by_pointer
3
- from Functions.caption_editor_functions import get_captions_by_video_id, save_dataframe
4
- from Resources.css import css
5
 
6
  next_video_pointer = 0
7
  user = ""
 
1
  import gradio as gr
2
+ from .Functions.video_player_functions import youtube_link_to_id, get_video_embed_by_id, get_video_link_by_pointer
3
+ from .Functions.caption_editor_functions import get_captions_by_video_id, save_dataframe
4
+ from .Resources.css import css
5
 
6
  next_video_pointer = 0
7
  user = ""
Pages/registration_page.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
 
3
  with gr.Blocks() as registration:
4
  with gr.Column(variant="panel"):
@@ -8,4 +9,4 @@ with gr.Blocks() as registration:
8
  registration_button = gr.Button(value="Register")
9
  registration_result = gr.Markdown()
10
 
11
- # registration_button.click(fn=func, inputs=[username, password], outputs=registration_result)
 
1
  import gradio as gr
2
+ from .Functions.auth_functions import register
3
 
4
  with gr.Blocks() as registration:
5
  with gr.Column(variant="panel"):
 
9
  registration_button = gr.Button(value="Register")
10
  registration_result = gr.Markdown()
11
 
12
+ registration_button.click(fn=register, inputs=[username, password], outputs=registration_result)
README.md CHANGED
Binary files a/README.md and b/README.md differ