Exemplo n.º 1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('misc.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        try:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            hq_1 = bcrypt.generate_password_hash(
                form.question_1.data).decode('utf-8')
            hq_2 = bcrypt.generate_password_hash(
                form.question_2.data).decode('utf-8')
            hq_3 = bcrypt.generate_password_hash(
                form.question_3.data).decode('utf-8')
            user = User(username=form.username.data,
                        display_name=form.display_name.data,
                        password=hashed_password,
                        question_1=hq_1,
                        question_2=hq_2,
                        question_3=hq_3)
            db.session.add(user)
            db.session.commit()
            flash(f'Your account has been created! You are able to login now.',
                  'success')
            return redirect(url_for('usersReviews.login'))
        except exc.IntegrityError:
            flash(f'Username exists, please choose a different one!', 'danger')
            # return redirect(url_for('usersReviews.register'))
            return redirect(url_for('usersReviews.register'))
    return render_template('register.html', title='Register', form=form)
Exemplo n.º 2
0
def account():
    reviews = Review.query.filter_by(user_id=current_user.username).all()
    questions_form = UpdateQuestionsForm()
    password_form = UpdatePasswordForm()
    name_form = UpdateNameForm()

    user = User.query.filter_by(username=current_user.username).first()

    if questions_form.validate_on_submit():
        if user:
            hq_1 = bcrypt.generate_password_hash(
                questions_form.question_1.data).decode('utf-8')
            hq_2 = bcrypt.generate_password_hash(
                questions_form.question_2.data).decode('utf-8')
            hq_3 = bcrypt.generate_password_hash(
                questions_form.question_3.data).decode('utf-8')
            user.question_1 = hq_1
            user.question_2 = hq_2
            user.question_3 = hq_3
            db.session.commit()
            flash(f'Your security questions has been updated!', 'success')
            return redirect(url_for('usersReviews.account'))
        else:
            flash(f'Password is wrong, check again', 'danger')
    elif password_form.validate_on_submit():
        if user:
            new_hashed_password = bcrypt.generate_password_hash(
                password_form.new_password.data).decode('utf-8')
            user.password = new_hashed_password
            db.session.commit()
            flash(f'Your password has been succesfully updated!', 'success')
            return redirect(url_for('usersReviews.account'))
        else:
            flash(f'Password format is incorrect, check again', 'danger')
    elif name_form.validate_on_submit():
        if user:
            user.display_name = name_form.new_display_name.data
            db.session.commit()
            flash(f'Your display name has been succesfully updated!',
                  'success')
            return redirect(url_for('usersReviews.account'))
        else:
            flash(f'Display name format is incorrect!', 'danger')

    whitelist = Whitelist.query.filter_by(user_id=user.id).all()
    blacklist = Blacklist.query.filter_by(user_id=user.id).all()

    return render_template('account.html',
                           title='Account',
                           form1=questions_form,
                           form2=password_form,
                           form3=name_form,
                           whitelist=whitelist,
                           blacklist=blacklist,
                           reviews=reviews)
Exemplo n.º 3
0
def signup_post():
    try:

        email = request.form['email']
        password1 = request.form['password1']
        password2 = request.form['password2']

        user = User.query.filter_by(email=email).first()

        if user:
            flash('Email already exists. Please log in', 'w3-pale-red')
            return redirect(url_for('auth.login', email=email))
            # return render_template("login.html", email=email)

        if password1 != password2:
            flash('Passwords don\'t match. Try again', 'w3-pale-red')
            return render_template("signup.html", email=email)
        hash_ = bcrypt.generate_password_hash(password1).decode('utf-8')

        new_user = User(email=email, password=hash_)
        db.session.add(new_user)
        db.session.commit()
        flash('Sign up succesful', 'w3-pale-green')
        # return render_template("login.html", email=email)
        return redirect(url_for('auth.login'))

    except:
        flash('Sign up failed', 'w3-pale-red')

    return render_template("signup.html")
