Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…_TeamC_Assignment into feature/account-management
  • Loading branch information
HanisahMusrin committed Jan 25, 2024
2 parents 1cd2f9f + 2954afb commit d2cfcce
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion website/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def load_user(id):
#create admin account
with app.app_context():
if db.session.query(User).filter_by(username='Admin').count() < 1:
admin = User(username='Admin', password=generate_password_hash('password', method='pbkdf2'), isAdmin = 1)
admin = User(username="Admin", password=generate_password_hash('password', method='pbkdf2') , role='Admin')
db.session.add(admin)
db.session.commit()

Expand Down
6 changes: 3 additions & 3 deletions website/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def logout():
flash('Logged out successfully!',category='success')
return redirect('/')

@auth.route('/create-account',methods=['GET','POST'])
@auth.route('/register',methods=['GET','POST'])
def createAccount():
if request.method == "POST":
username = request.form.get('username')
Expand All @@ -48,7 +48,7 @@ def createAccount():
flash('Password must be greater than 7 characters.',category='error')
else:
new_user = User(username=username, password=generate_password_hash(
password, method='pbkdf2'))
password, method='pbkdf2'),role='user')
db.session.add(new_user)
db.session.commit()
login_user(new_user, remember=True)
Expand All @@ -57,7 +57,7 @@ def createAccount():

return redirect(url_for('auth.welcome'))

return render_template("create-account.html",user=current_user)
return render_template("register.html",user=current_user)

@auth.route('/welcome')
@login_required
Expand Down
17 changes: 12 additions & 5 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
from flask_login import UserMixin
from sqlalchemy.sql import func

#All User data have to have these attributes
class User(db.Model, UserMixin):
id = db.Column(db.Integer,primary_key=True)
username = db.Column(db.String(150),unique=True)
password = db.Column(db.String(150))
isAdmin = db.Column(db.Boolean,default=False)
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(50), nullable=False)
password = db.Column(db.String(50), nullable=False)
failed_login_attempts = db.Column(db.Integer, default=0)
role = db.Column(db.String(50), nullable=False)
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
approved_by = db.Column(db.String(50), nullable=True)
date_approved = db.Column(db.DateTime, nullable=True)


def __repr__(self):
return f'<User {self.username}>'
Empty file removed website/static/index.js
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion website/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ <h1 style="text-align: center;"}><u>Login</u></h1>
</div>
<br/><br/>
<button type="submit" class="btn btn-primary btn-success btn-lg" style="width: 200px"> Login</button>
<a type="submit" class="btn btn-primary btn-success btn-lg" style="float: right; width:200px" href="/create-account"> Create New User </a>
<a type="submit" class="btn btn-primary btn-success btn-lg" style="float: right; width:200px" href="/register"> Create New User </a>
</form>
{% endblock %}
File renamed without changes.
File renamed without changes.
17 changes: 9 additions & 8 deletions website/templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@
{% block title %}Welcome{% endblock %}

{% block nav %}
<div class="navbar-nav ml-auto" style="margin-right: 100px;">
<div class="navbar-nav ml-auto" style="margin-right: 100px; margin-bottom: 50px;">
<a class="btn btn-primary btn-danger btn-lg" style="width: 120px" id="logout" href="/logout">Logout</a>
</div>
{% endblock %}

{% block content %}
<br/><br/><br/><br/><br/>
{% if current_user.isAdmin==False %}
<h1 class="text-center fw-bold" style="font-size: 60px;">Hi {{current_user.username}}.</h1>
<h1 class="text-center fw-bold" style="font-size: 60px;">Welcome to the TSAO Capstone Records System</h1>
<br/><br/><br/>

{% if current_user.role!='Admin' %}
<div style="margin-bottom: 30px;">
<h1 class="text-center fw-bold" style="font-size: 60px;">Hi {{current_user.username}}.</h1>
<h1 class="text-center fw-bold" style="font-size: 60px;">Welcome to the TSAO Capstone Records System</h1>
<br/><br/><br/>
</div>
<div class="d-flex justify-content-center">
<a type="submit" class="btn btn-primary btn-success btn-lg mr-5" style="width:200px" href=""> Create </a>
<a type="submit" class="btn btn-primary btn-success btn-lg invisible" style="width:200px" href=""> Modify Accounts </a>
<a type="submit" class="btn btn-primary btn-success btn-lg ml-5" style="width:200px" href=""> Query </a>
</div>
{% else %}
<div style="margin-bottom: 30px;">
<h1 class="text-center fw-bold" style="font-size: 60px;">Hi Administrator.</h1>
<h1 class="text-center fw-bold" style="font-size: 60px;">Welcome to the TSAO Capstone Records System</h1>
<br/><br/><br/>
</div>

<div class="d-flex justify-content-center">
<a type="submit" class="btn btn-primary btn-success btn-lg mr-5" style="width:200px" href="/form"> Create </a>
Expand Down
1 change: 1 addition & 0 deletions website/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Blueprint, render_template
from os import path
from flask_login import login_required,current_user

views = Blueprint('views', __name__)
Expand Down

0 comments on commit d2cfcce

Please sign in to comment.