-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.py
166 lines (146 loc) · 5.97 KB
/
User.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 25 05:35:31 2021
@author: Jun Chao
"""
# Importing packages
import streamlit as st
import streamlit_authenticator as stauth
# import pyautogui
import pandas as pd
import numpy as np
from datetime import datetime
from validate_email import validate_email
import re
import nltk
from nltk import WordNetLemmatizer
from nltk.corpus import stopwords
from nltk.corpus import wordnet as wn
from nltk.tokenize import word_tokenize, sent_tokenize
lemmatizer = WordNetLemmatizer()
stop_words = stopwords.words('english')
class CurrentUser:
def __init__(self):
self.user_id = None
self.username = None
self.email = None
self.password = None
def set_user(self, u):
self.user_id = u['user_id']
self.username = u['username']
self.email = u['email']
self.password = u['password']
def get_user_id(self):
return self.user_id
def get_username(self):
return self.username
def get_email(self):
return self.email
def get_password(self):
return self.password
# =============================================================================
# def sign_up_account(self, users):
# st.header('**Sign-Up**')
#
# # Sign up form -> to prevent page refresh after one input
# with st.form(key='signup_form'):
# username = st.text_input(label='Username: ')
# email = st.text_input('Email: ')
# password = st.text_input('Password: ', type="password")
# btn_signup = st.form_submit_button(label='Sign Up')
#
#
# if btn_signup:
# now = datetime.now()
# reg_date = now.strftime("%d/%m/%Y %H:%M:%S")
# if users.empty == True:
# user_id = 1
# exists = False
# else:
# user_id = users.iloc[-1]['user_id'] + 1
# exists = email in self.email
# if not exists:
# valid = validate_email(email)
# if valid:
# users= users.append({
# 'user_id': user_id,
# 'username': username,
# 'email': email,
# 'password': password,
# 'reg_date': reg_date,
# 'del_date': None},
# ignore_index=True)
#
# st.success('Sign Up successful.')
# else:
# st.error("Invalid email.")
# else:
# st.error('Account already exists. Please login.')
# return users
#
#
# def login_account(self, user):
# st.header('**Login**')
#
# # Login form -> to prevent page refresh after one input
# with st.form(key='login_form'):
# email = st.text_input('Email: ')
# password = st.text_input('Password: ', type="password")
# btn_login = st.form_submit_button(label='Login')
#
# login = False
#
# if btn_login:
# exists = (user['email'] == email).any()
# if exists:
# valid_credentials = (len(user[(user['email'] == email) & (user['password'] == password)]) == 1)
#
# if valid_credentials:
# login = True
#
# index = user.index
# user_indices = index[(user['email'] == email) & (user['password'] == password)]
# index = user_indices.tolist()
#
# self.index = index[0]
# self.user_id = user['user_id'].iloc[self.index]
# self.username = user['username'].iloc[self.index]
# self.email = user['email'].iloc[self.index]
# self.password = user['password'].iloc[self.index]
# self.reg_date = user['reg_date'].iloc[self.index]
# self.del_date = user['del_date'].iloc[self.index]
#
# st.success('Login successfully')
#
# else:
# st.error('Incorrect email or password.')
# retry = st.selectbox('Do you want to continue?: ', ('Yes', 'No'))
# if retry == 'Yes':
# self.login_account()
# else:
# st.error('Account not found.')
# return login
# =============================================================================
# =============================================================================
# def edit_account(self):
# edit_menu = st.selectbox('Edit Account Details: ', ('Change Username', 'Change Email', 'Change Password'))
# edit_menu = st.text_area('Enter Number (1-3): ')
# login = self.login_account()
# if login:
# locate = (self.user['email'] == self.email) & (self.user["password"] == self.password)
# if edit_menu == 'Change Username':
# username = st.text_area('Enter New Username: ')
# self.user.at[locate ,'username'] = username
# self.username = username
# st.write('Username updated.')
# elif edit_menu == 'Change Email':
# email = st.text_area('Enter New Email: ')
# self.user.at[locate ,'email'] = email
# self.email = email
# st.write('Email updated.')
# elif edit_menu == 'Change Password':
# password = st.text_area('Enter New Password: ')
# self.user.at[locate ,'password'] = password
# self.password = password
# st.write('Password updated.')
# =============================================================================