From 965ddee7a7e7c9ea3bef39656d07611fbe7249a9 Mon Sep 17 00:00:00 2001 From: msinkec Date: Tue, 21 Sep 2021 17:34:35 +0200 Subject: [PATCH] fixes for bugs discovered in meeting --- app.py | 31 +++++++++++- ...5_added_is_removed_column_to_users_and_.py | 4 +- portal/base.py | 48 +++++++++++-------- templates/solar-admin.html | 23 +++++++++ templates/solar-forgotpass.html | 1 + templates/solar-manage-institution.html | 1 + templates/solar-oddaja.html | 2 +- templates/solar-register.html | 1 + 8 files changed, 87 insertions(+), 24 deletions(-) diff --git a/app.py b/app.py index 136d603..281b347 100644 --- a/app.py +++ b/app.py @@ -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(): diff --git a/migrations/versions/84168f439c55_added_is_removed_column_to_users_and_.py b/migrations/versions/84168f439c55_added_is_removed_column_to_users_and_.py index 31eb8fb..05bb1be 100644 --- a/migrations/versions/84168f439c55_added_is_removed_column_to_users_and_.py +++ b/migrations/versions/84168f439c55_added_is_removed_column_to_users_and_.py @@ -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 ### diff --git a/portal/base.py b/portal/base.py index 4a0fd18..5470117 100644 --- a/portal/base.py +++ b/portal/base.py @@ -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() diff --git a/templates/solar-admin.html b/templates/solar-admin.html index eb89e58..d881cc8 100644 --- a/templates/solar-admin.html +++ b/templates/solar-admin.html @@ -30,6 +30,7 @@ + Nazaj na oddajo {% with messages = get_flashed_messages() %} {% if messages %}
@@ -206,6 +207,28 @@
+

Spremeni podatke institucije

+
+ +
+ +
+ + + +

Zgodovina sodelovanja

diff --git a/templates/solar-forgotpass.html b/templates/solar-forgotpass.html index c9c4222..9df734d 100644 --- a/templates/solar-forgotpass.html +++ b/templates/solar-forgotpass.html @@ -12,6 +12,7 @@
logo
+ Nazaj na prijavo

Pozabljeno geslo - ŠOLAR

{% with messages = get_flashed_messages() %} diff --git a/templates/solar-manage-institution.html b/templates/solar-manage-institution.html index 3adfc32..2412928 100644 --- a/templates/solar-manage-institution.html +++ b/templates/solar-manage-institution.html @@ -30,6 +30,7 @@ + Nazaj na oddajo {% with messages = get_flashed_messages() %} {% if messages %}
diff --git a/templates/solar-oddaja.html b/templates/solar-oddaja.html index 43a1c8d..27c90a7 100644 --- a/templates/solar-oddaja.html +++ b/templates/solar-oddaja.html @@ -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;') }} diff --git a/templates/solar-register.html b/templates/solar-register.html index 4c7cf42..4dabb65 100644 --- a/templates/solar-register.html +++ b/templates/solar-register.html @@ -17,6 +17,7 @@
Zbiranje besedil za korpus Šolar poteka po naslednjem postopku, ki prinaša tudi točke za napredovanje.
+ Nazaj na prijavo

Registracija

{% with messages = get_flashed_messages() %}