def register(): ''' Register endpoint ''' if current_user.is_authenticated: return redirect(url_for('index')) form_login = LoginForm() form_register = RegisterForm() if form_register.validate_on_submit(): query_email = DB.session.query(User.id).filter_by( email=form_register.email.data).scalar() is not None query_user = DB.session.query(User.id).filter_by( username=form_register.username.data).scalar() is not None if not query_email and not query_user: hashed_password = generate_password_hash( form_register.password.data, method='sha256') new = User(username=form_register.username.data, password=hashed_password, email=form_register.email.data) DB.session.add(new) DB.session.commit() return redirect(url_for('login')) else: flash('Username or Email already exist') return render_template('login.html', form_login=form_login, form_register=form_register)
def register(request): if request.method == 'POST': frm = RegisterForm(request.POST) # frm.cleaned_data # print (frm) # return HttpResponse("efgsb") if frm.is_valid(): fdata = frm.cleaned_data uname = fdata['username'] name = fdata['name'] passwd = fdata['password'] try: print uname, passwd usr = User(username=uname) usr.set_password(passwd) usr.save() except: return HttpResponse("User already exists!") myusr = MyUser(user=usr, name=name, t=0) myusr.save() return render(request, "welcome.html") else: return HttpResponse("fill all the boxes") else: return HttpResponse('Nice Try!')
def loginn(): ''' Login endpoint ''' form_login = LoginForm() form_register = RegisterForm() if request.method == 'POST': if form_login.validate_on_submit(): new = User.query.filter_by( username=form_login.username.data).first() if new is not None: if check_password_hash(new.password, form_login.password.data): login_user(new, remember=form_login.remember.data) return redirect(url_for('index')) else: flash('Username or password is incorect') else: flash('Username or password is incorect') else: if current_user.is_authenticated: return redirect(url_for('index')) return render_template('login.html', form_login=form_login, form_register=form_register)
def register(): form = RegisterForm() if form.validate_on_submit(): db.session.add(form.user) db.session.commit() login_user(form.user) flash('You are registered successfully.', 'info') return redirect(url_for('index')) return render_template('register.html', form=form)
def login(): ''' Login view Workaround to have 2 forms on the same page ''' if current_user.is_authenticated: return redirect(url_for('index')) form_register = RegisterForm() form_login = LoginForm() return render_template('login.html', form_login=form_login, form_register=form_register)
def register(): form = RegisterForm() if form.validate_on_submit(): hash_password = generate_password_hash(form.password.data, method='sha256') # put data into database new_user = User(username=form.username.data, password=hash_password, email=form.email.data) datab.session.add(new_user) datab.session.commit() # redirect to login page return redirect(url_for('login')) return render_template('register.html', form=form)
def register(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): user = User.query.filter_by(email=form.email.data).first() if user is None: user = User(username=form.username.data, email=form.email.data, password=sha256_crypt.encrypt(str(form.password.data)), registeredAt=datetime.now(), confirmed=False) db.session.add(user) db.session.commit() user_settings = Setting(ageGap=2, searchDistance=30, settingsEdited=False) db.session.add(user_settings) db.session.commit() user_profile = Profile(fullname=form.name.data, firstName=form.name.data.split()[0], surname=' '.join( form.name.data.split()[1:]), username=form.username.data, profileEdited=False) db.session.add(user_profile) db.session.commit() token = s.dumps(form.email.data) msg = Message('Confirm your Email! :)', recipients=[form.email.data]) link = url_for('confirmed', token=token, _external=True) msg.body = f"Your confirmation link is: {link}" mail.send(msg) return redirect(url_for('confirm_email')) else: flash("Email or Username already being used!") return render_template('register.html', form=form)
def register_handle(): form=RegisterForm(request.form) if request.method=="POST" and form.validate(): stat = check_user(request.form['username']) if stat==True: flash("This username already taken") return redirect(url_for("register_handle")) else: username=request.form['username'] email =request.form['email'] password= request.form['pswd'] first_name =request.form['firstname'] last_name = request.form['lastname'] print("dfghjkl") print("fffff",username, password, email, first_name, last_name) add_user(password,username,email,first_name,last_name) flash("welcome"+username) session['logged_in'] = True session['username'] = username return redirect(url_for("dashboard")) return render_template("register.html", form=form)
def register_data(request): frm = RegisterForm() ctx = {'form': frm} return render(request, 'signinpage.html', ctx)