def profile_register(): if request.method == 'POST': if request.form['email'] and \ request.form['password'] and \ request.form['password2']: if len(request.form['email']) < 3: flash(gettext("Email address is too short"), 'error') valid = False else: valid = checkPassword(request.form['password'], request.form['password2']) else: valid = False flash(gettext("Please fill out all the fields!"), 'error') if valid: newUser = WishUser(request.form['email'], request.form['name']) newUser.setPassword(request.form['password']) if request.form['email'] == app.config['ROOTUSER']: log.info("[System] Registred root user: %s" % request.form['email']) newUser.admin = True newUser.locked = False newUser.veryfied = True db_session.add(newUser) try: runQuery(db_session.commit) actUrl = url_for('profile_verify', userId=newUser.id, verifyKey=newUser.verifyKey, _external=True) if send_email(app, newUser.email, gettext("%(sitetitle)s: Activation Email", sitetitle=app.config['SITETITLE']), "<h3>%s %s</h3>" % (gettext("Hello"), request.form['name']) + gettext("We are happy to welcome you to " "%(sitetitle)s!<br>Please verify your " "account with <a href='%(url)s'>this " "link</a>.<br><br>", sitetitle=app.config['SITETITLE'], url=actUrl) + gettext("<br><br>Have fun and see you soon ;)"), app.config['EMAILBANNERWELCOME']): flash(gettext("Please check your mails at %(emailaddr)s", emailaddr=newUser.email), 'info') else: flash(gettext("Error sending the email to you."), 'error') return redirect(url_for('profile_login')) except Exception as e: flash("%s: %s" % (gettext("SQL Alchemy Error"), e), 'error') log.warning("[System] SQL Alchemy Error: %s" % e) # db_session.expire(newUser) return render_template('profile_register.html', values=request.form)
def admin_exclusion_add(): check_admin_permissions() if request.form['userIdA'] != request.form['userIdB']: newExclusion = Exclusion(request.form['userIdA'], request.form['userIdB']) db_session.add(newExclusion) try: runQuery(db_session.commit) except Exception as e: log.warning("[Exclusion] SQL Alchemy Error on enter wish: %s" % (e)) flash(gettext("The exclusion could not be saved"), 'error') else: flash(gettext("Unable to add this exclude"), 'error') return redirect(url_for('admin_secretsanta_management'))
def enter_wish(): if not session.get('logged_in'): return redirect(url_for('index')) if request.method == 'POST': newWish = Wish(session.get('userid'), request.form['userid'], request.form['text']) db_session.add(newWish) try: runQuery(db_session.commit) except Exception as e: log.warning("[Wish] SQL Alchemy Error on enter wish" ": %s" % (e)) flash(gettext("The wish could not be saved"), 'error') return render_template('enter_wish.html')
def admin_secretsanta_go(): message = [] solver = SecretSantaSolver(runQuery(WishUser.query.all), runQuery(Exclusion.query.all)) ret = solver.run() if ret: message.append("Calculations done in %s loops:" % (solver.loops)) for (donator, reciever) in ret: db_session.add(History(donator.id, reciever.id)) if send_email(app, donator.email, gettext("%(sitetitle)s: Secret Santa %(year)s", sitetitle=app.config['SITETITLE'], year=time.strftime('%Y')), gettext("<h3>Hello %(donator)s</h3>" "You are the Secret Santa to: %(reciever)s" "<br>You can login here: " "<a href='%(loginurl)s'>%(exturl)s</a>" "<br>Please do not reply to this email!<br>", donator=donator.name, reciever=reciever.name, loginurl=url_for('profile_login', _external=True), exturl=url_for('index', _external=True)) + gettext("<br><br>Have fun and see you soon ;)"), app.config['EMAILBANNER']): message.append("Email to %s sent" % donator.email) else: message.append("Unable to send email to %s" % donator.email) try: runQuery(db_session.commit) except Exception as e: log.warning("[History] SQL Alchemy Error on history: %s" % (e)) else: flash(gettext("Calculation not ok"), 'error') return render_template('admin_secretsanta_management.html', message='\n'.join(message), exclusions=runQuery(Exclusion.query.all), users=runQuery(WishUser.query.all))