forked from crunk/distribusi-verse
crunk
3 years ago
9 changed files with 130 additions and 34 deletions
@ -0,0 +1,20 @@ |
|||||
|
from app import db |
||||
|
|
||||
|
|
||||
|
class Distribusis(db.Model): |
||||
|
"""distribusi model class for a single distribusi in distribusi-verse""" |
||||
|
|
||||
|
__tablename__ = "distribusis" |
||||
|
|
||||
|
id = db.Column(db.Integer, primary_key=True) |
||||
|
distribusiname = db.Column(db.String(300), nullable=True, unique=True) |
||||
|
userid = db.Column(db.Integer, db.ForeignKey("users.id")) |
||||
|
term = db.Column(db.Integer, nullable=False, unique=False) |
||||
|
|
||||
|
# Academic year eg:2020-2021, so no need for a Datetime object |
||||
|
year = db.Column(db.String(9), nullable=True, unique=False) |
||||
|
tags = db.Column(db.String(500), nullable=True, unique=False) |
||||
|
visible = db.Column(db.Boolean, server_default="false") |
||||
|
|
||||
|
def __repr__(self): |
||||
|
return "<Distribusi %r>" % self.distribusiname |
@ -0,0 +1,24 @@ |
|||||
|
import os |
||||
|
from flask_login import current_user |
||||
|
from usermodel import User |
||||
|
from forms.loginform import LoginForm |
||||
|
|
||||
|
|
||||
|
def LoginUser(): |
||||
|
loginform = LoginForm() |
||||
|
if loginform.validate_on_submit(): |
||||
|
try: |
||||
|
user = User.query.filter_by(email=loginform.email.data).first() |
||||
|
if user is None: |
||||
|
loginform.password.errors.append("Invalid email or password!") |
||||
|
return render_template("login.html", loginform=loginform) |
||||
|
if check_password_hash(user.password, loginform.password.data): |
||||
|
login_user(user) |
||||
|
flash("Logged in successfully.", "success") |
||||
|
else: |
||||
|
flash("Invalid email or password!", "danger") |
||||
|
loginform.password.errors.append("Invalid email or password!") |
||||
|
return loginform |
||||
|
except Exception as e: |
||||
|
flash(e, "danger") |
||||
|
return loginform |
Loading…
Reference in new issue