Beispiel #1
0
    def post(self):        
        if request.method == 'POST':
            form = NewUserForm()
            if form.validate_on_submit():
                try:
                    user = User.create()
                    # Set Permissions
                    if current_user.is_admin():
                        user.role = int(form.role.data)

                    del form.role
                    del form.timezone
                    del form.lang
                    form.populate_obj(user)
                    user.set_password(form.password.data)
                    user.save()

                    flash(gettext('User was succesfully saved'))
                    return redirect(url_for('UsersView:get',id=user.id))                     
                except:
                    flash(gettext('Error while creating the user'), 'error')
                    raise                    
            else:
                flash(gettext('Invalid submission, please check the messages below'), 'error')
        else:
            form = NewUserForm()

        return render_template('admin/users/add.html', 
            title = gettext('Create new user'),
            form = form,
            user = [])
Beispiel #2
0
def add_user():
	form = NewUserForm()
	if form.validate_on_submit():
		user = User()
		form.populate_obj(user)
		db.session.add(user)
		db.session.commit()
		return redirect('/new_post')
	return render_template("add_user.html", form = form)
Beispiel #3
0
def add_user():
		form=NewUserForm () #creating a new user
		if form.validate_on_submit(): #if all the areas in the form that NEED to be complete are go ahead and submit form 
			user=User() #setting up the database to receive the user
			form.populate_obj(user) #inserting the user info into the data
			db.session.add(user) #add
			db.session.commit() #commit
			return redirect('/') #go back to the page
		return render_template('add_user.html', form = form)
Beispiel #4
0
def add_user():
    form = NewUserForm()
    if form.validate_on_submit():
        user = User()
        form.populate_obj(user)
        db.session.add(user)
        db.session.commit()
        return redirect('/')
    return render_template("add_user.html", form=form)
Beispiel #5
0
def add_user():
	form = NewUserForm()
	if form.validate_on_submit(): #valid_on_submit is a subfunction
			user = User()
			#if user submits a valid form, populate the object/class user.
			form.populate_obj(user)
			#Then add to the database and commit
			db.session.add(user)
			db.session.commit()
			#direct them back to the landing page
			return redirect('/')

	return render_template("add_user.html",form = form) #Just shows them the form
Beispiel #6
0
    def post(self):
        form = NewUserForm()

        if request.method == 'POST':

            if form.validate_on_submit():
                user = User.create()
                form.populate_obj(user)
                user.set_password(form.password.data)
                user.save()

                return resp(url_for('UsersView:get', id=user.id), redirect=True,
                            message=gettext('User was succesfully saved'))
            else:
                return resp('admin/users/add.html', form=form, user=None, status=False,
                            message=gettext('Invalid submission, please check the messages below'))

        return resp('admin/users/add.html', form=form, user=None)
Beispiel #7
0
def sign_up():
    form = NewUserForm()
    if form.validate_on_submit():
        user = User()
        form.populate_obj(user)
        db.session.add(user)
        db.session.commit()
        return redirect('/topics')
    return render_template('sign_up.html', form=form)

    form = NewUserForm()  #calling on NewUserForm from forms.py
    if form.validate_on_submit(
    ):  #if statement: saying the if the submit button is pushed then,
        user = User()  #it prepares a new row for the info to be passed in
        form.populate_obj(user)  #then populates new user info entered by user
        db.session.add(user)  #creates the new user
        db.session.commit()  #then commits and saves to the database
        return redirect('/')  #after it is submitted, it redirects to...
    return render_template('.html', form=form)  # the topics page