Exemple #1
0
def admin():
    form=AdminForm(request.form)
    users=User.query.all()
    choices=[]
    
    if request.method=="GET" or request.method=="POST":
        tags=Tag.query.all()
        for tag in tags:
            choices.append((tag.tagname,tag.tagname))
        form.tags.choices=choices
    
    if form.validate_on_submit()==True:
        
        if form.add_new_admins()==True:
            flash("Users [" + str(form.newadmins.data) + "] added to admins!")
        
        if form.remove_admins()==True:
            flash("Users [" + str(form.oldadmins.data) + "] removed from admins!")
        
        if form.remove_tags()==True:
            flash("Tags [" + str(form.tags.data) + "] removed!")   
        
        #Nollataan kaikki submitin jalkeen:
        form.oldadmins.data=""
        form.newadmins.data=""
        choices=[]
        tags=Tag.query.all()
        for tag in tags:
            choices.append((tag.tagname,tag.tagname))
        form.tags.choices=choices
    
    return render_template('admin_page.html',title="Admin Options",form=form,users=users)
Exemple #2
0
def create_admin_view(corporation_slug_to_id, **kwargs):
    roles = RoleAccess(
        corporation_id=corporation_slug_to_id).roles_available_to_create_admin()

    roles_to_choose = [(i.id, i.name) for i in roles]

    form = AdminForm(roles_to_choose, corporation_slug_to_id)

    next_page = request.args.get('next')

    if request.method == 'POST':
        if form.submit_admin.data and form.validate_on_submit():
            AdminAccess(corporation_id=corporation_slug_to_id,
                        email=form.email_admin.data.strip(),
                        role_id=form.role_admin.data.strip()).create_admin()
            flash('Your admin is now live!')
            if next_page:
                return redirect(next_page)
            form.email_admin.data = ''
            form.role_admin.data = ''

        elif form.cancel_admin.data:
            if next_page:
                return redirect(next_page)
            form.email_admin.data = ''
            form.role_admin.data = ''

    return render_template('create_admin.html', form=form)
Exemple #3
0
def admin_page():
    form = AdminForm()
    if request.method == 'GET':
        with g.db as cur:
            sql = """select user_id,user_name,user_type,id from usertable
        """
            cur.execute(sql)
            user_list = [
                dict(user_id=row[0],
                     user_name=row[1],
                     user_type=row[2],
                     id=row[3]) for row in cur.fetchall()
            ]

        return render_template('modify.html', form=form, user_list=user_list)
    else:

        if form.validate_on_submit():
            with g.db as cur:
                sql = """insert into usertable(user_id,user_name,user_type) values('{0}','{1}','{2}')
            """.format(form.user_id.data, form.user_name.data,
                       form.user_type.data)
                cur.execute(sql)
            flash('You have add a user!')

        else:
            flash(form.errors)
        return redirect(url_for('admin_page'))
Exemple #4
0
def login():
    userf = UserForm()
    admin = AdminForm()

    if userf.validate_on_submit():

        comand = userf.comand_name.data
        username = userf.username.data
        password = userf.password.data
        db_sess = db_session.create_session()
        team = db_sess.query(Teams).filter(Teams.name == comand).filter(
            Teams.name != 'Admins').first()

        if team and check_password_hash(team.password_hash, password):
            users = db_sess.query(
                User.username).filter(User.team == team.name).all()
            users_names = [x[0] for x in users]

            if username in users_names:
                login_user(
                    db_sess.query(User).filter(User.team == team.name).filter(
                        User.username == username).first())
                return redirect("/user")

            else:
                if len(users) < 6:
                    us = User()
                    us.username = username
                    us.team = comand
                    db_sess.add(us)
                    db_sess.commit()
                    login_user(us)
                    return redirect("/user")

                else:
                    return render_template('login.html',
                                           form=userf,
                                           adm_form=admin)
        return render_template('login.html', form=userf, adm_form=admin)

    if admin.validate_on_submit():

        name = admin.ad_username.data
        password = admin.ad_password.data
        db_sess = db_session.create_session()
        admins = db_sess.query(User).filter(User.username == name).filter(
            User.role == 1).first()
        team = db_sess.query(Teams).filter(Teams.name == 'Admins').first()

        if admins and check_password_hash(team.password_hash, password):
            login_user(admins)
            return redirect('/admin')

        else:
            return render_template('login.html', form=userf, adm_form=admin)
    return render_template('login.html',
                           title='Авторизация',
                           form=userf,
                           adm_form=admin)
Exemple #5
0
def admin_login():
    form = AdminForm()
    if form.validate_on_submit():
        admin = Admin.query.filter_by(username=form.username.data).first()
        if admin is None or not admin.password == form.password.data:
            flash("Invalid User name or Password", "error")
            return redirect(url_for('admin_login'))
        return redirect(url_for('admin', name=form.username.data))
    return render_template('admin_login.htm', form=form)
def admin_page():
    if not session.get('admin'):
        form = AdminForm()
        if form.validate_on_submit():
            session['admin'] = True
            return redirect('/admin/control')
        return render_template('form.html', form=form)
    else:
        return redirect(url_for('admin.control'))
