def show_register(): form = RegisterUser() if form.validate_on_submit(): username = form.username.data password = form.password.data first_name = form.first_name.data last_name = form.last_name.data email = form.email.data new_user = User(username=username, password=password, first_name=first_name, last_name=last_name, email=email) db.session.add(new_user) db.session.commit() session[USER_KEY] = new_user.toJSON() session['username'] = new_user.username # return redirect("/secret") return redirect(f"/users/{new_user.username}") else: return render_template("register.html", form=form)
def signup(): form = RegisterUser() if form.validate_on_submit(): username = form.username.data password = form.password.data email = form.email.data new_user = User.register(username, password, email) db.session.add(new_user) db.session.commit() session["user_id"] = new_user.id return redirect(url_for('user_profile', id=new_user.id)) return render_template('signup.html', form=form)
def register(): form = RegisterUser() if form.validate_on_submit(): name = form.name.data email = form.email.data password = generate_password_hash(password=form.password.data, method='pbkdf2:sha256', salt_length=8) user = User(name=name, email=email, password=password) db.session.add(user) db.session.commit() return redirect(url_for('get_all_posts')) return render_template("register.html", form=form)
def register_user(): """ form to register user """ form = RegisterUser() if form.validate_on_submit(): user = User.register_user(form) add_user_to_db(user) return redirect(f"/users/{user.username}") else: return render_template("register.html", form=form)
def register(): if not user_in_session(): form = RegisterUser() error = None if form.validate_on_submit() and request.method == 'POST': email = form.email.data if not validate_email(email): username = form.username.data if not validate_username(username): password = sha256((form.password.data).encode()) password_confirm = sha256((form.password_confirm.data).encode()) if password.hexdigest() == password_confirm.hexdigest(): name = form.name.data age = form.age.data user = User( name=name, age=age, email=email, username=username, password=password.hexdigest(), created_at=datetime.now().date() ) db.session.add(user) db.session.commit() flash('Your account has been created successfully!') return redirect(url_for('login')) else: error = 'Passwords no match!' else: error = 'Username already exist!' else: error = 'Email already exist!' return render_template('auth/register.html', form=form, error=error) else: abort(404)
def register(): form = RegisterUser() if form.validate_on_submit(): email = form.email.data password = form.password.data username = form.username.data try: form.check_mail(email) except ValidationError as error: return render_template('already_exist.html', error=repr(error)) try: form.check_username(username) except ValidationError as error: return render_template('already_exist.html', error=repr(error)) user = User(email, username, password, 'default.png') db.session.add(user) db.session.commit() user = User.query.filter_by(email=form.email.data).first() mail = user.email send_mail(mail) return redirect(url_for('login')) return render_template('register.html', form=form)
def process_user_registration(): """ process the form and redirect to /secret""" form = RegisterUser() if form.validate_on_submit(): username = form.username.data password = form.password.data email = form.email.data first_name = form.first_name.data last_name = form.last_name.data user = User.register(username, password, email, first_name, last_name) db.session.add(user) db.session.commit() session["username"] = user.username return redirect("/login") else: return render_template('register.html')
def register(): form = RegisterUser() if form.validate_on_submit(): email = form.email.data if db.session.query(User).filter(User.email == email).first() == None: is_admin = False if db.session.query(User).count() == 0: is_admin = True user = User(name=form.name.data, email=form.email.data, is_admin=is_admin, password=generate_password_hash(form.password.data, salt_length=8)) db.session.add(user) db.session.commit() return redirect(url_for('get_all_posts')) else: flash("You've already signed with that email, log in instead!") return redirect(url_for("login")) else: return render_template("register.html", form=form)
def register(): form = RegisterUser() if form.validate_on_submit(): username = form.username.data password = form.password.data email = form.email.data first_name = form.first_name.data last_name = form.last_name.data user = User.register(username=username, password=password, email=email, first_name=first_name, last_name=last_name) db.session.add(user) db.session.commit() session['username'] = user.username return redirect('/secret') else: return render_template('register.html', form=form)
def register(): form = RegisterUser() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() password = generate_password_hash(form.password.data, method='pbkdf2:sha256', salt_length=8) if not user: user = User(name=form.name.data, email=form.email.data, password=password) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for("get_all_posts")) else: flash("You've already signed up with that email, log in instead!") return redirect((url_for("login"))) return render_template("register.html", form=form, current_user=current_user)
def register_user(): """show and process registration form and add new user""" form = RegisterUser() if form.validate_on_submit(): 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) if new_user: db.session.add(new_user) db.session.commit() session["username"] = new_user.username # keep logged in return redirect(f'/users/{username}') return render_template("register.html", form=form)
def display_register_form_and_handle_register_form(): """Displays the register form and handles submitted forms""" form = RegisterUser() if form.validate_on_submit(): user = User.register( **{ key: value for (key, value) in form.data.items() if key != 'csrf_token' }) db.session.add(user) try: db.session.commit() session['user_id'] = user.id return redirect(f'/users/{form.username.data}') except IntegrityError as error: flash(error.args[0][error.args[0].find("DETAIL"):]) return render_template("register.html", form=form) else: return render_template("register.html", form=form)
def show_register_form(): """ show form to register/create user """ form = RegisterUser() return render_template('register.html', form=form)
def register(request): WEB_FILES, LIVE_SITE, totalNumberOfGames, sendBackUrl, startOffset, \ user, userId, message, topHits, topRated = initialVars(request) #Need this in the event that they don't process the form and nav to login sendBackUrl = '/' if request.method == 'GET': # Form has no data yet. request.session['sendBackUrl'] = request.GET.get('sendBack', '/') captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR']) form = RegisterUser(initial={'captchaHash': captchaHash}) return render_to_response('register.html', locals()) elif request.method == 'POST': # Form has data. form = RegisterUser(request.POST) if form.is_valid(): name = form.cleaned_data['name'] password1 = form.cleaned_data['password1'] password2 = form.cleaned_data['password2'] captchaHash = form.cleaned_data['captchaHash'] captchaEntry = form.cleaned_data['captchaEntry'] captchaEntry = captchaEntry.lower() description = form.cleaned_data['description'] if password1 != password2: captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR']) form = RegisterUser(initial={ 'captchaHash': captchaHash, 'name': name }) error = 'Passwords do not match. Please re-enter.' #log(request, 'REGISTERUSERERROR', name, "Password don\'t match") return render_to_response('register.html', locals()) SALT = flashburrito.settings.SECRET_KEY[:20] hashEntry = sha.new(SALT + captchaEntry).hexdigest() if captchaHash == hashEntry: # User entered valid Captcha code User.objects.create_user(name, '', password1) user = authenticate(username=name, password=password1) if description != "": userProfile = UserProfile(user=user, description=description) userProfile.save() #log(request, 'REGISTERUSER', name, 'Valid Registration') login(request, user) else: # User entered invalid Captcha code captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR']) form = RegisterUser(initial={ 'captchaHash': captchaHash, 'name': name }) error = 'Invalid Captcha Code. Please Enter again.' #log(request, 'REGISTERUSERERROR', name, "Invalid Captcha Code") return render_to_response('register.html', locals()) else: # Form is not valid captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR']) #TODO should parse through form and log exact error #log(request, 'REGISTERUSERERROR', "Bad Form", "Other: Form is Not Valid") return render_to_response('register.html', locals()) sendBackUrl = request.session.get('sendBackUrl', '/') request.session['sendBackUrl'] = None return HttpResponseRedirect(sendBackUrl)
def register(): form = RegisterUser() if form.validate_on_submit(): flash('username="******",email requested ="%s",password="******"' %(form.username.data,form.email.data,form.password.data)) return redirect('/index') return render_template('register.html', title='RegisterUser',form=form)
def register(request): WEB_FILES, LIVE_SITE, totalNumberOfGames, sendBackUrl, startOffset, \ user, userId, message, topHits, topRated = initialVars(request) #Need this in the event that they don't process the form and nav to login sendBackUrl = '/' if request.method == 'GET': # Form has no data yet. request.session['sendBackUrl'] = request.GET.get('sendBack', '/') captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR'] ) form = RegisterUser(initial={'captchaHash': captchaHash}) return render_to_response('register.html', locals()) elif request.method == 'POST': # Form has data. form = RegisterUser(request.POST) if form.is_valid(): name = form.cleaned_data['name'] password1 = form.cleaned_data['password1'] password2 = form.cleaned_data['password2'] captchaHash = form.cleaned_data['captchaHash'] captchaEntry = form.cleaned_data['captchaEntry'] captchaEntry = captchaEntry.lower() description = form.cleaned_data['description'] if password1 != password2: captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR'] ) form = RegisterUser(initial={'captchaHash': captchaHash, 'name': name}) error = 'Passwords do not match. Please re-enter.' #log(request, 'REGISTERUSERERROR', name, "Password don\'t match") return render_to_response('register.html', locals()) SALT = flashburrito.settings.SECRET_KEY[:20] hashEntry = sha.new(SALT+captchaEntry).hexdigest() if captchaHash == hashEntry: # User entered valid Captcha code User.objects.create_user(name, '', password1) user = authenticate(username=name, password=password1) if description != "": userProfile = UserProfile( user=user, description=description ) userProfile.save() #log(request, 'REGISTERUSER', name, 'Valid Registration') login(request, user) else: # User entered invalid Captcha code captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR'] ) form = RegisterUser(initial={'captchaHash': captchaHash, 'name': name}) error = 'Invalid Captcha Code. Please Enter again.' #log(request, 'REGISTERUSERERROR', name, "Invalid Captcha Code") return render_to_response('register.html', locals()) else: # Form is not valid captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR'] ) #TODO should parse through form and log exact error #log(request, 'REGISTERUSERERROR', "Bad Form", "Other: Form is Not Valid") return render_to_response('register.html', locals()) sendBackUrl = request.session.get('sendBackUrl', '/') request.session['sendBackUrl'] = None return HttpResponseRedirect(sendBackUrl)