def signup_route(): # Check if the viewer already has a session. if 'logged_in' in session: # Display. return redirect(url_for('main.main_route')) # cannot register again # Retrieve the registration form. form = RegistrationForm(request.form) options = {'error': []} # Deal with POST requests. if request.method == "POST": if form.validate(): # Insert the user into database. database.add_user(form.username.data, form.firstname.data, form.lastname.data, form.password1.data, form.email.data) # Display. return redirect( url_for('user.login_route')) # still need to log in else: options['error'] = [] for error_list in form.errors.items(): options['error'] += error_list[1] # note: form.errors.items() is like: # [('username', ['error message', 'error message']), # ('password', ['error message'])] # Display. return render_template("signup.html", form=form, **options) # Display. return render_template("signup.html", form=form, **options)
def _newForm(self): from RegistrationForm import RegistrationForm form = RegistrationForm() p = form.properties() p.project = "test" p.mailto = "*****@*****.**" return form
def signup_route(): # Check if the viewer already has a session. if 'logged_in' in session: # Display. return redirect(url_for('main.main_route')) # cannot register again # Retrieve the registration form. form = RegistrationForm(request.form) options = { 'error': [] } # Deal with POST requests. if request.method == "POST": if form.validate(): # Insert the user into database. database.add_user(form.username.data, form.firstname.data, form.lastname.data, form.password1.data, form.email.data) # Display. return redirect(url_for('user.login_route')) # still need to log in else: options['error'] = [] for error_list in form.errors.items(): options['error'] += error_list[1] # note: form.errors.items() is like: # [('username', ['error message', 'error message']), # ('password', ['error message'])] # Display. return render_template("signup.html", form=form, **options) # Display. return render_template("signup.html", form=form, **options)
def register(): if current_user is not None and current_user.is_authenticated(): return redirect(url_for('chatChannels')) form = RegistrationForm() if form.validate_on_submit(): if form.password.data == form.passwordConfirmation.data: user = User(form.username.data, form.password.data) if UserManager.registerNewUser(session, user): return redirect(request.args.get("next") or url_for("login")) else: flash('This username is already in use') else: flash('Passwords do not match') return render_template("register.html", form=form)
def register(): form = RegistrationForm(request.form) if request.method == 'POST' and request.form['btn'] == 'Register': # user = User(form.username.data, form.email.data) try: username = form.username.data email = form.email.data photo_id = sess['photo_id'] database.child("User").child(username).child("name").set(username) database.child("User").child(username).child("pic").set(photo_id) #with sql.connect("pythonsqlite.db") as con: # cur = con.cursor() # cur.execute("INSERT INTO User (username,email) VALUES (?, ?)", (username, email)) # con.commit() # print("inserted into table") # msg = "Record successfully added" #upload_file(username) except: print("Connection Error") #con.rollback() msg = "error in insert operation" # db_session.add(user) flash('Thanks for registering') return redirect(url_for('login')) return render_template('register.html', form=form)
def upload_file(username=''): if request.method == 'POST' and request.form['btn'] == 'upload': print("in upload methiod ") # check if the post request has the file part print(request.files) if 'file' not in request.files: print("no files ") flash('No file part') # return redirect(request.url) file = request.files['file'] print("the file ", file) # if user does not select file, browser also # submit an empty part without filename if file.filename == '': flash('No selected file') # return redirect(request.url) if file and allowed_file(file.filename): random_no = random.randint(0, 10000) filename = str(random_no) + '.' + file.filename.rsplit( '.', 1)[1].lower() sess['photo_id'] = filename # secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) # return redirect(url_for('uploaded_file', # filename=filename)) form = RegistrationForm(request.form) return render_template('register.html', form=form)