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
8166056b
Commit
8166056b
authored
Apr 27, 2020
by
Vladislav Rykov
Browse files
users signup under admin control
parent
2bc4157a
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/app/__pycache__/views.cpython-35.pyc
View file @
8166056b
No preview for this file type
app/app/templates/admin/settings.html
0 → 100644
View file @
8166056b
{% extends 'layout.html' %}
{% block title %} Settings {{ username }} {% endblock %}
{% block content %}
<div
class=
"row"
>
<div
class=
"col-md-3"
>
<div
class=
"clickback"
>
<span
class=
"glyphicon glyphicon-arrow-left"
></span>
<p><a
class=
"backlink"
onclick=
"history.back(-1)"
></a></p>
</div>
</div>
<div
class=
"col-md-6"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<h2><center>
Settings {{ username }}:
</center></h2>
</div>
<div
class=
"panel-body"
>
<form
class=
"form-inline"
action=
"settings"
method=
"post"
>
<h4>
Personal Settings:
</h4>
<br>
<table
class=
"table"
>
<tr>
<td>
<label
for=
"name"
>
Name
</label>
</td>
<td>
<input
type=
"text"
class=
"form-control"
id=
"name"
name=
"name"
value=
"{{ username }}"
>
</td>
</tr>
<tr>
<td>
<label
for=
"password"
>
Password
</label>
</td>
<td>
<input
type=
"password"
class=
"form-control"
id=
"password"
name=
"password"
placeholder=
"Password"
>
</td>
</tr>
</table>
<br>
<h4>
Administrative Settings:
</h4>
<table
class=
"table"
>
<tr>
<td>
<label
for=
"users_signup"
>
Allow users to signup autonomously
</label>
</td>
<td>
<input
type=
"checkbox"
class=
"form-control"
id=
"users_signup"
name=
"users_signup"
value=
"us"
{%
if
users_signup
%}
checked
{%
endif
%}
>
</td>
</tr>
</table>
<button
type=
"submit"
class=
"btn btn-default"
>
Save
</button>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
app/app/views.py
View file @
8166056b
...
@@ -28,11 +28,11 @@ def index():
...
@@ -28,11 +28,11 @@ def index():
session
.
pop
(
'appkey'
,
None
)
session
.
pop
(
'appkey'
,
None
)
# print('apps: ', apps)
# print('apps: ', apps)
if
apps
[
0
]:
if
apps
[
0
]:
return
render_template
(
'public/index.html'
,
apps
=
apps
[
1
])
return
render_template
(
'public/index.html'
,
apps
=
apps
[
1
]
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]
)
else
:
else
:
return
render_template
(
'public/index.html'
,
feedback
=
apps
[
1
])
return
render_template
(
'public/index.html'
,
feedback
=
apps
[
1
]
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]
)
else
:
else
:
return
render_template
(
'public/index.html'
)
return
render_template
(
'public/index.html'
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]
)
...
@@ -40,12 +40,12 @@ def index():
...
@@ -40,12 +40,12 @@ def index():
def
signup
():
def
signup
():
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
if
session
[
'role'
]
and
session
[
'role'
]
==
'admin'
:
if
session
[
'role'
]
and
session
[
'role'
]
==
'admin'
:
return
render_template
(
'admin/signup.html'
)
return
render_template
(
'admin/signup.html'
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]
)
else
:
else
:
if
app
.
config
[
'USERS_SIGNUP'
]:
if
app
.
config
[
'USERS_SIGNUP'
]:
return
render_template
(
'public/signup.html'
)
return
render_template
(
'public/signup.html'
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]
)
else
:
else
:
return
redirect
(
url_for
(
'index'
))
return
redirect
(
url_for
(
'index'
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]
))
else
:
else
:
if
app
.
config
[
'USERS_SIGNUP'
]
or
session
[
'role'
]
==
'admin'
:
if
app
.
config
[
'USERS_SIGNUP'
]
or
session
[
'role'
]
==
'admin'
:
username
=
request
.
form
[
'username'
]
username
=
request
.
form
[
'username'
]
...
@@ -53,10 +53,10 @@ def signup():
...
@@ -53,10 +53,10 @@ def signup():
if
(
username
==
''
or
password
==
''
):
if
(
username
==
''
or
password
==
''
):
feedback
=
'Username or password fields cannot be empty'
feedback
=
'Username or password fields cannot be empty'
return
render_template
(
'public/signup.html'
,
feedback
=
feedback
)
return
render_template
(
'public/signup.html'
,
feedback
=
feedback
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]
)
elif
(
len
(
password
)
<
8
):
elif
(
len
(
password
)
<
8
):
flash
(
'Password length must be at least 8 characters.'
,
'danger'
)
flash
(
'Password length must be at least 8 characters.'
,
'danger'
)
return
redirect
(
request
.
url
)
return
redirect
(
request
.
url
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]
)
else
:
else
:
role
=
'user'
role
=
'user'
if
request
.
form
[
'role'
]
and
request
.
form
[
'role'
]
==
'administrator'
:
if
request
.
form
[
'role'
]
and
request
.
form
[
'role'
]
==
'administrator'
:
...
@@ -444,7 +444,7 @@ def user_delete():
...
@@ -444,7 +444,7 @@ def user_delete():
def
settings
():
def
settings
():
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
if
session
[
'role'
]
==
'admin'
:
if
session
[
'role'
]
==
'admin'
:
return
render_template
(
'
public
/settings.html'
,
username
=
session
[
'name'
])
return
render_template
(
'
admin
/settings.html'
,
username
=
session
[
'name'
]
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]
)
else
:
else
:
return
render_template
(
'public/settings.html'
,
username
=
session
[
'name'
])
return
render_template
(
'public/settings.html'
,
username
=
session
[
'name'
])
else
:
else
:
...
@@ -459,10 +459,15 @@ def settings():
...
@@ -459,10 +459,15 @@ def settings():
res
=
ud
.
update_password
(
session
[
'name'
],
request
.
form
[
'password'
].
encode
(
'utf-8'
))
res
=
ud
.
update_password
(
session
[
'name'
],
request
.
form
[
'password'
].
encode
(
'utf-8'
))
if
not
res
[
0
]:
if
not
res
[
0
]:
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
return
redirect
(
request
.
url
);
return
redirect
(
request
.
url
)
if
session
[
'role'
]
==
'admin'
:
if
request
.
form
.
getlist
(
'users_signup'
)
and
request
.
form
.
getlist
(
'users_signup'
)[
0
]
==
'us'
:
app
.
config
[
'USERS_SIGNUP'
]
=
True
else
:
app
.
config
[
'USERS_SIGNUP'
]
=
False
return
redirect
(
url_for
(
'index'
)
)
return
redirect
(
request
.
url
)
def
pend_delete_all_ack
():
def
pend_delete_all_ack
():
...
...
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