Exemple #7
0
def admin():
    form = AdminForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            flash(f'The password is accepted', 'success')
            return render_template('admin.html', title='Admin', form=form), 200
        else:
            flash(f'The password is not accepted', 'danger')
            return render_template('admin.html', title='Admin', form=form), 403

    return render_template('admin.html', title='Admin', form=form), 200
Exemple #8
0
    def index(self):
        spform = SetPhaseForm()
        pnform = PhaseNomForm()
        pvform = PhaseVoteForm()
        psform = PhaseStaticForm()
        bform = BanForm()
        aform = AdminForm()
        nform = NomIDForm()
        cform = ClearForm()

        if ((spform.static.data or spform.nom.data or spform.vote.data) and
                spform.validate_on_submit()):
            self.set_phase(spform)
            return self.check_full_index()
        if ((pnform.pnon.data and pnform.validate_on_submit()) or
                pnform.pnoff.data):
            self.phase_sched(pnform, 1)
            return self.check_full_index()
        if ((pvform.pvon.data and pvform.validate_on_submit()) or
                pvform.pvoff.data):
            self.phase_sched(pvform, 2)
            return self.check_full_index()
        if ((psform.pson.data and psform.validate_on_submit()) or
                psform.psoff.data):
            self.phase_sched(psform, 0)
            return self.check_full_index()
        if (bform.ban.data or bform.unban.data) and bform.validate_on_submit():
            if self.ban(bform):
                return self.check_full_index()
        if (aform.give.data or aform.take.data) and aform.validate_on_submit():
            self.change_admin(aform)
            return self.check_full_index()
        if ((nform.rem.data or nform.rwarn.data or nform.rban.data) and
                nform.validate_on_submit()):
            self.remove_nom(nform.nomid.data, nform.rwarn.data, nform.rban.data)
            return self.check_full_index()
        if ((cform.cnoms.data or cform.cvotes.data) and
                cform.validate_on_submit()):
            self.clear(cform)
            return self.check_full_index()

        full = self.get_full()
        s = State.query.first()
        if s.dtnom is not None:
            pnform.dtnom.data = s.dtnom
        if s.dtvote is not None:
            pvform.dtvote.data = s.dtvote
        if s.dtstatic is not None:
            psform.dtstatic.data = s.dtstatic

        return self.render("admin/index.html", spform=spform, pnform=pnform,
            pvform=pvform, psform=psform, aform=aform, bform=bform, nform=nform,
            cform=cform, awards=list_awards(), full=full, phase=phase())
Exemple #9
0
def admin_login():
	form = AdminForm()
	if request.method == 'POST':
		if form.validate_on_submit():
			user = Admin.query.filter_by(username=request.form['username']).first()
			if user:
				if check_password_hash(user.password, request.form['password']):
					login_user(user)
					session['admin'] = True
					flash('Welcome Admin')
					return redirect(url_for('index'))
				else:
					flash('Username or Password Invalid')
			else:
				flash('Username or Password Invalid')
	return render_template('admin-login.html', form=form)
Exemple #10
0
def admin_add():
    form = AdminForm()
    if form.validate_on_submit():
        data = form.data
        admin_num = Admin.query.filter_by(name=data['name']).count()
        if admin_num == 1:
            flash("管理员名称已经存在!", "err")
            return redirect(url_for("admin.admin_add"))
        from werkzeug.security import generate_password_hash
        admin = Admin(name=data['name'],
                      pwd=generate_password_hash(data['pwd']),
                      role_id=data['role'])
        db.session.add(admin)
        db.session.commit()
        flash("添加管理员成功!", "ok")
        return redirect(url_for("admin.admin_list", page=1))
    return render_template("admin/admin_add.html", form=form)
Exemple #11
0
def admin_edit(id=None):
    form = AdminForm()
    admin = Admin.query.get_or_404(id)
    if request.method == "GET":
        form.pwd.data = admin.pwd
        form.role.data = admin.role_id
    if form.validate_on_submit():
        data = form.data
        admin_num = Admin.query.filter_by(name=data["name"]).count()
        if admin.name != data["name"] and admin_num == 1:
            flash("管理员名称已经存在!", "err")
            return redirect(url_for("admin.admin_edit", id=id))
        from werkzeug.security import generate_password_hash
        admin.name = data["name"]
        admin.pwd = generate_password_hash(data["pwd"])
        admin.role_id = data["role"]
        db.session.add(admin)
        db.session.commit()
        flash("修改管理员成功!", "ok")
        return redirect(url_for("admin.admin_list", page=1))
    return render_template("admin/admin_edit.html", form=form, admin=admin)
Exemple #12
0
def admin():

    form = AdminForm()
    if form.validate_on_submit():

        username = form.username.data
        password = form.password.data
        #authenticate returns the username
        admin = Admin.authenticate(username, password)

        if admin:
            do_login(admin)
            return redirect(f'/{get_route()}/admin-home')
        else:
            return render_template('admin-login.html', form=form)

    #if admin not logged in then show the login form
    if not g.user:
        return render_template('admin-login.html', form=form)
    #if admin logged in the show admin home
    else:
        return redirect(f'{get_route()}/admin-home')
