Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.server
Commits
6220f3d4
Commit
6220f3d4
authored
Apr 17, 2020
by
Vladislav Rykov
Browse files
data,pend & user dao changed
parent
d173fa12
Changes
5
Show whitespace changes
Inline
Side-by-side
dao/data/data.pyc
View file @
6220f3d4
No preview for this file type
dao/pend/pend.pyc
View file @
6220f3d4
No preview for this file type
dao/user/user.py
View file @
6220f3d4
import
psycopg2
from
misc
import
with_psql
import
bcrypt
import
bcrypt
class
UserDao
:
@
with_psql
def
create
(
cur
,
name
,
password
):
def
__init__
(
self
):
pass
# decorator implementation
def
with_psql
(
f
):
def
_with_psql
(
*
args
,
**
kwargs
):
conn
=
psycopg2
.
connect
(
'dbname=gateway'
)
cur
=
conn
.
cursor
()
try
:
res
=
f
(
cur
,
*
args
,
**
kwargs
)
except
(
Exception
,
psycopg2
.
DatabaseError
)
as
error
:
conn
.
rollback
()
res
=
(
False
,
error
)
else
:
conn
.
commit
()
finally
:
cur
.
close
()
conn
.
close
()
return
res
return
_with_psql
@
staticmethod
@
with_psql
def
create
(
cur
,
name
,
password
):
query
=
"""
query
=
"""
INSERT INTO
INSERT INTO
users
users
...
@@ -39,9 +13,8 @@ class UserDao:
...
@@ -39,9 +13,8 @@ class UserDao:
cur
.
execute
(
query
,
(
name
,
bcrypt
.
hashpw
(
password
,
bcrypt
.
gensalt
())))
cur
.
execute
(
query
,
(
name
,
bcrypt
.
hashpw
(
password
,
bcrypt
.
gensalt
())))
return
(
True
,)
return
(
True
,)
@
staticmethod
@
with_psql
@
with_psql
def
delete
(
cur
,
name
):
def
delete
(
cur
,
name
):
query
=
"""
query
=
"""
DELETE FROM
DELETE FROM
users
users
...
@@ -51,9 +24,8 @@ class UserDao:
...
@@ -51,9 +24,8 @@ class UserDao:
cur
.
execute
(
query
,
(
name
,))
cur
.
execute
(
query
,
(
name
,))
return
(
True
,)
return
(
True
,)
@
staticmethod
@
with_psql
@
with_psql
def
update_name
(
cur
,
old_name
,
new_name
):
def
update_name
(
cur
,
old_name
,
new_name
):
query
=
"""
query
=
"""
UPDATE users SET
UPDATE users SET
name = %s
name = %s
...
@@ -63,9 +35,8 @@ class UserDao:
...
@@ -63,9 +35,8 @@ class UserDao:
cur
.
execute
(
query
,
(
new_name
,))
cur
.
execute
(
query
,
(
new_name
,))
return
(
True
,)
return
(
True
,)
@
staticmethod
@
with_psql
@
with_psql
def
update_password
(
cur
,
name
,
password
):
def
update_password
(
cur
,
name
,
password
):
query
=
"""
query
=
"""
UPDATE users SET
UPDATE users SET
password = %s
password = %s
...
@@ -75,9 +46,8 @@ class UserDao:
...
@@ -75,9 +46,8 @@ class UserDao:
cur
.
execute
(
query
,
(
password
,
name
))
cur
.
execute
(
query
,
(
password
,
name
))
return
(
True
,)
return
(
True
,)
@
staticmethod
@
with_psql
@
with_psql
def
get
(
cur
,
name
,
password
):
def
get
(
cur
,
name
,
password
):
query
=
"""
query
=
"""
SELECT * FROM
SELECT * FROM
users
users
...
...
dao/user/user.pyc
View file @
6220f3d4
No preview for this file type
server.py
View file @
6220f3d4
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
,
session
,
send_from_directory
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
,
session
,
send_from_directory
import
psycopg2
import
psycopg2
import
bcrypt
import
misc
import
dao.user.user
as
ud
import
dao.user.user
as
ud
import
dao.application.application
as
ad
import
dao.application.application
as
ad
import
dao.device.device
as
dd
import
dao.device.device
as
dd
import
dao.pend.pend
as
pend
import
dao.pend.pend
as
pend
import
dao.data.data
as
data
import
dao.data.data
as
data
import
binascii
import
misc
import
os
import
os
...
@@ -44,8 +45,7 @@ def signup():
...
@@ -44,8 +45,7 @@ def signup():
feedback
=
'Username or password fields cannot be empty'
feedback
=
'Username or password fields cannot be empty'
return
render_template
(
'signup.html'
,
feedback
=
feedback
)
return
render_template
(
'signup.html'
,
feedback
=
feedback
)
else
:
else
:
uh
=
ud
.
UserDao
()
res
=
ud
.
create
(
username
,
password
)
res
=
uh
.
create
(
username
,
password
)
if
(
not
res
[
0
]):
if
(
not
res
[
0
]):
return
render_template
(
'signup.html'
,
feedback
=
res
[
1
])
return
render_template
(
'signup.html'
,
feedback
=
res
[
1
])
else
:
else
:
...
@@ -67,8 +67,7 @@ def login():
...
@@ -67,8 +67,7 @@ def login():
feedback
=
'Username or password fields cannot be empty'
feedback
=
'Username or password fields cannot be empty'
return
render_template
(
'login.html'
,
feedback
=
feedback
)
return
render_template
(
'login.html'
,
feedback
=
feedback
)
else
:
else
:
uh
=
ud
.
UserDao
()
res
=
ud
.
get
(
username
,
password
)
res
=
uh
.
get
(
username
,
password
)
if
(
not
res
[
0
]):
if
(
not
res
[
0
]):
return
render_template
(
'login.html'
,
feedback
=
msg
[
1
])
return
render_template
(
'login.html'
,
feedback
=
msg
[
1
])
else
:
else
:
...
...
Write
Preview
Supports
Markdown
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