def register_developer():
	return redirect(url_for('.index'))
	if g.user:
		flash(u'Вы уже зарегистрированы', 'warning')
		return redirect(url_for('.index'))
	
	form = forms.DeveloperRegisterForm(request.form)
	if request.method == 'POST' and form.validate():
		users.add_user(
			email=form.email.data,
			password_hash=generate_password_hash(form.password.data),
			first_name=form.first_name.data,
			last_name=form.last_name.data,
			organization=form.organization.data,
			phone=form.phone.data,
			messenger_type=form.messenger_type.data,
			messenger_uid=form.messenger_uid.data)
		user = users.get_user_by_email(form.email.data, full=True)
		if user:
			users.confirm_user(user.id)
			mmail.lists_add_user(user)
			users.add_user_role(user.id, roles.DEVELOPER)
			user.roles.append(roles.DEVELOPER)
			invites.register_invite(form.invite.data)
			session['user_id'] = user.id
			flash(u'Вы успешно зарегистрированы', 'success')
			return redirect(url_for('cabinet.index'))
		flash(u'Произошла ошибка при регистрации. Обратитесь к администрации.', 'error')
		
	return render_template('site/register-developer.html', form=form)
def info_password_change():
	form = forms.PasswordChangeForm(request.form)
	form.oldpassword.user = g.user
	if request.method == 'POST' and form.validate():
		actions.users.update_user(g.user.id, password_hash=generate_password_hash(form.password.data))
		flash(u'Пароль успешно изменен', 'success')
		return redirect(url_for('.info'))
	return render_template('cabinet/info-password-change.html', form=form)
def users_info_password_change(id):
	user = do_or_abort(a.users.get_user_by_id, id)
	form = forms.AdminPasswordChangeForm(request.form)
	if request.method == 'POST' and form.validate():
		a.users.update_user(user.id, password_hash=gen.generate_password_hash(form.password.data))
		flash(u'Пароль пользователя успешно изменен', 'success')
		return redirect(url_for('.users_info', id=user.id))
	return render_template('admin/users-info-password-change.html', user=user, form=form)
def register_customer():
	return redirect(url_for('.index'))
	if g.user:
		flash(u'Вы уже зарегистрированы', 'warning')
		return redirect(url_for('.index'))
	
	ref = session.get('ref', '')
	key = app.config.get('REFERRAL_CRYPT_KEY', 'qwertyui12345678')
	
	try:
		id, _salt = aes_base16_decrypt(key, ref).split('$')
		referrer = users.get_user_by_id(int(id))
		if not referrer or not referrer.is_customer():
			raise ValueError()
	except:
		form = None
	else:
		form = forms.CustomerRegisterForm(request.form)
		if request.method == 'POST' and form.validate():
			users.add_user(email=form.email.data,
				password_hash=generate_password_hash(form.password.data),
				first_name=form.first_name.data,
				last_name=form.last_name.data,
				organization=form.organization.data,
				phone=form.phone.data,
				messenger_type=form.messenger_type.data,
				messenger_uid=form.messenger_uid.data,
				referrer_id=referrer.id)
			user = users.get_user_by_email(form.email.data, full=True)
			if user:
				users.add_user_role(user.id, roles.CUSTOMER)
				user.roles.append(roles.CUSTOMER)
				session['user_id'] = user.id
				session['ref'] = ''
				tmail.user_confirm_email(user)
				flash(u'Вы успешно зарегистрированы. На указанный электронный адрес'
					u' было выслано письмо с подтверждением.', 'success')
				return redirect(url_for('cabinet.index'))
			flash(u'Произошла ошибка при регистрации. Обратитесь к администрации.', 'error')
	
	return render_template('site/register-customer.html', form=form)
def users_register_customer():
	form = forms.CustomerRegisterForm(request.form)
	if request.method == 'POST' and form.validate():
		do_or_abort(a.users.add_user,
			email=form.email.data,
			password_hash=gen.generate_password_hash(form.password.data),
			first_name=form.first_name.data,
			last_name=form.last_name.data,
			organization=form.organization.data,
			phone=form.phone.data,
			messenger_type=form.messenger_type.data,
			messenger_uid=form.messenger_uid.data)
		user = do_or_abort(a.users.get_user_by_email, form.email.data, full=True)
		if user:
			a.users.confirm_user(user.id)
			a.users.add_user_role(user.id, roles.CUSTOMER)
			user.roles.append(roles.CUSTOMER)
			flash(u'Рекламодатель успешно зарегистрирован', 'success')
			mmail.lists_add_user(user)
			return redirect(url_for('.users_info', id=user.id))
		flash(u'Произошла ошибка при регистрации. Обратитесь к администрации.', 'error')
	
	return render_template('admin/users-register-customer.html', form=form)
import os, sys

this_path = os.path.realpath(os.path.dirname(__file__))
project_path = os.path.join(this_path, "heymoose")
config_path = os.path.join(this_path, "config_debug.py")

if project_path not in sys.path:
	sys.path.insert(0, project_path)

os.environ["FRONTEND_SETTINGS_PATH"] = config_path

from heymoose.core import actions
from heymoose.utils.gen import generate_password_hash
import time, random

pw = generate_password_hash('password')
email_admin = '*****@*****.**'
email_customer_template = 'c{0}@c.ru'
email_developer_template = 'd{0}@d.ru'
first_names = (u'Иван', u'Петр', u'Сидор', u'Евгений')
last_names = (u'Иванов', u'Петров', u'Сидоров', u'Ковалев')

customers_count = 10
developers_count = 10
orders_per_customer = 10
apps_per_developer = 1
actions_per_app_and_order = 1

def fill_db():
	# Dummy request forces server to regenerate schema
	actions.orders.get_orders()