Exemplo n.º 4
0
def su_register():
    form = SeperUserRegistrationForm()
    if form.is_submitted():
        mail = User.query.filter_by(email=form.email.data).first()
        if bcrypt.check_password_hash(su_key, form.key.data):
            if mail:
                flash(
                    f'{form.email.data} alreaady Registered. Choose another one or contact Admin.',
                    'danger')
                return redirect(url_for('su_register'))
            else:
                hashed_password = bcrypt.generate_password_hash(
                    form.password.data).decode('utf-8')
                s_user = User(user_name=form.username.data,
                              email=form.email.data,
                              password=hashed_password,
                              role='super')
                db.session.add(s_user)
                db.session.commit()
                flash(
                    f' Account created for {form.username.data} successfully..!',
                    'success')
                return redirect(url_for('user_login'))
        else:
            flash(f'you entered a wrong key..', 'danger')
    return render_template('su_r3gister.html',
                           title='SuperUser Registration',
                           form=form)
Exemplo n.º 5
0
def user_register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = UserRegistrationForm()
    if form.is_submitted():
        mail = User.query.filter_by(email=form.email.data).first()
        if mail:
            flash(
                f'{form.email.data} alreaady Registered. Choose another one or contact Admin.',
                'danger')
            return redirect(url_for('user_register'))
        else:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user = User(user_name=form.username.data,
                        email=form.email.data,
                        password=hashed_password)
            db.session.add(user)
            db.session.commit()
            flash(f' Account created for {form.username.data} successfully..!',
                  'success')
            return redirect(url_for('user_login'))
    return render_template('user_register.html',
                           title='User Registration',
                           form=form)
Exemplo n.º 6
0
	def create_user(cls, username, email, password, phone_number, admin = False):
		cls.create(
			username = username,
			email = email,
			password = bcrypt.generate_password_hash(password),
			phone_number = phone_number,
			is_admin = admin
			)
Exemplo n.º 7
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)
Exemplo n.º 8
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = SignUpForm()
    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'Acoount is created succesfully for {form.username.data}! Now you Can Login', 'success')
        return redirect(url_for('login'))
    return render_template('signup.html',title='Sign Up',form=form)
Exemplo n.º 9
0
def register():
	if current_user.is_authenticated:
		return redirect(url_for('index'))
	form = RegistrationForm()
	if form.validate_on_submit():
		hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		user = Leden(aanhef=form.aanhef.data, voornaam=form.voornaam.data, achternaam=form.achternaam.data, email=form.email.data, password=hashed_password)
		db.session.add(user)
		db.session.commit()
		flash(f'Account aangemaakt! U kunt nu inloggen', 'success')
		return redirect(url_for('login'))
	return render_template("register.html", form=form)
Exemplo n.º 10
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    registration_form = RegistrationForm()
    if registration_form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            registration_form.password.data).decode('UTF-8')
        new_user = User(username=registration_form.username.data,
                        email=registration_form.email.data,
                        password=hashed_password)
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('login'))
    return render_template('sign-up-page.html', form=registration_form)
Exemplo n.º 11
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.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)
Exemplo n.º 12
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(f'Password is Updated succesfully , Now you Can Login', 'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html',title="Reset Password",form=form)
Exemplo n.º 13
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,
                    roles=[find_or_create_role('regular')])
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created!', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', form=form)
Exemplo n.º 14
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(
            "Secret_Password").decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        send_request_email(user)
        db.session.add(user)
        db.session.commit()
        flash('Access has been requested', 'success')
        return redirect(url_for('main.home'))
    return render_template('register.html', title='Register', form=form)
