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 register(): if request.method == 'POST' and 'User-Agent' not in request.headers: email = request.form['email'] password = generate_password_hash(request.form['password']) name = request.form['name'] if name and email and password: if Users.query.filter_by(email = email).first() is None: new_user = Users(name, email, password) db.session.add(new_user) db.session.commit() user = Users.query.filter_by(email = email).first() token = user.generate_auth_token(600) #---visit tutorial on generating this return jsonify({'error':'null', 'data':{'token': token.decode('ascii'), 'expires': 600, 'user':{'id': user.id, 'email': user.email, 'name': user.name}, 'message':'success'}}) if Users.query.filter_by(email = email).first() is not None: user = Users.query.filter_by(email = email).first() return jsonify({'error': '1', 'data': {'email': user.email}, 'message':'user already exists'}) form = SignUpForm() if request.method == 'POST' and 'User-Agent' in request.headers: if form.validate_on_submit(): email = request.form['email'] password = generate_password_hash(request.form['password']) name = request.form['name'] new_user = Users(name, email, password) db.session.add(new_user) db.session.commit() # user = Users.query.filter_by(email = email).first() # token = user.generate_auth_token(600) #---visit tutorial on generating this return redirect(url_for('login')) return render_template( 'signup.html', title='User Signup', year=datetime.now().year, form=form, user=g.user )
def sign_up(): """ Creates a new user and logs them in """ form = SignUpForm() form['csrf_token'].data = request.cookies['csrf_token'] url = '' if request.files: url = upload_file_to_s3(request.files['image_file']) if form.validate_on_submit(): user = User(first_name=form.data['first_name'], last_name=form.data['last_name'], email=form.data['email'], password=form.data['password'], street_address=form.data['street_address'], town=form.data['town'], zipcode=form.data['zipcode'], state=form.data['state'], country=form.data['country'], profile_image_url=url, qr_image_url='test') db.session.add(user) db.session.commit() login_user(user) return user.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}
def sign_up(): """ Creates a new user and logs them in """ form = SignUpForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): if ('image' in request.files): image = request.files['image'] image.filename = get_unique_filename(image.filename) upload = upload_file_to_s3(image) url = upload['url'] else: url = 'https://github.com/Drewthurm21/LookingForGroup/blob/main/images/main_logo.PNG?raw=true' user = User(username=form.data['username'], email=form.data['email'], password=form.data['password'], image_url=url) db.session.add(user) db.session.commit() print('------------->', user) login_user(user) return user.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}, 401
def signup(): signup_form = SignUpForm() context = { 'signup_form': signup_form, } if signup_form.validate_on_submit(): username = signup_form.username.data password = signup_form.password.data re_password = signup_form.re_password.data if password == re_password: user_doc = get_user(username) if user_doc.to_dict() is None: hash_password = generate_password_hash(password) user_data = UserData(username, hash_password) put_user(user_data) put_init_todo(DefaultTodo(username)) user = UserModel(user_data) login_user(user) flash("Bienvenido a Remaind {}".format( str(user.id).capitalize())) return redirect(url_for('board')) else: flash("usuario existe.") else: flash("Contraseñas no coinciden.") return render_template("signup.html", **context)
def login(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('books')) signinform = SignInForm() signupform = SignUpForm() if signinform.validate_on_submit(): user = User.query.filter_by(username=signinform.username.data).first() password = make_secure_token(signinform.password.data) if user is not None and password == user.password: login_user(user) return redirect(url_for('books')) else: flash('Invalid login. Please try again.') if signupform.validate_on_submit(): username = signupform.username.data email = signupform.email.data password = make_secure_token(signupform.password.data) user = User(username=username, email=email, password=password) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for('books')) return render_template('auth.html', title='Sign In', signinform=signinform, signupform=signupform, )
def sign_up(): form = SignUpForm() top5 = getTop5() message_01 = 'User already exists' message_02 = 'User was successfully created. Click in the "Log in" button to access the page.' if form.validate_on_submit(): name = request.values.get('name') email = request.values.get('email') password_hash = generate_password_hash(request.values.get('password')) phone = request.values.get('phone') address = request.values.get('address') user = User(name, email, password_hash, phone, address) # If email does not exists in the database if user.register() == 1: return render_template('user/sign_up.html', form=form, message=message_02, top5=top5) # If email already exists in the database else: return render_template('user/sign_up.html', form=form, message=message_01, top5=top5) else: return render_template('user/sign_up.html', form=form, message="", top5=top5)
def signUp(): form = SignUpForm() form.promo_choice.choices = [(promotion.id_promotion, promotion.code) for promotion in Promotion.query.all()] if current_user.is_authenticated: return redirect(url_for('dashboard')) flash(f"Vous êtes déja inscrit sur notre application !", "info") #Send form if conditions = OK and redirect if request.method == 'POST' and form.validate_on_submit(): user = User(lastname=form.lastname.data, firstname=form.firstname.data, username=form.username.data, email=form.email.data, birthday=form.birthday.data) user.set_password(form.password.data) promotion = Promotion.query.filter_by( id_promotion=form.promo_choice.data).first() db.session.add(user) promotion.promotions.append(user) db.session.commit() flash( 'Votre inscription a été prit en compte {}. Veuillez vérifier vos email pour confirmer votre inscription' .format(form.username.data, "info")) return redirect(url_for('index')) return render_template('signup.html', title='Sign Up', form=form)
def signUp(): """Signs a user up to the system""" form = SignUpForm() if form.validate_on_submit(): try: user = User.sign_up(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, department=form.department.data, password=form.password.data, image_url=form.image_url.data, current_role_id=form.user_role.data) db.session.commit() if user.current_role.role == "stocker": stocker = Stocker(user_id=user.id) db.session.add(stocker) db.session.commit() elif user.current_role.role == "forklift_driver": driver = ForkliftDriver(user_id=user.id) db.session.add(driver) db.session.commit() except IntegrityError: flash("Email is already in use", "danger") return redirect("/sign-up") handle_login(user) flash(f"Welcome {user.first_name}!", "success") return redirect("/") return render_template("/signup.html", form=form)
def sign_up(): form = SignUpForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): if User.query.filter(User.username == form.data['username']).first(): return jsonify({ 'user': { 'errors': validation_errors_to_error_messages( {'ERROR': ['Username must be unique']}) } }) elif User.query.filter(User.email == form.data['email']).first(): return jsonify({ 'user': { 'errors': validation_errors_to_error_messages( {'ERROR': ['Email must be unique']}) } }) else: user = User(username=form.data['username'], email=form.data['email'], password=form.data['password']) db.session.add(user) db.session.commit() login_user(user) return jsonify({'user': user.to_dict()}) return jsonify( {'user': { 'errors': validation_errors_to_error_messages(form.errors) }})
def sign_up(): """ Creates a new user and logs them in """ form = SignUpForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): if "image" not in request.files: url = 'https://myplanits.s3-us-west-1.amazonaws.com/Screen+Shot+2021-03-08+at+4.58.09+PM.png' else: image = request.files["image"] if not allowed_file(image.filename): return {"errors": "file type not permitted"}, 400 image.filename = get_unique_filename(image.filename) upload = upload_file_to_s3(image) if "url" not in upload: upload['url'] = '' url = upload['url'] # url = {'url': ''} # if request.files: # url = upload_file_to_s3(request.files['image']) user = User(first_name=form.data['first_name'], last_name=form.data['last_name'], image_url=url, email=form.data['email'], password=form.data['password']) db.session.add(user) db.session.commit() login_user(user) return user.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}
def sign_up(): form = SignUpForm() if form.validate_on_submit(): table.put_item( Item={ 'name': form.name.data, 'email': form.email.data, 'mobile': form.mobile.data, 'country': form.country.data, 'newsletter': form.newsletter.data }) msg = 'Conguratulations !!! {} is now a Premium Member !'.format( form.name.data) flash(msg) # email to owner email_message = '\nname: {} ' \ '\nmobile: {}' \ '\nemail: {}' \ '\ncountry: {}'.format(form.name.data, form.mobile.data, form.email.data, form.country.data) notification.publish(Message=email_message, TopicArn=topic_arn, Subject="You've got a mail") return redirect(url_for('home_page')) return render_template('signup.html', form=form)
def sign_up(): """ Creates a new user and logs them in """ form = SignUpForm() form['csrf_token'].data = request.cookies['csrf_token'] if "profile_pic" not in request.files: return "No user_file key in request.files" file = request.files["profile_pic"] print("HELLOOOOOOOOOOOOOOO") print(dir(file)) if file: file_url = upload_file_to_s3(file, Config.S3_BUCKET) else: file_url = '' if form.validate_on_submit(): user = User(username=form.data['username'], email=form.data['email'], password=form.data['password'], profile_pic=file_url, fav_anime_id=int(form.data['fav_anime_id'])) db.session.add(user) db.session.commit() login_user(user) return user.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}
def signup(): form = SignUpForm() try: if form.validate_on_submit(): password = form.password.data username = form.username.data telephone = form.telephone.data phone_number = process_telephone(telephone) # Map object `user` of class `User` to a record of table User _user = User( username=username, password=password, telephone=phone_number, ) # Add record to database db.session.add(_user) # Save changes to db db.session.commit() # Log user in and create session login_user(_user, remember=form.remember_me.data) resp = make_response(redirect(url_for('dashboard'))) resp.set_cookie("userID", f"{_user.id}") return resp except Exception as err: print(err) db.session.rollback() form.submit.errors.append(f"Error saving user:{err}") return render_template('signup.html', form=form)
def sign_up(): form = SignUpForm() if form.validate_on_submit(): table.put_item( Item={ 'name': form.name.data, 'email': form.email.data, 'mobile': form.mobile.data, 'country': form.country.data, 'newsletter': form.newsletter.data }) msg = 'Congratulations !!! {} for signing in !'.format(form.name.data) # a flash message thorugh flask framework flash(msg) # mail to app owner, its me now created a sns service to vivekster account email_message = '\nname: {} ' \ '\nmobile: {} ' \ '\nemail: {} ' \ '\ncountry: {}'.format(form.name.data, form.mobile.data, form.email.data, form.country.data) notification.publish(Message=email_message, TopicArn=topic_arn, Subject="You've Got A Mail") return redirect(url_for('home_page')) return render_template('signup.html', form=form)
def signup(): if current_user.is_authenticated: return redirect(url_for('index')) form = SignUpForm() if form.validate_on_submit(): username_re_match = re.fullmatch("^(?!.*[-_]{2,})(?=^[^-_].*[^-_]$)[\w\s-]{5,8}$", form.username.data) password_re_match = re.fullmatch("^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%&])[A-Za-z\d@$!%&]{8,15}$", form.password.data) if not bool(username_re_match): flash("Username must contain a length of at least 5 characters and a maximum of 8 characters." "Username must contain at least one special character like - or _. " "Username must not start or end with these special characters and they can't be one after", 'error') return redirect(url_for('signup')) if not bool(password_re_match): flash("Password must contain a length of at least 8 characters and a maximum of 15 characters." "Password must contain at least one lowercase character" "Password must contain at least one uppercase character" "Password must contain at least one digit [0-9]." "Password must contain at least one special character like ! @ # & $ %.", 'error') return redirect(url_for('signup')) user = User(username=form.username.data, email=form.email.data, password=form.password.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash("You are successfully registered!", "success") return redirect(url_for("login")) return render_template('signup.html', title='Sign Up', form=form)
def sign_up(): """ Creates a new user and logs them in """ form = SignUpForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): user = User(name=form.data['name'], username=form.data['username'], email=form.data['email'], password=form.data['password']) db.session.add(user) db.session.commit() bodyPart1 = BodyPart(title='Shoulders', user_id=user.id) bodyPart2 = BodyPart(title='Back', user_id=user.id) bodyPart3 = BodyPart(title='Arms', user_id=user.id) bodyPart4 = BodyPart(title='Chest', user_id=user.id) bodyPart5 = BodyPart(title='Legs', user_id=user.id) bodyPart6 = BodyPart(title='Abs', user_id=user.id) db.session.add_all( [bodyPart1, bodyPart2, bodyPart3, bodyPart4, bodyPart5, bodyPart6]) db.session.commit() lift1 = Lift( title="Shoulder Press", description= "Sit on upright bench with dumbbells at shoulder height. Press weights upwards", body_part_id=bodyPart1.id) lift2 = Lift( title="Deadlift", description= "Stand with mid-foot under barbell. Grab bar, bend knees, straighten back and stand up with weight", body_part_id=bodyPart2.id) lift3 = Lift( title="Seated Bicep Curls", description= "Sit in incline bench with dumbbells at your sides. Contract biceps and bend your elbows to bring the weights shoulder height", body_part_id=bodyPart3.id) lift4 = Lift( title="Bench Press", description= "Lie on flat bench. Straighten you arms to un-rack bar. Bring bar down to mid-chest and press upwards", body_part_id=bodyPart4.id) lift5 = Lift( title="Leg Press", description= "Sit back in bench with head supported and feet shoulder-width apart. Press footplate forward", body_part_id=bodyPart5.id) lift6 = Lift( title="Sit-Ups", description= "Lie down on back with knees bent. Contract abs and sit up", body_part_id=bodyPart6.id) db.session.add_all([lift1, lift2, lift3, lift4, lift5, lift6]) db.session.commit() login_user(user) return user.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}
def signup(): form = SignUpForm() if form.validate_on_submit(): password = form.password.data address = form.address.data phonenum = form.phonenum.data fullname = form.address.data aadhar = form.aadhar.data url = "http://127.0.0.1:5000/registerfarmer" payload = {} payload['fullname'] = fullname payload['password'] = password payload['address'] = address payload['aadhar'] = aadhar payload['phone_no'] = phonenum payload['imagelink'] = "some.url.com" response = requests.post(url, json=payload).json() print(response['error']) if response['status'] == "OK": return redirect('/login') else: return render_template('signup.html', form=form, title='Join US', error=response['error']) return render_template('signup.html', form=form, title='Join US')
def signup(): title = 'Sign Up' form = SignUpForm() if request.method == 'POST' and form.validate_on_submit(): username = form.username.data email = form.email.data password = form.password.data existing_user = User.query.filter((User.username == username) | (User.email == email)).all() if existing_user: flash('The email or username is already in use. Please try again.', 'danger') return redirect(url_for("signup")) newuser = User(username, email, password) db.session.add(newuser) db.session.commit() flash( f"Thank you {username} for creating an account with us! We hope you enjoy your time here!", 'success') # msg = Message(f'Thank you, {username}', recipients=[email]) # msg.body = f'Dear {username}, thank you for registering for our application and supporting our product. We hope you enjoy this application and look forward to seeing you around. Rest assured, your user information is safe with us. Have an awesome time storing your contacts!' # mail.send(msg) return redirect(url_for('login')) return render_template('signup.html', title=title, form=form)
def sign_up(): form = SignUpForm() user = User() if form.validate_on_submit(): user_name = request.form.get('user_name') user_email = request.form.get('user_email') register_check = User.query.filter( db.or_(User.nickname == user_name, User.email == user_email)).first() if register_check: flash("error: The user's name or email already exists!") return redirect('/sign-up') if len(user_name) and len(user_email): user.nickname = user_name user.email = user_email user.role = ROLE_USER try: db.session.add(user) db.session.commit() except: flash("The Database error!") return redirect('/sign-up') flash("Sign up successful!") return redirect('/index') return render_template("sign_up.html", title='Sign Up', form=form)
def post(self, request, *args, **kwargs): form_data = request.POST user_img = form_data.get("user_img", "1") # Choice id to image path mapping # update by umakoshi masato choice2img_path = { str(i): f'img/user_icon_{i}.png' for i in range(1, 6) } url_path = choice2img_path[user_img] form = SignUpForm(data=form_data) if form.is_valid(): form.save() username = form.cleaned_data.get("username") email = form.cleaned_data.get("email") password = form.cleaned_data.get("password1") user = authenticate(username=username, email=email, password=password) img_choice = ImageChoice(user=user, url_path=url_path) img_choice.save() login(request, user) return redirect("/") return render(request, "app/signup.html", {"form": form})
def sign_up(): form = SignUpForm() user = User() if form.validate_on_submit(): user_name = request.form.get('user_name') user_password = request.form.get('user_password') user_email = request.form.get('user_email') register_check = User.query.filter( db.or_(User.username == user_name, User.email == user_email)).first() if register_check: flash("Error: Username or Email already exists.") return redirect(url_for('sign_up')) if len(user_name) and len(user_email) and len(user_password): user.username = user_name user.password_hash = generate_password_hash(user_password, method='pbkdf2:sha1', salt_length=8) user.email = user_email user.role = ROLE_USER try: db.session.add(user) db.session.commit() except: flash("Database error.") return redirect(url_for('sign_up')) flash("Sign up successful.") return redirect(url_for('index')) return render_template("sign_up.html", form=form)
def sign_up(): """ Creates a new user and logs them in """ form = SignUpForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): user = User(username=form.data['username'], email=form.data['email'], password=form.data['password'], free_currency=1000) db.session.add(user) db.session.commit() new_deck = Deck(user_id=user.to_dict()['id'], name=f"{user.to_dict()['username']}'s deck") db.session.add(new_deck) db.session.commit() card_arr = random.choice(decks) for card in card_arr: new_card = Card( user_id=user.to_dict()['id'], card_type=card, deck_id=new_deck.to_dict_lite()['id'], ) db.session.add(new_card) db.session.commit() login_user(user) return user.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}, 401
def sign_up(request): # 회원가입 form = SignUpForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.save() return Response(status=status.HTTP_201_CREATED) return Response(form.errors, status=status.HTTP_406_NOT_ACCEPTABLE)
def sign_up(): """ Creates a new user and logs them in """ form = SignUpForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): body = request.get_json() username = form.data['username'] user = User(username=username, email=form.data['email'], password=form.data['password'], firstname=body['firstname'], lastname=body['lastname'], fakebankinfo=body['fakebankinfo'], state=body['state']) db.session.add(user) db.session.commit() new_user = User.query.filter_by(username=username).first() new_user = new_user.to_dict() vault = Vault(user_id=new_user['id']) db.session.add(vault) db.session.commit() new_vault = Vault.query.filter_by(user_id=new_user['id']).first() coins = Coin.query.all() for coin in coins: vault_coin = VaultCoin(vault_id=new_vault.id, coin_id=coin.id, amount=0) db.session.add(vault_coin) db.session.commit() login_user(user) return user.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}, 401
def post(self, request): form = SignUpForm(request.POST, request.FILES) form.fields['payment_methods'].choices = self.choices_pay if form.is_valid(): if password_confirmed(form.cleaned_data): return render(request, 'app/signup.html', { 'message': 'Las contraseñas no coinciden', 'form': form }) try: tipo = form.cleaned_data['type'] create_user(tipo, form) return render(request, 'app/login.html', { 'message': 'Cuenta creada satisfactoriamente', 'form': form, }) except IntegrityError: return render(request, 'app/signup.html', { 'message': 'El usuario ya esta en uso', 'form': form }) except KeyError as e: return render(request, 'app/signup.html', { 'message': e.args[0], 'form': form }) else: form = LoginForm() return render(request, 'app/login.html', { 'form': form, })
def signup_page(): if current_user.is_authenticated: return redirect(url_for('index_page')) form = SignUpForm() if form.validate_on_submit(): _username = form.username.data _email = form.email.data _password = form.password.data # at this point, the form has done basic validation # we should be OK to create the user now user = User(username=_username, email=_email) user.set_password(_password) db.session.add(user) db.session.commit() flash( 'Congratulations! You\'ve successfully registered for the Devsite.' ) # retiderct to login page to let the new user login return redirect(url_for('login_page')) return render_template('signup.html', title='Sign Up', form=form)
def register(): """ Serves the register page """ form = SignUpForm(request.form) if form.validate_on_submit(): # Check if username exists user = User.query.filter_by(username=form.username.data).first() if user is not None: flash("Username already taken") return render_template('register.html', form=form) # Check that the password matches some basic criteria password = form.password.data if len(password) < 6 or re.search('\w*\d\w*', password) == None: flash('Password does not meet rules') return render_template('register.html', form=form) user = create_user(form.username.data, password, not form.played_chess_before.data, admin=False) # Assign the user to the session session.clear() session["current_user"] = user.id redirect_url = request.args.get("next", None) or url_for("index") # TODO: Validate that the redirect url is on our domain (not some other site) return redirect(redirect_url) return render_template('register.html', form=form)
def signup(): if current_user.is_authenticated: return redirect(url_for('index')) form = SignUpForm() # Dummy token_v2 dummy_token_v2 = 'a08d5b0a9c758029ce4178b82cb142b0b778f04fb19\ 71c3e8bc8f1b314c1d2b1b3636a874287baccfddd57dbf4912cdb47\ d62c493bbb067bcbdb0e72a3fd890a4469752808122bc650c6033ab563' if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) if form.token_v2.data != '': user.token_v2 = form.token_v2.data else: user.token_v2 = dummy_token_v2 db.session.add(user) db.session.commit() flash( 'Your account has been created successfully. You can log in now.', 'success') return redirect(url_for('login')) return render_template('signup.html', form=form)
def signup(): if current_user.is_authenticated: return redirect(url_for('index')) form = SignUpForm() if form.validate_on_submit(): email = form.email.data password = form.password.data rol = form.rol.data # Creamos el usuario y lo guardamos user = User(len(users) + 1, email, password, rol) print(user) users.append(user) print(users) session['rol'] = rol # Dejamos al usuario logueado login_user(user, remember=True) next_page = request.args.get('next', None) if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) return render_template("signup.html", form=form)
def register(): if request.method == 'POST' and 'User-Agent' not in request.headers: email = request.form['email'] password = generate_password_hash(request.form['password']) name = request.form['name'] if name and email and password: if Users.query.filter_by(email = email).first() is None: new_user = Users(name, email, password) db.session.add(new_user) db.session.commit() user = Users.query.filter_by(email = email).first() token = user.generate_auth_token(600) #---visit tutorial on generating this return jsonify({'error':'null', 'data':{'token': token.decode('ascii'), 'expires': 600, 'user':{'id': user.id, 'email': user.email, 'name': user.name}, 'message':'success'}}) if Users.query.filter_by(email = email).first() is not None: user = Users.query.filter_by(email = email).first() return jsonify({'error': '1', 'data': {'email': user.email}, 'message':'user already exists'}) form = SignUpForm() if request.method == 'POST' and 'User-Agent' in request.headers: if form.validate_on_submit(): email = request.form['email'] password = generate_password_hash(request.form['password']) name = request.form['name'] new_user = Users(name, email, password) db.session.add(new_user) db.session.commit() # user = Users.query.filter_by(email = email).first() # token = user.generate_auth_token(600) #---visit tutorial on generating this return redirect(url_for('login')) return render_template( 'signup.html', title='User Signup', year=datetime.datetime.now().year, form=form, user=g.user )
def sign_up(): """ Creates a new user and logs them in """ form = SignUpForm() form['csrf_token'].data = request.cookies['csrf_token'] err = '' data = request.get_json() if data['password'] != data['confirm_password']: err = 'Password and confirm password must match.' if form.validate_on_submit(): if err == '': user = User( username=form.data['username'], email=form.data['email'], password=form.data['password'], lastName=form.data['lastName'], firstName=form.data['firstName'], biography=form.data['biography'], ) db.session.add(user) db.session.commit() login_user(user) return user.to_dict() error_msgs = [ txt.split(': ')[1] for txt in validation_errors_to_error_messages(form.errors) ] if err: error_msgs.append(err) return {'errors': error_msgs}
def sign_up(): # Redirect the user to the index page if he or she has been authenticated # already. if current_user.is_authenticated: return redirect(url_for('home.home')) form = SignUpForm(request.form) # Add education. educations = Education.query.all() form.education_id.choices = [(e.id, e.name) for e in educations] if form.validate_on_submit(): query = User.query.filter(User.email == form.email.data) if query.count() > 0: flash(_('A user with this e-mail address already exists'), 'danger') return render_template('user/sign_up.htm', form=form) user = User(form.email.data, bcrypt.hashpw(form.password.data, bcrypt.gensalt()), form.first_name.data, form.last_name.data, form.student_id.data, form.education_id.data, form.birth_date.data, form.study_start.data, form.receive_information.data) user.phone_nr = form.phone_nr.data user.address = form.address.data user.zip = form.zip.data user.city = form.city.data user.country = form.country.data db.session.add(user) db.session.commit() group = Group.query.filter(Group.name == 'all').first() group.add_user(user) db.session.add(group) db.session.commit() copernica.update_user(user, subscribe=True) login_user(user) flash(_('Welcome %(name)s! Your profile has been succesfully ' 'created and you have been logged in!', name=current_user.first_name), 'success') return redirect(url_for('home.home')) else: flash_form_errors(form) return render_template('user/sign_up.htm', form=form)
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 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 signup(request): if request.method == 'POST': form = SignUpForm(request.POST) next = request.POST['next'] if form.is_valid(): prof = form.save() prof.folder_id = create_prof_folder(request.POST['email']) prof.save() user = auth.authenticate(username=request.POST['email'], password=request.POST['password']) if user is not None: auth.login(request, user) return HttpResponseRedirect(next) else: taken = False form = SignUpForm() next = request.GET.get('next', '/') context = { 'form':form, 'next': next } return render_to_response('signup.html', context, context_instance=RequestContext(request))
def signin(): """ The page on which a user sign in or sign up, depending on whether the SignUpForm or the LoginForm is submitted. :return: signin.html rendered with both forms """ if current_user.is_active: flash("You are already signed in.") return redirect(url_for("index")) signup = SignUpForm() login = LoginForm() if login.validate_on_submit(): username = login.username_l.data.lower() password = login.password_l.data u = User.query.filter_by(username=username).first() if u: if not u.is_active: flash("This account has been deactivated because of too many complaints from users.") elif pwd_context.verify(password, u.password): login_user(u) flash("You're in.") return redirect(url_for("public_profile", name=u.username)) else: flash("Wrong password.") else: flash('Never heard of you.') if signup.validate_on_submit(): username = signup.username_s.data.lower() password = pwd_context.encrypt(signup.password_s.data) blurb = signup.about_s.data url = signup.url_s.data badu = User.query.filter_by(username=username).first() if not badu: u = User(username, password, url, blurb) db.session.add(u) db.session.commit() login_user(u) flash("Welcome.") return redirect(url_for("index")) else: flash("Sorry, that one's taken.") return render_template("signin.html", signup=signup, login=login)