Commit ca4000a3 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

register view integrated

parent 934b4f89
...@@ -7,7 +7,7 @@ def create_datatable(cur, appkey, dev_id): ...@@ -7,7 +7,7 @@ def create_datatable(cur, appkey, dev_id):
cur.execute( cur.execute(
sql.SQL( sql.SQL(
"""CREATE TABLE {} ( """CREATE TABLE {} (
utc NUMERIC(10) NOT NULL, utc NUMERIC(10) DEFAULT EXTRACT(EPOCH FROM now())::int NOT NULL,
timedate VARCHAR(100) NOT NULL, timedate VARCHAR(100) NOT NULL,
data json NOT NULL data json NOT NULL
)""" )"""
......
...@@ -223,4 +223,4 @@ ...@@ -223,4 +223,4 @@
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<!-- Navbar --> <!-- Navbar -->
<nav class="navbar navbar-top navbar-horizontal navbar-expand-md navbar-dark"> <nav class="navbar navbar-top navbar-horizontal navbar-expand-md navbar-dark">
<div class="container px-4"> <div class="container px-4">
<a class="navbar-brand" href="../index.html"> <a class="navbar-brand" href="../">
<img src="{{ url_for('static', filename='assets/img/brand/white.png') }}" /> <img src="{{ url_for('static', filename='assets/img/brand/white.png') }}" />
</a> </a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse-main" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse-main" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
...@@ -34,12 +34,14 @@ ...@@ -34,12 +34,14 @@
</div> </div>
<!-- Navbar items --> <!-- Navbar items -->
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ml-auto">
{% if users_signup %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link nav-link-icon" href="/signup"> <a class="nav-link nav-link-icon" href="/register">
<i class="ni ni-circle-08"></i> <i class="ni ni-circle-08"></i>
<span class="nav-link-inner--text">Register</span> <span class="nav-link-inner--text">Register</span>
</a> </a>
</li> </li>
{% endif %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link nav-link-icon" href="/login"> <a class="nav-link nav-link-icon" href="/login">
<i class="ni ni-key-25"></i> <i class="ni ni-key-25"></i>
...@@ -111,8 +113,10 @@ ...@@ -111,8 +113,10 @@
<a href="#" class="text-light"><small>Forgot password?</small></a> <a href="#" class="text-light"><small>Forgot password?</small></a>
</div> </div>
<div class="col-6 text-right"> <div class="col-6 text-right">
{% if users_signup %}
<a href="/register" class="text-light"><small>Create new account</small></a> <a href="/register" class="text-light"><small>Create new account</small></a>
</div> {% endif %}
</div>
</div> </div>
</div> </div>
</div> </div>
......
{% extends 'general_layout.html' %}
{% block title %} HPC&amp;A IoT - Register {% endblock %}
{% block content %}
<body class="bg-default">
<div class="main-content">
<!-- Navbar -->
<nav class="navbar navbar-top navbar-horizontal navbar-expand-md navbar-dark">
<div class="container px-4">
<a class="navbar-brand" href="../">
<img src="{{ url_for('static', filename='assets/img/brand/white.png') }}" />
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse-main" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar-collapse-main">
<!-- Collapse header -->
<div class="navbar-collapse-header d-md-none">
<div class="row">
<div class="col-6 collapse-brand">
<a href="../">
<img src="{{ url_for('static', filename='assets/img/brand/blue.png') }}" />
</a>
</div>
<div class="col-6 collapse-close">
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar-collapse-main" aria-controls="sidenav-main" aria-expanded="false" aria-label="Toggle sidenav">
<span></span>
<span></span>
</button>
</div>
</div>
</div>
<!-- Navbar items -->
<ul class="navbar-nav ml-auto">
{% if users_signup %}
<li class="nav-item">
<a class="nav-link nav-link-icon" href="/register">
<i class="ni ni-circle-08"></i>
<span class="nav-link-inner--text">Register</span>
</a>
</li>
{% endif %}
<li class="nav-item">
<a class="nav-link nav-link-icon" href="/login">
<i class="ni ni-key-25"></i>
<span class="nav-link-inner--text">Login</span>
</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Header -->
<div class="header bg-gradient-primary py-7 py-lg-8">
<div class="container">
<div class="header-body text-center mb-7">
<div class="row justify-content-center">
<div class="col-lg-5 col-md-6">
<h1 class="text-white">Welcome!</h1>
<p class="text-lead text-light">Use these awesome forms to login or create new account in your project for free.</p>
</div>
</div>
</div>
</div>
<div class="separator separator-bottom separator-skew zindex-100">
<svg x="0" y="0" viewBox="0 0 2560 100" preserveAspectRatio="none" version="1.1" xmlns="http://www.w3.org/2000/svg">
<polygon class="fill-default" points="2560 0 2560 100 0 100"></polygon>
</svg>
</div>
</div>
<!-- Page content -->
<div class="container mt--8 pb-5">
<!-- Table -->
<div class="row justify-content-center">
<div class="col-lg-6 col-md-8">
<div class="card bg-secondary shadow border-0">
<div class="card-body px-lg-5 py-lg-5">
<div class="text-center text-muted mb-4">
<small>Sign up with credentials</small>
</div>
<form role="form" action="register" method="post">
<div class="form-group">
<div class="input-group input-group-alternative mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-single-02"></i></span>
</div>
<input class="form-control" maxlength="30" placeholder="Username" type="text" id="username" name="username">
</div>
</div>
<div class="form-group">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>
</div>
<input class="form-control" placeholder="Password" type="password" minlength="8" id="password" name="password" onkeyup="return validate_password();">
</div>
</div>
<div class="form-group">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>
</div>
<input class="form-control" placeholder="Repeat password" type="password" minlength="8" id="rpassword" name="rpassword" onkeyup="return validate_password();">
</div>
</div>
<div class="text-muted font-italic"><small>Required password strength: <span class="text-success font-weight-700">At least 8 characters.</span></small></div>
<div class="text-muted font-italic"><small id="passvalidation"></small></div>
<div class="text-center">
<button type="sumbit" id="submit" class="btn btn-primary mt-4">Create account</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var password = document.getElementById("password");
var rpassword = document.getElementById("rpassword");
$("#submit").prop("disabled", true);
function validate_password() {
if (password.value != rpassword.value) {
$("#passvalidation").html("<span class='text-danger font-weight-700'>Passwords do not match.</span>");
$("#submit").prop("disabled", true);
} else {
$("#passvalidation").html("<span class='text-success font-weight-700'>Passwords match.</span>");
$("#submit").prop("disabled", false);
}
}
</script>
{% endblock %}
...@@ -40,18 +40,18 @@ def index(): ...@@ -40,18 +40,18 @@ def index():
@app.route('/signup', methods=['GET', 'POST']) @app.route('/register', methods=['GET', 'POST'])
def signup(): def signup():
if request.method == 'GET': if request.method == 'GET':
if session['role'] and session['role'] == 'admin': if 'role' in session and session['role'] == 'admin':
return render_template('old/admin/signup.html', users_signup=app.config['USERS_SIGNUP']) return render_template('old/admin/signup.html', users_signup=app.config['USERS_SIGNUP'])
else: else:
if app.config['USERS_SIGNUP']: if app.config['USERS_SIGNUP']:
return render_template('old/public/signup.html', users_signup=app.config['USERS_SIGNUP']) return render_template('new/public/register.html', users_signup=app.config['USERS_SIGNUP'])
else: else:
return redirect(url_for('index', users_signup=app.config['USERS_SIGNUP'])) 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 ('role' in session and session['role'] == 'admin'):
username = request.form['username'] username = request.form['username']
password = request.form['password'].encode('utf-8') password = request.form['password'].encode('utf-8')
...@@ -63,7 +63,7 @@ def signup(): ...@@ -63,7 +63,7 @@ def signup():
return redirect(request.url, users_signup=app.config['USERS_SIGNUP']) 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 'role' in request.form and request.form['role'] == 'administrator':
role = 'admin' role = 'admin'
res = ud.create(username, password, role) res = ud.create(username, password, role)
...@@ -75,7 +75,7 @@ def signup(): ...@@ -75,7 +75,7 @@ def signup():
flash('User successfully created.', 'success') flash('User successfully created.', 'success')
if session['role'] and session['role'] == 'admin': if 'role' in session and session['role'] == 'admin':
return redirect(url_for('dashboard')) return redirect(url_for('dashboard'))
else: else:
return redirect(url_for('index')) return redirect(url_for('index'))
...@@ -86,7 +86,7 @@ def signup(): ...@@ -86,7 +86,7 @@ def signup():
@app.route('/login', methods=['GET', 'POST']) @app.route('/login', methods=['GET', 'POST'])
def login(): def login():
if request.method == 'GET': if request.method == 'GET':
return render_template('old/public/login.html') return render_template('new/public/login.html')
else: else:
username = request.form['username'] username = request.form['username']
password = request.form['password'].encode('utf-8') password = request.form['password'].encode('utf-8')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment