예제 #1
0
def index():
    userform = AddUserForm()
    categoryform = CategoryForm()
    if userform.validate_on_submit():
        user = User(name=userform.name.data, email=userform.email.data)
        user.set_password(userform.password.data)
        db.session.add(user)
        db.session.commit()
        flash('User registration successful')
        return redirect(url_for('index'))

    if categoryform.validate_on_submit():
        cat = Category(title=categoryform.title.data)
        db.session.add(cat)
        db.session.commit()
        flash('New Category added successful')
        return redirect(url_for('index'))

    totalusers = db.session.query(User).count()
    totalcategory = db.session.query(Category).count()
    totalposts = db.session.query(Post).count()

    return render_template('Adminindex.html',
                           title='Admin Panel',
                           admin='admin',
                           userform=userform,
                           categoryform=categoryform,
                           totalusers=totalusers,
                           totalcategory=totalcategory,
                           totalposts=totalposts)
예제 #2
0
def renshi_a():

    form = AddUserForm()
    if form.validate_on_submit():
        # 根据表单数据创建User对象
        u = User( username=form.username.data,
                  password=form.password.data,
                  sex = form.sex.data,
                  age = form.age.data,
                  confirmed = 1,
                  email=form.email.data,
                  idCard=form.idCard.data,
                  phonenumber=form.phonenumber.data,
                  section=form.section.data,
                  part=form.part.data,
                  )
        # 然后保存到数据库中
        db.session.add(u)
        # 此时还没有提交,所以新用户没有id值,需要手动提交
        db.session.commit()



    page = request.args.get('page',1,type=int)
    pagination = User.query.order_by(User.age).paginate(page=page,per_page=3,error_out=False)
    # us = User.query.filter(User.username == '用户测试').first()

    users = pagination.items
    resps =request.cookies.get('name')
    us = User.query.filter(User.username == resps)
    return render_template('bumen/renshi_a.html', us = us,users = users,pagination=pagination,
                           endpoint1 = 'admin.deluser',form =form,endpoint2='admin.select_part',
                           endpoint4='admin.del_absent',
                            endpoint5='admin.add_absent',endpoint6='admin.select_sections')
예제 #3
0
def add_user():
    if g.user.role != 0:
        return abort(403)
    form = AddUserForm()
    if form.validate_on_submit():
        user = User(name=form.name.data,username=form.username.data,password=form.password.data,role=form.role.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('add_user.html', form = form)
예제 #4
0
def add_user(data):
    form = AddUserForm()
    if form.validate_on_submit():
        try:
            u = User(username=form.username.data)
            u.set_password(form.password.data)
            db.session.add(u)
            db.session.commit()
        except IntegrityError:
            flash('User already exists')
    return redirect(url_for('users'))
예제 #5
0
def add_user():
    form = AddUserForm()
    if form.validate_on_submit():
        if form.permissions.data:
            permissions = UserPermissions.ADMIN
        else:
            permissions = UserPermissions.REGULAR_USER
        user = User(username=form.username.data, password=form.password.data, permissions=permissions)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('users'))
