login improvements

This commit is contained in:
2025-05-26 21:50:49 +02:00
parent 029815c218
commit a198fa3e0e
5 changed files with 67 additions and 16 deletions

View File

@@ -20,6 +20,9 @@ def init_routes(auth_bp):
return redirect(url_for('auth.login')) return redirect(url_for('auth.login'))
login_user(user, remember=remember) login_user(user, remember=remember)
next_page = request.args.get('next')
if next_page:
return redirect(next_page)
return redirect(url_for('main.dashboard')) return redirect(url_for('main.dashboard'))
return render_template('auth/login.html') return render_template('auth/login.html')
@@ -50,8 +53,8 @@ def init_routes(auth_bp):
db.session.add(new_user) db.session.add(new_user)
db.session.commit() db.session.commit()
flash('Registration successful! Please login.', 'success') login_user(new_user)
return redirect(url_for('auth.login')) return redirect(url_for('main.dashboard'))
return render_template('auth/register.html') return render_template('auth/register.html')
@@ -59,4 +62,4 @@ def init_routes(auth_bp):
@login_required @login_required
def logout(): def logout():
logout_user() logout_user()
return redirect(url_for('main.home')) return redirect(url_for('auth.login'))

View File

@@ -27,9 +27,9 @@ def init_routes(main_bp):
@main_bp.route('/') @main_bp.route('/')
def home(): def home():
if current_user.is_authenticated: if not current_user.is_authenticated:
return redirect(url_for('auth.login'))
return redirect(url_for('main.dashboard')) return redirect(url_for('main.dashboard'))
return render_template('home.html')
@main_bp.route('/dashboard') @main_bp.route('/dashboard')
@login_required @login_required

View File

@@ -7,13 +7,53 @@
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<link rel="stylesheet" href="{{ url_for('static', filename='css/auth.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/auth.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/colors.css') }}">
<link rel="stylesheet" href="{{ url_for('main.dynamic_colors') }}">
<style>
body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg,
var(--primary-opacity-15) 0%,
var(--bg-color) 25%,
var(--bg-color) 75%,
var(--primary-opacity-15) 100%);
position: relative;
overflow: hidden;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: radial-gradient(circle at 50% 50%,
var(--primary-opacity-8) 0%,
transparent 50%);
z-index: -1;
}
.auth-container {
width: 100%;
max-width: 400px;
margin: 0 auto;
}
.auth-card {
backdrop-filter: blur(10px);
background-color: var(--white);
box-shadow: 0 8px 32px var(--shadow-color);
border: 1px solid var(--border-light);
}
</style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<div class="auth-container"> <div class="auth-container">
<div class="card auth-card"> <div class="card auth-card">
<div class="auth-header text-center"> <div class="auth-header text-center">
<h2>Welcome Back</h2> <h2><i class="fas fa-lock me-2"></i>Welcome Back</h2>
<p class="mb-0">Sign in to your account</p> <p class="mb-0">Sign in to your account</p>
</div> </div>
<div class="card-body p-4"> <div class="card-body p-4">
@@ -21,7 +61,10 @@
{% if messages %} {% if messages %}
{% for category, message in messages %} {% for category, message in messages %}
{% if category in ['error', 'danger', 'login'] %} {% if category in ['error', 'danger', 'login'] %}
<div class="alert alert-{{ 'danger' if category in ['error', 'danger'] else 'info' }}">{{ message }}</div> <div class="alert alert-{{ 'danger' if category in ['error', 'danger'] else 'info' }}"
style="background-color: var(--danger-opacity-15); color: var(--danger-color); border: none;">
<i class="fas fa-exclamation-circle me-2"></i>{{ message }}
</div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
@@ -30,23 +73,28 @@
<form method="POST" action="{{ url_for('auth.login') }}"> <form method="POST" action="{{ url_for('auth.login') }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}"> <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<div class="mb-3"> <div class="mb-3">
<label for="email" class="form-label">Email address</label> <label for="email" class="form-label">
<i class="fas fa-envelope me-2" style="color: var(--primary-color);"></i>Email address
</label>
<input type="email" class="form-control" id="email" name="email" required> <input type="email" class="form-control" id="email" name="email" required>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="password" class="form-label">Password</label> <label for="password" class="form-label">
<i class="fas fa-key me-2" style="color: var(--primary-color);"></i>Password
</label>
<input type="password" class="form-control" id="password" name="password" required> <input type="password" class="form-control" id="password" name="password" required>
</div> </div>
<div class="mb-3 form-check"> <div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="remember" name="remember"> <input type="checkbox" class="form-check-input" id="remember" name="remember" style="accent-color: var(--primary-color);">
<label class="form-check-label" for="remember">Remember me</label> <label class="form-check-label" for="remember">Remember me</label>
</div> </div>
<button type="submit" class="btn btn-primary w-100">Sign In</button> <button type="submit" class="btn btn-primary w-100"
style="background-color: var(--primary-color); border-color: var(--primary-color);"
onmouseover="this.style.backgroundColor='var(--primary-light)'"
onmouseout="this.style.backgroundColor='var(--primary-color)'">
<i class="fas fa-sign-in-alt me-2"></i>Sign In
</button>
</form> </form>
<div class="text-center mt-3">
<p class="mb-0">Don't have an account? <a href="{{ url_for('auth.register') }}" class="text-decoration-none">Register</a></p>
</div>
</div> </div>
</div> </div>
</div> </div>