def signup(): form = SignupForm() if form.validate_on_submit(): u = User() form.populate_obj(u) u.password = User.encrypt_password(request.form.get('password')) u.save() if login_user(u): flash("Awesome, you're good to go!", 'success') return redirect(url_for('create.create_description')) return render_template('user/signup.html', form=form)
def update_credentials(): form = UpdateCredentialsForm(obj=current_user) if form.validate_on_submit(): new_password = request.form.get('password', '') current_user.email = request.form.get('email') if new_password: current_user.password = User.encrypt_password(new_password) current_user.save() flash('Your sign in settings have been updated.', 'success') return redirect(url_for('user.settings')) return render_template('user/update_credentials.html', form=form)
def password_reset(): form = PasswordResetForm(reset_token=request.args.get('reset_token')) if form.validate_on_submit(): u = User.deserialize_token(request.form.get('reset_token')) if u is None: flash('Your reset token has expired or was tampered with.', 'error') return redirect(url_for('user.begin_password_reset')) form.populate_obj(u) u.password = User.encrypt_password(request.form.get('password')) u.save() if login_user(u): flash('Your password has been reset.', 'success') return redirect(url_for('user.settings')) return render_template('user/password_reset.html', form=form)
def users(): """ Generate fake users. """ app_config = current_app.config random_emails = [] data = [] click.echo('Working...') # Ensure we get about 100 unique random emails. for i in range(0, 99): random_emails.append(fake.email()) random_emails.append(app_config['SEED_ADMIN_EMAIL']) random_emails = list(set(random_emails)) while True: if len(random_emails) == 0: break fake_datetime = fake.date_time_between(start_date='-1y', end_date='now').strftime('%s') created_on = datetime.utcfromtimestamp( float(fake_datetime)).strftime('%Y-%m-%dT%H:%M:%S Z') random_percent = random.random() if random_percent >= 0.05: role = 'member' else: role = 'admin' email = random_emails.pop() random_percent = random.random() if random_percent >= 0.5: random_trail = str(int(round((random.random() * 1000)))) username = fake.first_name() + random_trail last_created_on = created_on else: username = None last_created_on = None fake_datetime = fake.date_time_between(start_date='-1y', end_date='now').strftime('%s') current_sign_in_on = datetime.utcfromtimestamp( float(fake_datetime)).strftime('%Y-%m-%dT%H:%M:%S Z') params = { 'created_on': created_on, 'updated_on': created_on, 'role': role, 'email': email, 'username': username, 'password': User.encrypt_password('password'), 'sign_in_count': random.random() * 100, 'credits': 10, 'last_created_on': last_created_on, 'current_sign_in_on': current_sign_in_on, 'current_sign_in_ip': fake.ipv4(), 'last_sign_in_on': current_sign_in_on, 'last_sign_in_ip': fake.ipv4() } # Ensure the seeded admin is always an admin with the seeded password. if email == app_config['SEED_ADMIN_EMAIL']: password = User.encrypt_password(app_config['SEED_ADMIN_PASSWORD']) params['role'] = 'admin' params['password'] = password data.append(params) return _bulk_insert(User, data, 'users')