예제 #6
0
def add_user():
    if g.user.role != 0:
        return abort(403)
    form = AddUserForm()
    if form.validate_on_submit():
        user = User(name=form.name.data,
                    username=form.username.data,
                    password=form.password.data,
                    role=form.role.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('add_user.html', form=form)
예제 #7
0
파일: routes.py 프로젝트: pschader/kaapana
def index():
    hello_world_user = os.environ['HELLO_WORLD_USER']
    form = AddUserForm()
    if form.validate_on_submit():
        user = User(username=form.username.data)
        db.session.add(user)
        db.session.commit()
        return redirect('index')
    users = User.query.all()
    return render_template('index.html',
                           title='Home',
                           hello_world_user=hello_world_user,
                           users=users,
                           form=form)
예제 #8
0
def add_user(key):
    form = AddUserForm()
    request_model = database_model.get_join_request(key)
    if request_model.email != "":
        form.name = request_model.email.split(".")[0].title()
        if form.validate_on_submit():
            user = UserModel()
            user.name = form.username.data
            user.email = request_model.email
            user.slack = form.slack.data
            database_model.add_user(user)
            database_model.clear_join_requests(request_model.email)
            return redirect("/")
        return render_template("add_user.html", form=form)
    else:
        return Response("Invalid key", 403)
예제 #9
0
def create():
    form = AddUserForm()
    form.city.choices = [('Bangalore', 'Bangalore'), ('Chennai', 'Chennai'),
                         ('Mangalore', 'Mangalore')]

    #form.submit = SubmitField('Add')

    if form.validate_on_submit():
        data = {
            'name': form.name.data,
            'age': form.age.data,
            'city': form.city.data,
            'mobile': form.mobile.data
        }
        mongo.db.user.insert_one(data)
        flash("\"%s\" added successfully!" % form.name.data, 'success')
        return redirect(url_for('index'))
    return render_template('create.html', title='Add user', form=form)
예제 #10
0
def add_user():
    ''' Add a user or an admin.

    :return: Redirect to the admin dashboard method
    :rtype: redirect
    '''
    form = AddUserForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        role = form.role.data
        email = form.email.data
        db = get_db()
        error = None

        if not username:
            error = 'Username is required.'
        elif not password:
            error = 'Password is required.'
        elif db.execute('SELECT id FROM user WHERE username = ?',
                        (username, )).fetchone() is not None:
            error = 'User {} is already registered.'.format(username)
        elif email and (role != 'admin'):
            error = 'Only admins can have an email adress.'
        if error is None:
            if not email:
                db.execute(
                    'INSERT INTO user (username, password, user_role,'
                    ' first_login) VALUES (?, ?, ?, ?)',
                    (username, generate_password_hash(password), role, 1))
                db.commit()
            else:
                db.execute(
                    'INSERT INTO user (username, password, user_role, '
                    'first_login, email) VALUES (?, ?, ?, ?, ?)',
                    (username, generate_password_hash(password), role, 1,
                     email))
                db.commit()
            return redirect(url_for('admins.dashboard'))

        flash(error)

    return redirect(url_for('admins.dashboard'))
예제 #11
0
def admin_adduser():
    if (current_user.is_admin() == False):
        return "Access Denied"      
    form = AddUserForm()
    
    if form.validate_on_submit():
        form.validate()
        #check if user already exists in database
        present = User.query.filter_by(username=form.username.data).first()
        if present is not None:
            flash("Error: This user already exists")
            return render_template("admin-adduser.html", form=form)
        user = User(username=form.username.data, admin=form.admin.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash("User Succesfully Created!") 
        return redirect(url_for('admin'))
    return(render_template('admin-adduser.html', form=form))
예제 #12
0
def add_user(role=0):
    form = AddUserForm()

    if form.validate_on_submit():

        if (not g.user or g.user.id != models.ROLE_ADMIN) and models.ROLE_USER:
            flash("Unauthorized access.", "danger")
            return redirect(url_for('admin'))

        name = form.name.data
        surname = form.surname.data
        pw = form.pw.data
        mail = form.mail.data
        user = models.User(name=name, surname=surname, password=pw, mail=mail, role=role)

        db.session.add(user)
        db.session.commit()
        flash("The user %r has been created!" % str(name + ' ' + surname), "success")
        return redirect(url_for('admin'))

    return render_template("add_user.html", page_id="admin", title="New user", form=form, u=g.user)
예제 #13
0
def add_user():
    roles = User.query.all()
    role = User.query.filter_by(id=current_user.id).first()
    if current_user.admin == 0:
        redirect(url_for('index'))
        flash(
            'You do not have access to that page. Please contact your administrator.'
        )
    form = AddUserForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data)
        user.set_password(form.first_name.data)
        db.session.add(user)
        db.session.commit()
        flash('You have successfully created {} {}\'s account!'.format(
            user.first_name, user.last_name))
        return redirect(url_for('admin_manage_user'))
    return render_template('admin_update_user.html',
                           title="Add User",
                           form=form,
                           roles=roles)