def addUser(): form = CreateAccountForm(request.form) if request.method == 'POST' and form.validate(): # save user in the database if session.get('username') is not None: app.logger.debug( "User is logged in so it must be an admin editing users") usertype = form.usertype.data app.logger.debug(form.usertype.data) cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\ [form.newname.data, form.newusername.data, form.newpassword.data, usertype]) # log the user in g.db.commit() app.logger.debug('New user created') allUsersQuery = g.db.execute('select * from users') allUsers = allUsersQuery.fetchall() session['message'] = {'message': 'User has been added'} return redirect(url_for('userOptions')) else: app.logger.debug( "User is not logged in- a new user is being created") app.logger.debug("Form field has data") usertype = form.usertype.data app.logger.debug(form.usertype.data) cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\ [form.newname.data, form.newusername.data, form.newpassword.data, usertype]) # log the user in g.db.commit() app.logger.debug('New user created') session['username'] = form.newusername.data return redirect(url_for('userOptions')) title = "Add a New User" return render_template('adduser.html', form=form, title=title)
def addUser(): form = CreateAccountForm(request.form) if request.method == 'POST' and form.validate(): # save user in the database if session.get('username') is not None: app.logger.debug("User is logged in so it must be an admin editing users") usertype = form.usertype.data app.logger.debug(form.usertype.data) cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\ [form.newname.data, form.newusername.data, form.newpassword.data, usertype]) # log the user in g.db.commit() app.logger.debug('New user created') allUsersQuery = g.db.execute('select * from users') allUsers = allUsersQuery.fetchall() session['message'] = { 'message': 'User has been added'} return redirect(url_for('userOptions')) else: app.logger.debug("User is not logged in- a new user is being created") app.logger.debug("Form field has data") usertype = form.usertype.data app.logger.debug(form.usertype.data) cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\ [form.newname.data, form.newusername.data, form.newpassword.data, usertype]) # log the user in g.db.commit() app.logger.debug('New user created') session['username'] = form.newusername.data return redirect(url_for('userOptions')) title = "Add a New User" return render_template('adduser.html', form=form, title=title)
def createAccount(): app.logger.debug('In create account!') form = CreateAccountForm(request.form) if request.method == 'POST' and form.validate(): usertype = form.usertype.data app.logger.debug(form.usertype.data) cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\ [form.newname.data, form.newusername.data, form.newpassword.data, usertype]) # log the user in g.db.commit() app.logger.debug('New user created') session['username'] = form.newusername.data return redirect(url_for('home')) title = "Create An Account" return render_template('createaccount.html', url="base.html", form=form, title=title)
def createAccount(): app.logger.debug('In create account!') form = CreateAccountForm(request.form) if request.method == 'POST' and form.validate(): usertype = form.usertype.data app.logger.debug(form.usertype.data) cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\ [form.newname.data, form.newusername.data, form.newpassword.data, usertype]) # log the user in g.db.commit() app.logger.debug('New user created') session['username'] = form.newusername.data return redirect(url_for('home')) title = "Create An Account" return render_template('createaccount.html', url="base.html", form=form, title=title)
def create_account(): #if g.user is not None or 'user_id' not in session: # return redirect(url_for('index')) form = CreateAccountForm(request.form) if request.method == 'POST': if form.validate(): user = User.query.filter_by(username=form.ca_username.data).first() if user is None: new_user = User(form.ca_username.data, form.ca_email.data, form.ca_password.data) db.session.add(new_user) db.session.commit() flash('Account Created') session['user_id'] = new_user.id return redirect(url_for('index')) else: flash(u"Username can not be used.", 'error') else: flash_form_errors(form) return render_template('create_account.html', create_account_form=form)
def create_account(): #if g.user is not None or 'user_id' not in session: # return redirect(url_for('index')) form = CreateAccountForm(request.form) if request.method == 'POST': if form.validate(): user = User.query.filter_by(username=form.ca_username.data).first() if user is None: new_user = User(form.ca_username.data, form.ca_email.data, form.ca_password.data) db.session.add(new_user) db.session.commit() flash('Account Created') session['user_id'] = new_user.id return redirect(url_for('index')) else: flash(u"Username can not be used.", 'error') else: flash_form_errors(form) return render_template('create_account.html', create_account_form=form)
def POST(self): login = LoginAccountForm() create = CreateAccountForm(Request().POST) if create.validate() != True: return render('index.mako', login=login, create=create) return web.input()