Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
21_22-J 38
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 38
21_22-J 38
Commits
89274bdb
Commit
89274bdb
authored
Apr 24, 2022
by
W.D.R.P. Sandeepa
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'it18218640' into 'master'
complete login fun See merge request
!141
parents
2294ffe2
a1c15a36
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
15256 additions
and
102 deletions
+15256
-102
API/app.py
API/app.py
+94
-68
API/db/dbConnection.py
API/db/dbConnection.py
+1
-1
API/model/userModel.py
API/model/userModel.py
+2
-2
frontend/package-lock.json
frontend/package-lock.json
+15092
-23
frontend/src/router/router.js
frontend/src/router/router.js
+1
-1
frontend/src/screen/auth/Login.js
frontend/src/screen/auth/Login.js
+41
-5
frontend/src/screen/auth/Register.js
frontend/src/screen/auth/Register.js
+25
-2
No files found.
API/app.py
View file @
89274bdb
import
re
import
MySQLdb
import
mysql
from
flask
import
Flask
,
redirect
,
url_for
,
render_template
,
request
,
jsonify
,
make_response
from
flask
import
Flask
,
redirect
,
url_for
,
render_template
,
request
,
jsonify
,
make_response
import
random
import
random
import
os
import
os
...
@@ -18,35 +22,36 @@ app = Flask(__name__)
...
@@ -18,35 +22,36 @@ app = Flask(__name__)
def
home
():
def
home
():
return
render_template
(
'home.html'
)
return
render_template
(
'home.html'
)
#
@app.route('/register', methods =['POST'])
@
app
.
route
(
'/register'
,
methods
=
[
'POST'
])
#
def register():
def
register
():
#
msg = ''
msg
=
''
#
if request.method == 'POST' and 'username' in request.form and 'password' in request.form and 'email' in request.form:
if
request
.
method
==
'POST'
and
'username'
in
request
.
form
and
'password'
in
request
.
form
and
'email'
in
request
.
form
:
#
username = request.form['username']
username
=
request
.
form
[
'username'
]
#
password = request.form['password']
password
=
request
.
form
[
'password'
]
#
email = request.form['email']
email
=
request
.
form
[
'email'
]
#
cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor
=
mysql
.
connection
.
cursor
(
MySQLdb
.
cursors
.
DictCursor
)
#
cursor.execute('SELECT * FROM user WHERE name = % s', (username,))
cursor
.
execute
(
'SELECT * FROM user WHERE name =
%
s'
,
(
username
,))
#
account = cursor.fetchone()
account
=
cursor
.
fetchone
()
#
if account:
if
account
:
#
msg = 'Account already exists !'
msg
=
'Account already exists !'
#
elif not re.match(r'[^@]+@[^@]+\.[^@]+', email):
elif
not
re
.
match
(
r'[^@]+@[^@]+\.[^@]+'
,
email
):
#
msg = 'Invalid email address !'
msg
=
'Invalid email address !'
#
elif not re.match(r'[A-Za-z0-9]+', username):
elif
not
re
.
match
(
r'[A-Za-z0-9]+'
,
username
):
#
msg = 'Username must contain only characters and numbers !'
msg
=
'Username must contain only characters and numbers !'
#
elif not username or not password or not email:
elif
not
username
or
not
password
or
not
email
:
#
msg = 'Please fill out the form !'
msg
=
'Please fill out the form !'
#
else:
else
:
#
cursor.execute('INSERT INTO accounts VALUES (NULL, % s, % s, % s)', (username, password, email,))
cursor
.
execute
(
'INSERT INTO accounts VALUES (NULL,
%
s,
%
s,
%
s)'
,
(
username
,
password
,
email
,))
#
mysql.connection.commit()
mysql
.
connection
.
commit
()
#
msg = 'You have successfully registered !'
msg
=
'You have successfully registered !'
#
elif request.method == 'POST':
elif
request
.
method
==
'POST'
:
#
msg = 'Please fill out the form !'
msg
=
'Please fill out the form !'
#
return msg
return
msg
# Color Function Route (IT18218640)
# Color Function Route (IT18218640)
# Get Color activities route
# Get Color activities route
@
app
.
route
(
"/getColorActivities1"
)
@
app
.
route
(
"/getColorActivities1"
)
def
getColorActivities1
():
def
getColorActivities1
():
return
get_color_activities1
()
return
get_color_activities1
()
...
@@ -60,43 +65,61 @@ def getColorActivitiesResult():
...
@@ -60,43 +65,61 @@ def getColorActivitiesResult():
# print("data_dic")
# print("data_dic")
return
get_color_activity_result
()
return
get_color_activity_result
()
# @app.route("/predict", methods=["POST"])
@
app
.
route
(
"/predict"
,
methods
=
[
"POST"
])
# def predict():
def
predict
():
# # get audio file and save it
# audio_file = request.files["file"]
data
=
request
.
get_json
()
#
print
((
f
"{data}"
))
# print(f"{request.files['file']}")
# # print(f"{request.files['name']}")
fileitem
=
data
[
'uri'
]
#
# ######################################
# if fileitem.filename:
# print(f"{request.form['name']}")
# # strip the leading path from the file name
# #####################################
fn
=
os
.
path
.
basename
(
fileitem
)
# # print(f"{request.json}")
#
#
# # open read and write the file into the server
# file_name = str(random.randint(0, 100000))
open
(
fn
,
'wb'
)
.
write
(
fileitem
.
file
.
read
())
# # audio_file.save((file_name))
#
resp
=
make_response
(
request
.
get_json
())
# # get file name
resp
.
headers
[
'Access-Control-Allow-Origin'
]
=
'*'
# # predict_file_name = audio_file.filename
resp
.
headers
[
'Content-Type'
]
=
'application/json'
# # predict_file_name = predict_file_name.split("/")
return
resp
# # new_predict_file_name = predict_file_name[1]
# # new_predict_file_name = new_predict_file_name.split(".")
# get audio file and save it
# # FPFN = new_predict_file_name[0]
# audio_file = request.files["file"]
# # print(f"{FPFN}")
# audio_file = request.files["name"]
#
# # invoke keyword spotting service
# print((f"{request.data}"))
# kss = Keyword_Spotting_service()
# print((f"{request.form}"))
#
# print((f"{request.values}"))
# # make a prediction
# print((f"{request.json}"))
# predicted_keyword = kss.predict(file_name, request.form['name'])
# print(f"{request.form['name']}")
#
# file_name = str(random.randint(0, 100000))
# # remove the audio file
# audio_file.save((file_name))
# os.remove(file_name)
#
#
# # get file name
# # send back the predicted keword in json format
# predict_file_name = audio_file.filename
# data = {"Keyword": predicted_keyword}
# predict_file_name = predict_file_name.split("/")
# return jsonify(data)
# new_predict_file_name = predict_file_name[1]
# # return "audio_file"
# new_predict_file_name = new_predict_file_name.split(".")
# FPFN = new_predict_file_name[0]
# # print(f"{FPFN}")
#
# # invoke keyword spotting service
# kss = Keyword_Spotting_service()
#
#
# # make a prediction
# predicted_keyword = kss.predict(file_name, FPFN)
#
# # remove the audio file
# os.remove(file_name)
#
# # send back the predicted keword in json format
# data = {"Keyword" : predicted_keyword}
# return jsonify("print")
# return "Print"
# Read Function Route (IT)
# Read Function Route (IT)
...
@@ -119,26 +142,29 @@ def abc():
...
@@ -119,26 +142,29 @@ def abc():
# Loging
# Loging
@
app
.
route
(
"/login"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/login"
,
methods
=
[
'POST'
])
def
login
():
def
login
():
req
=
request
.
get_json
()
req
=
request
.
get_json
()
username
=
req
[
'username
'
]
email
=
req
[
'email
'
]
password
=
req
[
'password'
]
password
=
req
[
'password'
]
user
=
getStudentByName
(
username
,
password
)
user
=
getStudentByName
(
email
,
password
)
if
len
(
user
)
==
0
:
if
len
(
user
)
==
0
:
data
=
{
data
=
{
"body"
:
[],
"body"
:
[],
"message"
:
"Failed"
"message"
:
"Failed"
,
"status"
:
404
}
}
else
:
else
:
data
=
{
data
=
{
"body"
:
user
,
"body"
:
user
,
"message"
:
"Success"
"message"
:
"Success"
,
"status"
:
200
}
}
body
=
jsonify
(
data
)
body
=
jsonify
(
data
)
return
make_response
(
body
)
return
make_response
(
body
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
# app.run(host='192.168.8.101
')
app
.
run
(
host
=
'192.168.8.102
'
)
# app.run(host='192.168.8.100,port='5000', debug=True)
# app.run(host='192.168.8.100,port='5000', debug=True)
app
.
run
(
debug
=
True
)
# app.run(debug=True)
\ No newline at end of file
\ No newline at end of file
API/db/dbConnection.py
View file @
89274bdb
...
@@ -12,7 +12,7 @@ def create_con():
...
@@ -12,7 +12,7 @@ def create_con():
database
=
"helply"
,
database
=
"helply"
,
host
=
"127.0.0.1"
,
host
=
"127.0.0.1"
,
user
=
"root"
,
user
=
"root"
,
password
=
"
12345678
"
password
=
"
rp19970520
"
)
)
return
db
return
db
...
...
API/model/userModel.py
View file @
89274bdb
from
API.db.dbConnection
import
get_data
from
API.db.dbConnection
import
get_data
def
getStudentByName
(
username
,
password
):
def
getStudentByName
(
email
,
password
):
qry
=
'SELECT * FROM `user` WHERE
name = "{}" AND password = "{}"'
.
format
(
username
,
password
)
qry
=
'SELECT * FROM `user` WHERE
email = "{}" AND password = "{}"'
.
format
(
email
,
password
)
user
=
get_data
(
qry
)
user
=
get_data
(
qry
)
return
user
return
user
frontend/package-lock.json
View file @
89274bdb
This diff is collapsed.
Click to expand it.
frontend/src/router/router.js
View file @
89274bdb
...
@@ -7,7 +7,7 @@ import Home from '../screen/home';
...
@@ -7,7 +7,7 @@ import Home from '../screen/home';
import
Start
from
'
../screen/Start
'
;
import
Start
from
'
../screen/Start
'
;
import
Register
from
'
../screen/auth/Register
'
;
import
Register
from
'
../screen/auth/Register
'
;
import
Login
from
'
../screen/auth/Login
'
;
import
Login
from
'
../screen/auth/Login
'
;
import
Splash
from
'
../screen/splash/
s
plash
'
;
import
Splash
from
'
../screen/splash/
S
plash
'
;
import
Color
from
'
../screen/Color
'
;
import
Color
from
'
../screen/Color
'
;
import
Blue
from
'
../screen/activity/Blue
'
;
import
Blue
from
'
../screen/activity/Blue
'
;
import
Read
from
'
../screen/Read
'
;
import
Read
from
'
../screen/Read
'
;
...
...
frontend/src/screen/auth/Login.js
View file @
89274bdb
...
@@ -3,6 +3,8 @@ import Orientation from 'react-native-orientation-locker';
...
@@ -3,6 +3,8 @@ import Orientation from 'react-native-orientation-locker';
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
SafeAreaView
,
ScrollView
,
View
,
StyleSheet
,
ImageBackground
,
Text
,
TextInput
,
TouchableOpacity
,
Image
}
from
"
react-native
"
;
import
{
SafeAreaView
,
ScrollView
,
View
,
StyleSheet
,
ImageBackground
,
Text
,
TextInput
,
TouchableOpacity
,
Image
}
from
"
react-native
"
;
import
client
from
"
../client/Client
"
;
const
isValidObjectField
=
(
obj
)
=>
{
const
isValidObjectField
=
(
obj
)
=>
{
return
Object
.
values
(
obj
).
every
(
value
=>
value
.
trim
());
return
Object
.
values
(
obj
).
every
(
value
=>
value
.
trim
());
}
}
...
@@ -66,11 +68,45 @@ const Login = () => {
...
@@ -66,11 +68,45 @@ const Login = () => {
const
submitForm
=
()
=>
{
const
submitForm
=
()
=>
{
if
(
isValidForm
()){
if
(
isValidForm
()){
()
=>
{
navigation
.
navigate
(
"
Start
"
)}
console
.
log
(
userInfo
);
loginFun
(
userInfo
)
}
}
}
}
const
loginFun
=
()
=>
{
var
formData
=
JSON
.
stringify
(
userInfo
);
client
.
post
(
'
login
'
,
formData
,
{
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
})
.
then
((
response
)
=>
{
console
.
log
(
response
.
data
);
if
(
response
.
data
.
status
==
404
){
return
updateError
(
'
Please register our system
'
,
setError
);
}
if
(
response
.
data
.
status
==
200
){
return
navigation
.
navigate
(
"
Start
"
);
}
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
});
}
return
(
return
(
<
SafeAreaView
>
<
SafeAreaView
>
<
ScrollView
>
<
ScrollView
>
...
@@ -85,15 +121,15 @@ const Login = () => {
...
@@ -85,15 +121,15 @@ const Login = () => {
{
error
?
(
<
Text
style
=
{{
color
:
'
red
'
,
fontSize
:
18
,
textAlign
:
'
center
'
}}
>
{
error
}
<
/Text>
)
: null
}
{
error
?
(
<
Text
style
=
{{
color
:
'
red
'
,
fontSize
:
18
,
textAlign
:
'
center
'
}}
>
{
error
}
<
/Text>
)
: null
}
<
View
style
=
{
styles
.
form_input
}
>
<
View
style
=
{
styles
.
form_input
}
>
<
TextInput
value
=
{
email
}
autoCapitalize
=
"
none
"
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
email
'
)}
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Email
"
><
/TextInput
>
<
TextInput
id
=
"
email
"
value
=
{
email
}
autoCapitalize
=
"
none
"
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
email
'
)}
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Email
"
><
/TextInput
>
<
/View
>
<
/View
>
<
View
style
=
{
styles
.
form_input
}
>
<
View
style
=
{
styles
.
form_input
}
>
<
TextInput
value
=
{
password
}
autoCapitalize
=
"
none
"
secureTextEntry
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
password
'
)}
keyboardType
=
"
visible-password
"
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Password
"
><
/TextInput
>
<
TextInput
id
=
"
password
"
value
=
{
password
}
autoCapitalize
=
"
none
"
secureTextEntry
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
password
'
)}
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Password
"
><
/TextInput
>
<
/View
>
<
/View
>
<
View
style
=
{
styles
.
form_input
}
>
<
View
style
=
{
styles
.
form_input
}
>
<
TouchableOpacity
onPress
=
{
()
=>
{
navigation
.
navigate
(
"
Home
"
)}
}
style
=
{
styles
.
btn
}
>
<
TouchableOpacity
onPress
=
{
submitForm
}
style
=
{
styles
.
btn
}
>
<
Text
style
=
{
styles
.
btn_text
}
>
<
Text
style
=
{
styles
.
btn_text
}
>
Sign
In
Sign
In
<
/Text
>
<
/Text
>
...
...
frontend/src/screen/auth/Register.js
View file @
89274bdb
...
@@ -82,11 +82,34 @@ const Register = () => {
...
@@ -82,11 +82,34 @@ const Register = () => {
const
submitForm
=
()
=>
{
const
submitForm
=
()
=>
{
if
(
isValidForm
()){
if
(
isValidForm
()){
console
.
log
(
userInfo
);
// console.log(userInfo);
registerFun
(
userInfo
);
}
}
}
}
// import client from "../client/Client";
const
registerFun
=
()
=>
{
console
.
log
(
userInfo
.
email
);
// client.get('register', userInfo, {
// headers: {
// Accept: 'application/json',
// 'Content-Type': 'application/json',
// },
// })
// .then((response) => {
// console.log(response);
// })
// .catch((err) => {
// console.log(err);
// });
}
return
(
return
(
<
SafeAreaView
>
<
SafeAreaView
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment