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, thanks for signing up!', 'success') return redirect(url_for('user.welcome')) return render_template('user/signup.html', form=form)
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): from app.blueprints.user.tasks import send_welcome_email send_welcome_email.delay(current_user.email) # Create a user id for the user mailbox_id = generate_mailbox_id() # Create an inbox for the user if create_inbox(mailbox_id): current_user.mailbox_count += 1 current_user.active_mailbox = True current_user.mailbox_id = mailbox_id current_user.save() from app.blueprints.parse.models.mailbox import Mailbox m = Mailbox() m.mailbox_id = mailbox_id m.user_email = current_user.email db.session.add(m) db.session.commit() flash('Awesome, thanks for signing up!', 'success') else: flash( 'There was a problem creating an inbox for you. Please try again.', 'error') current_user.active_mailbox = False current_user.mailbox_count = 0 current_user.mailbox_id = None current_user.save() return redirect(url_for('user.settings')) return render_template('user/signup.html', form=form)
def update_credentials(): form = UpdateCredentials(current_user, uid=current_user.id) 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. """ 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 else: username = 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, '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')