fixes for bugs discovered in meeting

This commit is contained in:
msinkec 2021-09-21 17:34:35 +02:00
parent d60ef26741
commit 965ddee7a7
8 changed files with 87 additions and 24 deletions

31
app.py
View File

@ -199,7 +199,7 @@ def solar_login_post():
password = request.form.get('password')
remember = True if request.form.get('remember') else False
user = RegisteredUser.query.filter_by(email=email).first()
user = portal.base.get_user_obj_by_email(email)
if not user or not check_password_hash(user.pass_hash, password):
flash('Napačni podatki za prijavo. Poskusite ponovno.')
@ -250,6 +250,9 @@ def solar_register_post():
if not password:
flash('Prazno polje za geslo.')
return redirect('/solar/register')
if len(password) > 8:
flash('Geslo mora biti vsaj 8 znakov dolgo.')
return redirect('/solar/register')
if len(password) > 100:
flash('Predolgo geslo.')
return redirect('/solar/register')
@ -621,6 +624,32 @@ def del_cooperation_history_item():
flash('Vnos odstranjen.')
return redirect(redirect_url())
@app.route('/solar/changeinstitutiondata', methods=['POST'])
@login_required
def change_institution_data():
if not portal.base.is_admin(current_user.id):
return '', 404
institution_id = request.form.get('id')
new_name = request.form.get('name')
new_region = request.form.get('region')
if not new_name:
flash('Prazno polje za naziv.')
return redirect(redirect_url())
if len(new_name) > 100:
flash('Predolgo ime.')
return redirect(redirect_url())
if not new_region in portal.solar.VALID_REGIONS:
flash('Neveljavna vrednost za regijo.')
return redirect(redirect_url())
portal.base.update_institution_data(institution_id, new_name, new_region)
flash('Podatki institucije so bili spremenjeni.')
return redirect(redirect_url())
@app.route('/solar/changeuseremail', methods=['POST'])
@login_required
def change_user_email():

View File

@ -18,8 +18,8 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('institution', sa.Column('is_removed', sa.Boolean(), server_default='true', nullable=False))
op.add_column('registered_user', sa.Column('is_removed', sa.Boolean(), server_default='true', nullable=False))
op.add_column('institution', sa.Column('is_removed', sa.Boolean(), server_default='false', nullable=False))
op.add_column('registered_user', sa.Column('is_removed', sa.Boolean(), server_default='false', nullable=False))
# ### end Alembic commands ###

View File

