def sign_up(): if 'email' in session: return redirect(url_for('home')) form = SignUpForm() email = str(form.email.data) if request.method == 'POST': if form.validate() is False: flash('Please fill out the form completely') return render_template('Signup.html', form=form) else: if Users.query.filter_by(email=form.email.data).first(): flash('Email address already in use') return render_template('Signup.html', form=form) else: users = Users(form.first_name.data, form.last_name.data, form.email.data, form.password.data) db.session.add(users) db.session.commit() session['email'] = form.email.data session['name'] = form.first_name.data user_id = Users.query.filter_by(email=form.email.data).first() session['id'] = user_id.id return redirect(url_for('home')) elif request.method == 'GET': return render_template('Signup.html', form=form)
def new(): data = MultiDict(mapping=request.json) form = SignUpForm(data) if form.validate(): if User.query.filter(User.email == data["email"]).first() is None: newUser = User(username=data["username"], email=data["email"], password=data["password"]) db.session.add(newUser) db.session.commit() newNotebook = Notebook(title='My Notebook', isDefault=True, userId=newUser.to_dict()["id"]) db.session.add(newNotebook) db.session.commit() user_dict = newUser.to_dict() return {user_dict["id"]: user_dict} else: res = make_response( {"errors": ["A user with that email already exists"]}, 401) return res else: errorset = set() for error in form.errors: errorset.add(form.errors[error][0]) errorlist = list(errorset) res = make_response({"errors": errorlist}, 401) return res
def signup(): form = SignUpForm() # if form.validate_on_submit(): # return redirect(url_for('index')) if request.method == 'POST' and form.validate(): email_id = form.email_id.data user_name = form.user_name.data password = form.password.data password_hash = generate_password_hash(password) cursor = mysql.connect().cursor() cursor.execute( '''INSERT into UserAccount(UserAccountId, UserName, EmailId, PasswordHash) values ({}, {}, {}, {})''' .format(0, user_name, email_id, password_hash)) mysql.commit() return redirect(url_for('login')) return render_template('signup.html', title='Sign Up', form=form)
async def _signup(request): form = SignUpForm(request.form) if request.method == 'POST': print(form.errors) if form.validate(): email = form.email.data user = await fetch_user(email) if user is None: user = await User.new_user(email=email, password=form.password.data) login_user(request, user) return response.redirect(app.url_for('home')) form.email.errors.append( 'An account with this email already exists!') return template('signup.html', form=form) return template('signup.html', form=SignUpForm())
def signup_user(): data = MultiDict(mapping=request.json) form = SignUpForm(data) if form.validate(): data = request.json new_user = User(first_name = data["first_name"], last_name = data["last_name"], email = data["email"], DOB = data["date_of_birth"], password=data["password"], lat = data["lat"], lng = data["lng"]) db.session.add(new_user) db.session.commit() new_user_dict = new_user.to_dict() new_user_profile = Profile(user_id = new_user_dict["id"], biography = "", location = data["location"]) db.session.add(new_user_profile) db.session.commit() return new_user_dict else: res = make_response({ "errors": format_errors(form.errors) }, 401) return res
def signup_form(): """ Sign up user """ form = SignUpForm(request.form) next_url = request.form.get('next', '/overview') if request.method == 'POST' and form.validate(): # Process form if route gets POST request from /index next_url = request.form.get('next', '/overview') user_data = form.data del user_data['confirm'] user = User(**user_data) db.session.add(user) db.session.commit() login_user(user) return redirect('/overview') return render_template("signup.html", form=form, next=next_url)
def sign_up(): errors = [] form = SignUpForm(request.form) if request.method == 'POST' and form.validate(): username = form.username.data real_name = form.real_name.data salt, passwd_hash = make_salt_passwd(form.password.data) user = list(User.view('users/by_username', key = username)) if user: errors.append('User already exists') else: new_user = User(username = username, real_name = real_name, salt = salt, password = passwd_hash) g.db.save_doc(new_user) flash('You have successfully registered') return redirect(url_for('index.index')) errors.extend(format_form_errors(form.errors.items())) return render_template('sign_up.html', form = form, errors = errors)
def sign_up(): errors = [] form = SignUpForm(request.form) if request.method == 'POST' and form.validate(): username = form.username.data real_name = form.real_name.data salt, passwd_hash = make_salt_passwd(form.password.data) user = list(User.view('users/by_username', key=username)) if user: errors.append('User already exists') else: new_user = User(username=username, real_name=real_name, salt=salt, password=passwd_hash) g.db.save_doc(new_user) flash('You have successfully registered') return redirect(url_for('index.index')) errors.extend(format_form_errors(form.errors.items())) return render_template('sign_up.html', form=form, errors=errors)
def sign_up_post(): form = SignUpForm() if not form.validate(): return json.dumps({ 'answer': False, 'details': 'Password must contain at least 8 characters; Latin letters and digits are allowed' }) if not form.password.data == form.confirm_password.data: return json.dumps({'answer': False, 'details': 'Passwords must match'}) res = SignUp().sign_up(form.login.data, form.password.data) if not res: return json.dumps({ 'answer': False, 'details': 'User with this name already exists' }) User().set_online(form.login.data) return json.dumps({'answer': True, 'details': 'OK'})