Exemplo n.º 15
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(name=form.name.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Successfully registered, {form.name.data}. Please log in.',
              'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Exemplo n.º 16
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegisterForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(username=form.username.data,
                    password=hashed_password,
                    security_question=form.security_question.data,
                    security_answer=form.security_answer.data)
        db.session.add(user)
        db.session.commit()
        flash(f'Account Created for {form.username.data}. You can now log in!',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', form=form, title="Register")
Exemplo n.º 17
0
def registration():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    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,
                    mobile=form.mobile.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Your account has been created for {form.username.data}!',
              'success')
        return redirect(url_for('index'))
    return render_template('registration.html', title='SignUp Form', form=form)
Exemplo n.º 18
0
def forgot_password():
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(
                user.question_1,
                form.question_1.data) and bcrypt.check_password_hash(
                    user.question_2,
                    form.question_2.data) and bcrypt.check_password_hash(
                        user.question_3, form.question_3.data):
            new_hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user.password = new_hashed_password
            db.session.commit()
            flash('Your password has been succesfully updated!', 'success')
            return redirect(url_for('usersReviews.login'))
    return render_template('forgot_password.html', form=form)
Exemplo n.º 19
0
def register():
    form = Registration()
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    if form.validate_on_submit():
        username = form.username.data
        email = form.email.data
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode()
        user = User(username=username,
                    email=email,
                    hashed_password=hashed_password)
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=False)
        flash('You have been registered!', 'success')
        return redirect(url_for('main.home'))
    return render_template('register.html', form=form)
Exemplo n.º 20
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    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(
            'Welcome ' + form.username.data +
            '! Your account has been created. You can now log in', 'success')
        return redirect(url_for('users.login'))
    return render_template("register.html",
                           header='Create Your Account',
                           form=form)
Exemplo n.º 21
0
def main():
    """Main entry point for script."""
    with app.app_context():
        db.metadata.create_all(db.engine)
        if User.query.all():
            print 'A user already exists! Create another? (y/n):',
            create = raw_input()
            if create == 'n':
                return

        print 'Enter email address: ',
        email = raw_input()
        password = getpass()
        assert password == getpass('Password (again):')

        user = User(email=email, password=bcrypt.generate_password_hash(password))
        db.session.add(user)
        db.session.commit()
        print 'User added.'
Exemplo n.º 22
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('This is invalid token', 'danger')
        return redirect(url_for('reset_request'))
    form = ReserPasswordForm()
    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 account has been Updated! You are now able to log in',
              'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html', form=form)
def generate_user(i, user_type):
    exists = True
    while exists:
        print(f"Generating Random {user_type} {i}")
        random_user = RandomUser({'nat': 'us', 'gender': 'male'})
        exists = User.query.filter_by(email=random_user.get_email()).first()
    random_picture = requests.get(random_user.get_picture())
    random_name = secrets.token_hex(8)
    _, extension = os.path.splitext(random_user.get_picture())
    file_name = random_name + extension
    path = os.path.join(app.root_path, "static/profile_pictures", file_name)
    size = 500, 500
    picture = Image.open(BytesIO(random_picture.content))
    picture.thumbnail(size)
    picture.save(path)
    password = bcrypt.generate_password_hash("password").decode("utf-8")
    user = User(user_type=user_type,
                first_name=random_user.get_first_name(),
                last_name=random_user.get_last_name(),
                email=random_user.get_email(),
                password=password,
                picture=file_name)
    if user_type == UserTypes.DRIVER:
        for j in range(0, randint(0, MAX_SPONSORSHIPS)):
            exists = True
            while exists:
                print(f"Generating Random Sponsorship {j} for Random User {i}")
                sponsor_id = randint(1, Sponsor.query.count())
                sponsor = Sponsor.query.get(sponsor_id)
                exists = sponsor in user.all_sponsors()
            sponsorship = Sponsorship()
            sponsorship.driver = user
            sponsorship.sponsor = sponsor
            sponsorship.active = bool(getrandbits(1))
            if sponsorship.active:
                sponsorship.points = randint(0, MAX_POINTS)
            db.session.add(sponsorship)
    elif user_type == UserTypes.STORE_MANAGER:
        sponsor_id = randint(1, Sponsor.query.count())
        user.employer = Sponsor.query.get(sponsor_id)
    db.session.add(user)