@ -405,22 +405,30 @@ def update_user_name(user_id, new_name):
db.session.commit()
return rowcount
def update_institution_data(institution_id, new_name, new_region):
rowcount = db.session.query(Institution).filter_by(id=institution_id).update({'name': new_name, 'region': new_region})
db.session.commit()
return rowcount
def remove_user(user_id):
#db.session.query(UserCooperationHistory).filter(UserCooperationHistory.user == user_id).delete()
#db.session.query(UserInstitutionMapping).filter(UserInstitutionMapping.user == user_id).delete()
#db.session.query(RegisteredUser).filter(RegisteredUser.id == user_id).delete()
db.session.query(UserCooperationHistory).filter(UserCooperationHistory.user == user_id).delete()
db.session.query(UserInstitutionMapping).filter(UserInstitutionMapping.user == user_id).delete()
db.session.query(RegisteredUser).filter(RegisteredUser.id == user_id).delete()
db.session.commit()
#db.session.query(RegisteredUser).filter(RegisteredUser.id == user_id).update({'is_removed': True})
#db.session.commit()
db.session.query(RegisteredUser).filter(RegisteredUser.id == user_id).update({'is_removed': True})
db.session.commit()
def undo_remove_user(user_id):
db.session.query(RegisteredUser).filter(RegisteredUser.id == user_id).update({'is_removed': False})
db.session.commit()
#def undo_remove_user(user_id):
# db.session.query(RegisteredUser).filter(RegisteredUser.id == user_id).update({'is_removed': False})
# db.session.commit()
def remove_institution(institution_id):
db.session.query(Institution).filter(Institution.id == institution_id).update({'is_removed': True})
db.session.query(CorpusAccess).filter(CorpusAccess.institution == institution_id).delete()
db.session.query(Institution).filter(Institution.id == institution_id).delete()
db.session.commit()
#db.session.query(Institution).filter(Institution.id == institution_id).update({'is_removed': True})
#db.session.commit()
def del_user_from_institution(user_id, institution_id):
@ -429,22 +437,22 @@ def del_user_from_institution(user_id, institution_id):
def get_all_active_users():
return RegisteredUser.query.filter_by(is_removed=False).filter_by(active=True).order_by(RegisteredUser.id).all()
return RegisteredUser.query.filter_by(active=True).order_by(RegisteredUser.id).all()
def get_all_inactive_users():
return RegisteredUser.query.filter_by(is_removed=False).filter_by(active=False).order_by(RegisteredUser.id).all()
return RegisteredUser.query.filter_by(active=False).order_by(RegisteredUser.id).all()
def get_all_users_join_institutions(active=True):
#return RegisteredUser.query.filter_by(active=True).order_by(RegisteredUser.id).all()
return db.session.query(RegisteredUser, UserInstitutionMapping).filter(RegisteredUser.is_removed==False).outerjoin(UserInstitutionMapping,
return db.session.query(RegisteredUser, UserInstitutionMapping).outerjoin(UserInstitutionMapping,
RegisteredUser.id == UserInstitutionMapping.user).filter(RegisteredUser.active == active).order_by(RegisteredUser.id).all()
def get_all_active_institution_users(institution_id):
return RegisteredUser.query.filter_by(is_removed=False).filter_by(active=True).join(UserInstitutionMapping,
return RegisteredUser.query.filter_by(active=True).join(UserInstitutionMapping,
RegisteredUser.id == UserInstitutionMapping.user).filter(UserInstitutionMapping.institution == institution_id).all()
@ -552,12 +560,6 @@ def send_admins_new_user_notification_mail(user_id, config):
Nov uporabnik "{}" je ustvaril uporabniški račun na portalu za oddajanje besedil Šolar in čaka na odobritev.
'''.format(user.name)
message = MIMEMultipart()
message['From'] = config['MAIL_LOGIN']
message['To'] = email
message['Subject'] = 'Ponastavitev gesla'
message.attach(MIMEText(body, "plain"))
text = message.as_string()
admins = RegisteredUser.query.filter_by(role="admin").all()
@ -565,6 +567,12 @@ def send_admins_new_user_notification_mail(user_id, config):
context = ssl.create_default_context()
for admin in admins:
message = MIMEMultipart()
message['From'] = config['MAIL_LOGIN']
message['To'] = admin.email
message['Subject'] = 'Nova registracija'
message.attach(MIMEText(body, "plain"))
text = message.as_string()
try:
with SMTP_SSL(config['MAIL_HOST'], config['SMTP_PORT'], context=context) as server:
server.login(config['MAIL_LOGIN'], config['MAIL_PASS'])
@ -579,7 +587,7 @@ def send_user_activation_mail(user_id, config):
message = MIMEMultipart()
message['From'] = config['MAIL_LOGIN']
message['To'] = email
message['To'] = user.email
message['Subject'] = 'Ponastavitev gesla'
message.attach(MIMEText(body, "plain"))
text = message.as_string()

View File

@ -30,6 +30,7 @@
</style>
</head>
<body>
<a href="/solar/oddaja">Nazaj na oddajo</a>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div style="background: blue;">
@ -206,6 +207,28 @@
<input type="text" id="id-to" name="id-to"><br>
<input type="submit" value="Združi">
</form>
<h3>Spremeni podatke institucije</h3>
<form action="/solar/changeinstitutiondata" method="post">
<label for="id">ID institucije</label>
<input type="text" id="id" name="id"><br>
<label for="name">Nov naziv:</label>
<input type="text" id="name" name="name"><br>
<label for="region">Nova regija:</label>
<select name="region" id="region">
<option value="CE">Celje</option>
<option value="GO">Nova Gorica</option>
<option value="KK">Krško</option>
<option value="KP">Koper</option>
<option value="KR">Kranj</option>
<option value="LJ">Ljubljana</option>
<option value="MB">Maribor</option>
<option value="MS">Murska Sobota</option>
<option value="NM">Novo mesto</option>
<option value="PO">Postojna</option>
<option value="SG">Slovenj Gradec</option>
</select>
<input type="submit" value="Spremeni">
</form>
<h2>Zgodovina sodelovanja</h2>
<div class="tableFixHead">
<table>

View File

@ -12,6 +12,7 @@
<div id="logo-container">
<img src="/static/image/logo.svg" alt="logo"/>
</div>
<a href="/solar/login" class="contract-item-button" style="float: none;">Nazaj na prijavo</a>
<h3 id="title" style="font-size: 27px; text-align: left;">Pozabljeno geslo - ŠOLAR</h3>
<div>
{% with messages = get_flashed_messages() %}

View File

@ -30,6 +30,7 @@
</style>
</head>
<body>
<a href="/solar/oddaja">Nazaj na oddajo</a>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div style="background: blue;">

View File

@ -12,8 +12,8 @@
left: 385px;
background: linear-gradient(198.62deg, rgba(255, 255, 255, 0.49) -1.62%, rgba(255, 255, 255, 0.73) -1.61%, rgba(255, 255, 255, 0.41) 79.34%);
box-shadow: 20px 4px 40px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(20px);
border: 0px;
backdrop-filter: blur(20px);
border-radius: 0px 20px 20px 0px;') }}
<link rel="stylesheet" href="/static/style.css" type="text/css">
</head>

View File

@ -17,6 +17,7 @@
<div class="form-text"><em>Zbiranje besedil za korpus Šolar poteka po naslednjem postopku, ki prinaša tudi točke za napredovanje.</em></div>
<a href="/solar/login" class="contract-item-button" style="float: none;">Nazaj na prijavo</a>
<h3 id="title" style="font-size: 27px; text-align: left;">Registracija</h3>
<div>
{% with messages = get_flashed_messages() %}