Пример #1
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('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Пример #2
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():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been updated! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html', title='Reset Password', form=form)
Пример #3
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()
        #lets us know the account was created
        flash(
            f'Account created for {form.username.data}! You are now able to log in',
            'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Пример #4
0
def registration():

    if current_user.is_authenticated:
        flash(f'logged in as {current_user.username}')
        return redirect(url_for('func'))

    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("Your account has been created!. You can now log in", "success")
        return redirect(url_for('login'))
    return render_template("register.html", title="Register", form=form)
Пример #5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f"Your account has been created! You are now able to log in!",
              "success")
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Пример #6
0
def register():

    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()

    if form.validate_on_submit():
        hashed_pasword = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data,email=form.email.data,password=hashed_pasword)
        usage = Usage(username=form.username.data,nosessions=0)
        db.session.add(user)
        db.session.add(usage)
        db.session.commit()
        flash(f'Your account was created Successfully', 'success')

        return redirect(url_for('home'))

    return render_template('register.html', title='Register', form=form)
Пример #7
0
def reset_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():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        User.objects(email=user.email).update_one(password=hashed_password)
        flash(f'Password has been updated', 'success')
        return redirect(url_for('main.home'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #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'Your account has been created! You are now able to log in',
              'success')
        return redirect(url_for("login"))

    return render_template("register.html", title="Register", form=form)
Пример #9
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.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 is created for {form.username.data} and activation link has been sent to your email. Please verify !',
            'success')
        send_activation_mail(user)
        return redirect(url_for('users.login'))
    return render_template('register.html', title='register', form=form)
Пример #10
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if not user:
        flash('That token is expired', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash(f'password updated {user.username}!', 'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #11
0
def reset_token():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('Invalid/Expired request', category='warning')
        return redirect(url_for('users.reset_password'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        password_hash = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = password_hash
        db.session.commit()
        flash(f'New password set', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_password.html',
                           title='Reset Password',
                           form=form)
Пример #12
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('This token is invalid/expired, please try again', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data)
        user.password = hashed_password
        db.session.commit()
        flash('Password updated successfully', 'warning')
        return redirect(url_for('users.login'))

    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #13
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,
                    level=form.level.data)
        db.session.add(user)
        db.session.commit()
        flash("Account created for {}.".format(form.username.data), 'success')
        return redirect(url_for('login'))
    else:
        flash('that username or email is already taken', 'danger')
    return render_template("register.html", title="Register", form=form)
Пример #14
0
def reset_token(token):  # Reset password with token
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if not user:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash("You'password has been updatedt! You can now log in.", 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #15
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('Not valid token, it might have expired', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Password updated. You can now log in', 'success')
        return redirect(url_for('users.login'))
    return render_template('users/reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #16
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('The token is invalid or has expired, please try again', 'error')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash(f'Your password has been updated. You can now login', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #17
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')
        if form.user.data:
            user = User(username = form.username.data, email = form.email.data, password = hashed_password, userAddress = form.userAddress.data, role = "user")
            db.session.add(user)
            db.session.commit()
            flash(f'Your account has been created! You are now able to log in', 'success')
        elif form.restaurant.data:
            user = User(username = form.username.data, email = form.email.data, password = hashed_password, userAddress = form.userAddress.data, role = "restaurant")
            db.session.add(user)
            db.session.commit()
            flash(f'Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html',title = 'Register', form = form)
Пример #18
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_token(token)
    if not user:
        flash('That is an invalid or expired token.', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = \
            bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash(f'Your password has been updated! You are now able to login',
              'success')
        return redirect(url_for('signin'))

    return render_template('reset_token.html', title="Reset Password", form=form)
Пример #19
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    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():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash(f'Password Has Been Upated', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #20
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        # hasing New Users password
        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)
        # adding New User to the Datbase
        db.session.add(user)
        db.session.commit()
        # success is a bootstrap message
        flash('Your account has been created! Please log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Пример #21
0
def register():
    # this is to prevent already authenticated users from registering again.
    if current_user.is_authenticated:
        return redirect(url_for('main.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'Hoi {form.username.data}! Your account has been created. Please log in now.',
            'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Пример #22
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user_to_register = User(username=form.username.data,
                                email=form.email.data,
                                password=hashed_password)

        db.session.add(user_to_register)
        db.session.commit()

        flash(f'Account Created! You can now login.', 'success')
        return redirect(url_for('users.login'))

    return render_template('register.html', title='Register', form=form)
Пример #23
0
def reset_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 in an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been updated! You are now able to log in',
              'success')
        return redirect(url_for('users.login'))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form)
Пример #24
0
def account():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=current_user.username).first()
        if user and form.password.data == form.re_password.data:
            # user.password = form.password.data
            user.password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            db.session.commit()
            flash('Your account has been updated!', 'success')
        else:
            flash('Your password not match!', 'danger')
        return redirect(url_for('users.account'))
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title='Change Password',
                           image_file=image_file,
                           form=form)
Пример #25
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():
        password = bcrypt.generate_password_hash(form.password.data)
        user.password = password
        db.session.commit()
        flash(f"Your Password has been updated.You are now able to login",
              "success")
        return redirect(url_for('login'))

    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #26
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user:
        form = ResetPasswordForm()
        if form.validate_on_submit():
            hashed_pw = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user.password = hashed_pw
            db.session.commit()
            flash(f"Account password has been changed!!", 'success')
            return redirect(url_for('users.login'))
        return render_template("reset_token.html",
                               title="Reset Password",
                               form=form)
    else:
        flash("That is an invalid or expired token!", "warning")
        return redirect(url_for("users.reset_request"))
Пример #27
0
def reset_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 a invalid or expired token", "danger")
        return redirect(url_for("users.reset_request"))
    form = PasswordResetForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user.password = hashed_password
        db.session.commit()
        flash(f"You password has been updated! You are now be able to log in",
              "success")
        return redirect(url_for("users.login"))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form)
Пример #28
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if not user:
        flash('Invalid or Expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hash_pwd = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hash_pwd
        db.session.commit()
        flash('Your password now has been updated! You are now able to log in',
              'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #29
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))

    rform = RegistrationForm()
    if rform.validate_on_submit():
        # has the password
        hashed_pwd = bcrypt.generate_password_hash(
            rform.password.data).decode('utf-8')
        user = User(username=rform.username.data,
                    email=rform.email.data,
                    password=hashed_pwd)
        db.session.add(user)
        db.session.commit()
        flash(
            f'Account has been created for {rform.username.data}. You can login',
            'success')
        return redirect(url_for('users.login'))  # redirect to login
    return render_template('register.html', title='Register', form=rform)
Пример #30
0
def reset_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 Token or Token is Expired', 'warning')
        return redirect(url_for('users.reset_request'))
    form = RequestPasswordForm()
    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)
        user.password = hashed_password
        db.session.commit()
        flash('Your Password  has been Updated! You can login now', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #31
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_auth_token(token)
    if user is None:
        flash('Invalid or Expired token', 'danger')
        return redirect(url_for('users.reset_request'))

    form = PasswordResetForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_pw
        db.session.commit()
        flash(f'Your Password has been updated. Now you can login', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_password.html',
                           title='Update Password',
                           form=form)
Пример #32
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')
        #creating User instance
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(
            'Your account has been created! You can now login with your login credentials.',
            'success')
        return redirect(url_for('login'))

    return render_template('register.html', title='Register', form=form)