def new_user(): """ :return: """ if request.method == 'POST': email = request.form['email'] try: if User.new_user_valid(email, request.form['pword'], request.form['confirmpword']): fname = request.form['fname'] lname = request.form['lname'] pword = Utils.hash_password(request.form['pword']) phone = request.form['phone'] location = request.form['location'] if User.check_offline_user_exist(email) is not None: user = User.get_user_by_email(email) user.f_name = fname user.l_name = lname user.password = pword user.admin_created = 'No' user.prognosticator = 'Yes' user.admin = 'No' user.phone = phone user.location = location user.created_on = datetime.datetime.utcnow() user.save_to_mongo() else: user = User(fname, lname, email, pword, phone=phone, location=location, created_on=datetime.datetime.utcnow()) user.save_to_mongo() alerts, attendance = User.user_default_values() for alert in alerts: Alert(user=user._id, alert=alert, yes_no='On').save_to_mongo() for na in attendance: UserGame(user=user.json(), game=Game.get_game_by_num(na, Year.get_current_year()._id)._id, attendance=attendance[na], home_score=0, away_score=0, game_date=0).save_to_mongo() session['user'] = user._id session['useradmin'] = user.admin return redirect(url_for('alerts.manage_alerts')) except UserErrors.UserError as e: return render_template("users/new_user.jinja2", error=e.message) else: return render_template("users/new_user.jinja2")
def user_administration(): if request.method == 'POST': user = User(f_name=request.form['fname'], l_name=request.form['lname'], email=request.form['email'], prognosticator=request.form['prognosticator'], admin_created='Yes' ) alerts, attendance = User.user_default_values() user.insert_new_user() for alert in alerts: new_alert = Alert(user._id, alert, alerts[alert]) new_alert.save_to_mongo() for na in attendance: new_attendance = UserGame(user=user.json(), game=Game.get_game_by_num(na, Year.get_current_year()._id)._id, attendance=attendance[na], home_score=0, away_score=0, game_date=0) new_attendance.save_to_mongo() users = User.get_all_users() return render_template('users/admin_dashboard.jinja2', users=users)