예제 #1
0
def mongo_add():
    form = AddUser()
    if request.method == 'POST' and form.validate_on_submit():
        if request.form['user_role'] != '':
            # parsing role values
            role = {}

            role_unicod = request.form['user_role']

            id = role_unicod[3:4]
            id = int(id)

            name_start = role_unicod.find('role_name')
            name_end = len(role_unicod)
            name = role_unicod[name_start+10:name_end]

            role['id'] = id
            role['role_name'] = name

            # insert data to DB
            user_instant.insert(fname=form.fname.data, lname=form.lname.data,\
                                login=form.login.data, email=form.email.data,\
                                role=role)
            return redirect(url_for('mongo_userslist'))

    return render_template('mongo_add.html', form=form)
예제 #2
0
파일: app.py 프로젝트: Em98/easy-Tor-detect
def users():
    form = AddUser()

    if form.validate_on_submit():
        if current_user.role != 'admin':
            flash('You are not permitted to add users.', 'warning')
            return redirect(url_for('users'))

        if form.role.data not in ['admin', 'user']:
            flash('%s is not a valid role.' % form.role.data, 'warning')
            return redirect(url_for('users'))

        user = User(username=form.username.data,
                    password=form.password.data,
                    role=form.role.data,
                    temp_password=True,
                    token=get_uuid())

        db.session.add(user)
        db.session.commit()

        flash('User %s has been added.' % user.username, 'success')
        return redirect(url_for('users'))

    else:

        if current_user.role != 'admin':
            flash('You are not permitted to edit users.', 'warning')
            return redirect(url_for('dashboard'))

        users = User.query.order_by(User.id).all()
        return render_template('users.html', form=form, users=users)
def add_user():
    form = AddUser()
    if request.method == "POST":
        if form.validate_on_submit():
            user = dbfunctions.add_user(form.username.data, form.password.data)
            if user:
                flash("User {} was created.".format(user.username))
            return redirect(url_for("users.index"))

    return render_template("users/add_user.html", form=form)
예제 #4
0
def add_users():
    form = AddUser(request.form)
    if request.method == 'POST' and form.validate():
        #if request.method == 'POST':
        user = User(name=form.name.data)
        user.role = form.role.data
        user.email = (form.email.data)
        user.password_hash(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('User Added')
        return redirect(url_for('judge'))

    return render_template('adduser.html', form=form)
예제 #5
0
def all_users():
    ALL_IP = ip_addresses()
    url = request.url_root
    url = url[7:-1]
    dicts = {
        'ALL_IP': ALL_IP,
        'IP': ALL_IP['IP'],
        'using_desktop': using_desktop(),
        'url': url,
    }
    # Shows all users
    users = list_of_users()
    changepassform = ChangePass()
    adduserform = AddUser()
    dicts['changepassform'] = changepassform
    dicts['adduserform'] = adduserform
    return render_template('all_users.html', users=users, dicts=dicts)
예제 #6
0
def add_user():
    roles = Role.query.all()
    form = AddUser()

    if request.method == 'POST' and form.validate_on_submit():
        if request.form['user_role'] != '':
            role = Role.query.filter_by(\
                                        id=request.form['user_role']).first()
            user = User(form.fname.data, form.lname.data, form.login.data,\
                        form.email.data, role)
            db.session.add(user)
            db.session.commit()
            flash('%s %s was successfully added to Data Base'\
                   % (form.lname.data,form.fname.data))
            return redirect(url_for('userslist'))

    return render_template('add_user.html', roles=roles, form=form)
def register():
    form = AddUser(request.form)
    #check if user exists in the database
    if form.validate_on_submit():
        user = mongo.db.user
        dose_user_exist = user.find_one({'username': request.form['username']})
        #if user dose not exist create user
        if dose_user_exist is None:
            cryptpass = bcrypt.hashpw(request.form['password'].encode('utf-8'),
                                      bcrypt.gensalt())
            user.insert_one({
                'username': request.form['username'],
                'password': cryptpass,
                'email': request.form['email']
            })
            session['username'] = request.form['username']
            flash('Your Account has been created, You can now login',
                  'alert-success')
            return redirect(url_for('login'))
        flash('That username already exists, Please try again', 'alert-danger')
        return redirect(url_for('register'))
    return render_template("register.html", title='Register', form=form)
예제 #8
0
def add_user():
    # Adds user directly to the system, including samba
    ALL_IP = ip_addresses()
    url = request.url_root
    url = url[7:-1]
    dicts = {
        'ALL_IP': ALL_IP,
        'IP': ALL_IP['IP'],
        'using_desktop': using_desktop(),
        'url': url,
    }

    if not session.get('logged_in'):
        return redirect(url_for('login'))

    form = AddUser(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            username = form.username.data
            password = form.password.data

            users = list_of_users()
            for u in users:
                if username == u[0]:
                    return 'Username already existing'

            cmd_useradd = "useradd " + username + " -s /bin/bash -m"
            #cmd_useradd = "useradd -G blox " + username + " -s /bin/bash -m"
            cmd_password = "******" + username + ' ' + password
            system(cmd_useradd)
            system(cmd_password)
            return "<h2>Successfully Added Acount " + username + '. ' + '<a href="' + url_for(
                'all_users') + '"> Go Back </a>'
        else:
            return 'fails'

    else:
        return render_template('add_user.html', form=form, dicts=dicts)
예제 #9
0
def add_user():
	# Adds user directly to the system, including samba
	form = AddUser(request.form)
	if request.method == 'POST':
		if form.validate_on_submit():
			username = form.username.data
			password = form.password.data

			users = list_of_users()
			for u in users:
				if username == u[0]:
					return 'Username already existing'

			cmd_useradd = "useradd " + username + " -s /bin/bash -m"
			cmd_password = "******" + username + ' ' + password
			system(cmd_useradd)
			system(cmd_password)
			return username + ' ' + password
		else:
			return 'fails'

	else:
		return render_template('add_user.html', form=form)
예제 #10
0
def add_user_registration_form():
    """ show the registration form for user """

    form = AddUser()

    if form.validate_on_submit():
        print("Hi!")
        username = form.username.data
        password = form.password.data
        email = form.email.data
        first_name = form.first_name.data
        last_name = form.last_name.data

        new_user = User.register(username, password, email, first_name,
                                 last_name)

        db.session.add(new_user)
        db.session.commit()

        session["user_id"] = new_user.username

        return redirect(f"/users/{new_user.username}")
    else:
        return redirect("/register")
예제 #11
0
파일: views.py 프로젝트: yoos/orvsd_central
def register():
    #user=current_user
    form = AddUser()
    message = ""

    if request.method == "POST":
        if form.password.data != form.confirm_pass.data:
            message = "The passwords provided did not match!\n"
        elif not re.match('^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$',
                          form.email.data):
            message = "Invalid email address!\n"
        else:
            # Add user to db
            db.session.add(
                User(name=form.user.data,
                     email=form.email.data,
                     password=form.password.data))
            db.session.commit()
            message = form.user.data + " has been added successfully!\n"

    return render_template('add_user.html',
                           form=form,
                           message=message,
                           user=current_user)
예제 #12
0
def show_registration_form():
    """ show the registration form for user """
    form = AddUser()
    return render_template("register.html", form=form)