Esempio n. 1
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_passwd = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_passwd)
        db.session.add(user)
        db.session.commit()
        flash(f'Your account created successfully. Please login !!! ', category='success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title="Registration", form=form)
Esempio n. 2
0
def register():
	if current_user.is_authenticated:
		return redirect(url_for('main.home'))
	form = RegistrationForm()
	if form.validate_on_submit():
		hashedPassword = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		user = User(username = form.username.data, email = form.email.data, password = hashedPassword)
		db.session.add(user)
		db.session.commit()
		flash('Your account has been created. You can now Sign In!', 'success')
		return redirect(url_for('users.login'))
	return render_template('register.html', title = 'Register', form = form)
Esempio n. 3
0
def registerMulti():
    if current_user.administrator != 1:
        abort(403)
    form = RegistrationMultiForm()
    backval = RegistrationMultiBACKENDForm()
    posts = Post.query.all()
    if form.validate_on_submit():
        usersFileFN = secure_filename(form.csvFile.data.filename)
        usersFile = form.csvFile.data
        usersFile.save(
            os.path.join(current_app.root_path, "temp/", usersFileFN))

        with open(f"flaskBlog/temp/{usersFileFN}") as csv_file:
            csv_reader = csv.reader(csv_file, delimiter=',')
            line_count = 0
            for row in csv_reader:

                backval.username.data = row[0]
                backval.forename.data = row[1]
                backval.surname.data = row[2]
                backval.email.data = row[3]
                backval.password.data = row[4]

                if backval.validate():
                    hashedPwd = bcrypt.generate_password_hash(
                        row[4]).decode("utf-8")
                    newUser = User(username=str(row[0]).lower(),
                                   forename=row[1],
                                   surname=row[2],
                                   email=str(row[3]).lower(),
                                   password=hashedPwd)
                    db.session.add(newUser)
                    line_count += 1
                else:
                    db.session.flush()
                    flash(
                        f"Multiple User Creation Failed.  Record with username: '******' does not follow the proper registration criteria.",
                        "danger")
                    os.remove(f"flaskBlog/temp/{usersFileFN}")
                    return redirect(url_for("users.admin"))

        os.remove(f"flaskBlog/temp/{usersFileFN}")
        db.session.commit()
        flash(f"Succesfully Added {line_count} Users!", "success")

        return redirect(url_for("users.admin"))
    return render_template("registerMulti.html",
                           title="Register Users",
                           form=form,
                           posts=posts)
Esempio n. 4
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():  #Si les donnees sont valides...
        password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=password)
        #On ajoute l'utilisateur
        db.session.add(user)
        db.session.commit()  #save the user
        flash(f'Your account has been created! You can now log in', 'success')
        return redirect(url_for('login'))
    return render_template('auth/register.html', form=form)
Esempio n. 5
0
def reset_password(token):
    user = User.verify_token(token)
    if user is None:
        flash('Invalid or expired token', 'warning')
        return redirect(url_for('users.request_token'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_passwd = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_passwd
        db.session.commit()
        flash(f'Your password changed successfully. Please login !!! ', category='success')
        return redirect(url_for('users.login'))

    return render_template('reset_password.html', title='Reset Password', form=form)
Esempio n. 6
0
def registration():
    form = RegistrationForm()
    if form.validate_on_submit():
        username = request.form['username']
        email = request.form['email']
        password = request.form['password']
        hashed_password = bcrypt.generate_password_hash(password).decode(
            'utf-8')
        user = User(username=username, email=email, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created. You are ready to login.',
              'success')
        return redirect(url_for("login"))
    return render_template('register.html', title='Register', form=form)
Esempio n. 7
0
def reset_token(token):
	if current_user.is_authenticated:
		return redirect(url_for('home'))
	user = User.verify_reset_token(token)
	if user is None:
		flash('That is an invalid or expired token!', 'warning')
		return redirect(url_for('reset_request'))
	form = ResetPasswordForm()
	if form.validate_on_submit():
		hashedPassword = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		user.password = hashedPassword
		db.session.commit()
		flash('Your password has been updated. You can now Sign In!', 'success')
		return redirect(url_for('login'))
	return render_template('reset_token.html', title = 'Reset Password', form = form)
Esempio n. 8
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    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)
        db.session.add(user)
        db.session.commit()
        flash(f'Account Created, You will now be able to login! ', 'success')
        return redirect(url_for('login'))

    return render_template('register.html', title='Register', form=form)
Esempio n. 9
0
def reset_password_with_token(token):
	if current_user.is_authenticated:
		return redirect(url_for('main.home'))
	user = User.verify_reset_token(token)
	if user is None:
		flash('That is an invalid or expired token', 'warning')
		return redirect(url_for('users.reset_request'))
	form = ResetPasswordForm()
	if form.validate_on_submit():
		print("ResetPasswordForm has been validated")
		hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		user.password = hashed_password
		db.session.commit()
		flash('Your Account has been updated ! You should be able to Login', 'success')
		return redirect(url_for('users.login'))
	print("ResetPasswordForm has NOT been validated")
	return render_template('reset_token.html', title="Reset Password", form=form) 
Esempio n. 10
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        if form.validate_on_submit():
            profile_pic = None
            if form.picture.data:
                profile_pic = save_profile_picture(form.picture.data)
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pw,
                    image_file=profile_pic)
        db.session.add(user)
        db.session.commit()
        flash('Your account was created. You can now login!', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Esempio n. 11
0
def register():
    if current_user.administrator != 1:
        abort(403)
    form = RegistrationForm()
    posts = Post.query.all()
    if form.validate_on_submit():
        hashedPassword = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(username=str(form.username.data).lower(),
                    email=str(form.email.data).lower(),
                    password=hashedPassword)
        db.session.add(user)
        db.session.commit()
        usersLoggedIn(user.username, user.id, user.administrator)
        flash(
            "Account created!  Please finish setting up user details when ready.",
            "success")
        return redirect(url_for("users.admin"))
    return render_template("register.html",
                           title="Register User",
                           form=form,
                           posts=posts)
Esempio n. 12
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    posts = Post.query.all()
    user = User.verify_reset_token(token)
    if not user:
        flash("Error: Invalid or expired token", "warning")
        return redirect(url_for("users.reset_request"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashedPassword = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user.password = hashedPassword
        db.session.commit()
        login_user(user)
        usersLoggedIn(user.username, user.id, user.administrator)
        flash(f"Password Updated!", "success")
        return redirect(url_for("users.login"))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form,
                           posts=posts)