Exemplo n.º 24
0
def register():
    print(count)
    if current_user.is_authenticated:
        flash(
            'You are already logged in. Please log out to create a new account.',
            'danger')
        return redirect(url_for('home'))
    form = RegistrationForm()
    title = 'Register'
    if form.validate_on_submit():
        #Generate a hashed-password, and store user + hashed pw in db
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = user_list(username=form.username.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(
            'Account created successfully. You can now log in with your username and password.',
            'success')
        return redirect(url_for('login'))
    return render_template('register.html', title=title, form=form)
def main():
    if REMOVE_EXISTING:
        db.drop_all()
        db.create_all()
        print(f"Removing All Existing Database Entries")
        User.query.filter(User.user_type.isnot(UserTypes.ADMIN)).delete()
        Sponsor.query.delete()
        Sponsorship.query.delete()
        print(f"Generating Admin Accounts")
        password = bcrypt.generate_password_hash("password").decode("utf-8")
        chase = User(user_type=UserTypes.ADMIN,
                     first_name="Chase",
                     last_name="Autry",
                     email="*****@*****.**",
                     password=password)
        jake = User(user_type=UserTypes.ADMIN,
                    first_name="Jake",
                    last_name="Ammons",
                    email="*****@*****.**",
                    password=password)
        lee = User(user_type=UserTypes.ADMIN,
                   first_name="Hyeop",
                   last_name="Lee",
                   email="*****@*****.**",
                   password=password)
        db.session.add_all([chase, jake, lee])
    if GEN_SPONSORS:
        for i in range(0, NUM_SPONSORS):
            generate_sponsor(i)
    if GEN_DRIVERS:
        for i in range(0, NUM_DRIVERS):
            generate_user(i, UserTypes.DRIVER)
    if GEN_STORE_MANAGERS:
        for i in range(0, NUM_STORE_MANAGERS):
            generate_user(i, UserTypes.STORE_MANAGER)
    if GEN_SUPPORT_TICKETS:
        for i in range(0, NUM_SUPPORT_TICKETS):
            generate_support_ticket(i)
    db.session.commit()
Exemplo n.º 26
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RegistrationForm()
    if form.validate_on_submit():
        users = getDBData()
        userFoundRow = None
        if users:
            for row in users:
                if row.username.lower() == form.username.data.lower():
                    userFoundRow = row
                    break

        if not userFoundRow:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode("utf-8")

            addUser(form.username.data, hashed_password)
            flash("User successfully created!")
            return redirect(url_for("login"))
        flash("The specified household nickname already exists")
    return render_template("register.html", form=form)
Exemplo n.º 27
0
def reset_password():
    if session.get('redeem_data', None) is None:
        flash('Verify Credentials First', 'danger')
        return redirect(url_for('forgot_password'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(
            id=session.get('redeem_data', [None, None, None])[2]).first()
        if not user:
            flash('An unknown error occured. Account is corrupted.', 'danger')
            return redirect('home')
        else:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode("utf-8")
            user.password = hashed_password
            db.session.commit()
            session.pop('redeem_data', None)
            flash(f'Succesfully changed password for {user.username}.',
                  'success')
            return redirect('login')
    return render_template('reset_password.html',
                           title="Reset Password",
                           form=form)
Exemplo n.º 28
0
def register():
    context = global_context()
    if current_user:
        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')
        email = form.email.data
        token = serializer.dumps(email, salt='email-confirmation')
        confirmation_link = url_for('confirm_email',
                                    token=token,
                                    _external=True)
        user_data = {
            'firstname': form.firstname.data,
            'lastname': form.lastname.data,
            'email': form.email.data,
            'password': hashed_password,
            'confirmation_link': confirmation_link,
        }
        user = User(**user_data)
        msg = Message('NBDF Anmeldung - Email bestätigen',
                      sender=app.config['MAIL_USERNAME'],
                      recipients=[email])
        msg.body = f'Willkommen auf der NBDF Seite.\n\nBitte benutze diesen Link um deinen Account zu bestätigen: {confirmation_link.replace("localhost",server_IP)}\n\nBitte antworte nicht direkt auf diese Email.'
        mail.send(msg)
        db.session.add(user)
        db.session.commit()
        flash(
            f'Willkommen {form.firstname.data}, bitte bestätige die Email für deinen Account.',
            'success')
        #context['user_email'] = form.email.data
        return redirect(url_for('login', **context))
    context['form'] = form
    context['title'] = 'Registrieren'
    return render_template('register.html', **context)
Exemplo n.º 29
0
 def password(self, password):
     self.password_hash = bcrypt.generate_password_hash(password).decode(
         'utf8')