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):
cur.execute(
sql.SQL(
"""CREATE TABLE {} (
utc NUMERIC(10) NOT NULL,
utc NUMERIC(10) DEFAULT EXTRACT(EPOCH FROM now())::int NOT NULL,
timedate VARCHAR(100) NOT NULL,
data json NOT NULL
)"""
......
......@@ -223,4 +223,4 @@
</script>
</body>
</html>
\ No newline at end of file
</html>
......@@ -9,7 +9,7 @@
<!-- Navbar -->
<nav class="navbar navbar-top navbar-horizontal navbar-expand-md navbar-dark">
<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') }}" />
</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">
......@@ -34,12 +34,14 @@
</div>
<!-- Navbar items -->
<ul class="navbar-nav ml-auto">
{% if users_signup %}
<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>
<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>
......@@ -111,8 +113,10 @@
<a href="#" class="text-light"><small>Forgot password?</small></a>
</div>
<div class="col-6 text-right">
{% if users_signup %}
<a href="/register" class="text-light"><small>Create new account</small></a>
</div>
{% endif %}
</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():
@app.route('/signup', methods=['GET', 'POST'])
@app.route('/register', methods=['GET', 'POST'])
def signup():
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'])
else:
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:
return redirect(url_for('index', users_signup=app.config['USERS_SIGNUP']))
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']
password = request.form['password'].encode('utf-8')
......@@ -63,7 +63,7 @@ def signup():
return redirect(request.url, users_signup=app.config['USERS_SIGNUP'])
else:
role = 'user'
if request.form['role'] and request.form['role'] == 'administrator':
if 'role' in request.form and request.form['role'] == 'administrator':
role = 'admin'
res = ud.create(username, password, role)
......@@ -75,7 +75,7 @@ def signup():
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'))
else:
return redirect(url_for('index'))
......@@ -86,7 +86,7 @@ def signup():
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return render_template('old/public/login.html')
return render_template('new/public/login.html')
else:
username = request.form['username']
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