Exemple #13
0
def popular_places():
    try:
        db = mysql.connect()
        mycursor = db.cursor()
        mycursor.execute("select distinct(city) from placedetails")
        cities = []
        for row in mycursor:
            cities.append(row[0])
        form = AdminForm()
        form.city.choices = [(city, city) for city in cities]
        if request.method == 'POST' and form.validate_on_submit():
            cname = request.form['city']
            subset = df_iplace[df_iplace['city'] == cname]
            places = subset['placename'].value_counts().to_frame()
            plot = bc.Bar(places.iloc[0:5, ],
                          label="index",
                          values="placename",
                          plot_width=1000,
                          plot_height=700,
                          legend="top_right",
                          bar_width=0.3,
                          min_border=30,
                          xlabel="Places",
                          ylabel="Count")
            script, div = components(plot)
            return render_template(
                "admin.html",
                form=form,
                script=script,
                title_text="Top 5 Places visited by people in ",
                div=div,
                bokeh_css=CDN.render_css(),
                bokeh_js=CDN.render_js(),
                city=cname)
        return render_template("admin.html", form=form)
    except:
        print("Exception occured in admin")
    finally:
        db.close()
Exemple #14
0
def admin():
    form = AdminForm()
    if form.validate_on_submit():

        if request.method == 'POST':
            cu = conn.cursor()
            admin_form = str(form.AdminID.data)
            password_form = str(form.password.data)
            select = ("SELECT AdminID,password "
                      "FROM AdminInfo1 "
                      "WHERE AdminID= ?")
            cu.execute(select, [admin_form])
            results = cu.fetchone()
            print(results)
            if admin_form and password_form in results:
                flash('You have been logged in!', 'success')
                print(results)
                return redirect(url_for('adminhome'))
            else:
                flash('Login Unsuccessful. Please check username and password',
                      'danger')

    return render_template('AdminLogin.html', title='Login', form=form)
Exemple #15
0
def admin():
    form = AdminForm()
    info = []
    info_friends = []
    info_posts = []
    info_comments = []
    info_groups = []
    len_post = 0
    len_comment = 0
    len_friends = 0
    len_groups = 0

    cur = mysql.connection.cursor()
    cur.execute("select count(*) as count from User")
    total_users = cur.fetchone()
    cur.execute("select count(*) as count from Friends")
    total_friends = cur.fetchone()
    cur.execute("select count(*) as count from Posts")
    total_posts = cur.fetchone()
    cur.execute("select count(*) as count from Comment")
    total_comments = cur.fetchone()
    cur.execute("select count(*) as count from Groups")
    total_groups = cur.fetchone()
    cur.close()
    total_users = total_users['count']
    total_friends = total_friends['count']
    total_posts = total_posts['count']
    total_comments = total_comments['count']
    total_groups = total_groups['count']
    if form.validate_on_submit():
        cur = mysql.connection.cursor()
        cur.callproc("GETUSER_ADMIN_BY_USERNAME", [form.search.data])
        user_info = cur.fetchone()
        cur.close()
        info.append(user_info)

        cur = mysql.connection.cursor()
        cur.callproc("GETFRIEND_ADMIN_BY_USERNAME", [form.search.data])
        friends = cur.fetchall()
        info_friends.append(friends)
        cur.close()

        cur = mysql.connection.cursor()
        cur.callproc("GETPOST_ADMIN_BY_USERNAME", [form.search.data])
        posts = cur.fetchall()
        info_posts.append(posts)
        cur.close()

        cur = mysql.connection.cursor()
        cur.callproc("GETCOMMENT_ADMIN_BY_USERNAME", [form.search.data])
        comments = cur.fetchall()
        info_comments.append(comments)
        cur.close()

        cur = mysql.connection.cursor()
        cur.callproc("GETGROUP_ADMIN_BY_USERNAME", [form.search.data])
        groups = cur.fetchall()
        info_groups.append(groups)
        cur.close()
        print('info list:  >>>>>>> ', info)
        print('friend list:  >>>>>> ', info_friends)
        print('post list:  >>>>>>> ', info_posts)
        print('comment list: >>>>>>>>  ', info_comments)
        print('group list: >>>>>>>>  ', info_groups)
        len_post = len(info_posts[0])
        len_comment = len(info_comments[0])
        len_friends = len(info_friends[0])
        len_groups = len(info_groups[0])

        flash(f' User found', 'success')
        # return redirect(url_for('admin'))

    return render_template('admin.html',
                           title='Administrator',
                           form=form,
                           info=info,
                           info_friends=info_friends,
                           len_friends=len_friends,
                           info_posts=info_posts,
                           len_post=len_post,
                           len_comment=len_comment,
                           info_comments=info_comments,
                           ts=total_users,
                           tf=total_friends,
                           tp=total_posts,
                           tc=total_comments,
                           tg=total_groups,
                           len_c=len_comment,
                           len_p=len_post,
                           len_groups=len_groups,
                           info_groups=info_groups)