def new(): form = NewUserForm() form.federal_state.choices = [] form.federal_state.choices.append(('', _('Please select'))) for state in current_app.config['FEDERAL_STATES']: form.federal_state.choices.append(state) form.title.choices = current_app.config['SALUTATIONS'] form.type.choices = [] # add choice wich account types are possible if current_app.config['FEATURE_CUSTOMER_USERS']: form.type.choices.append((User.Type.CUSTOMER, _('customer'))) if current_app.config['FEATURE_CONSULTANT_USERS']: form.type.choices.append((User.Type.CONSULTANT, _('consultant'))) form.type.choices.append((User.Type.SERVICE_PROVIDER, _('service_provider'))) if form.validate_on_submit(): user = User(form.data['email'], form.data['password']) user.set_user_data(form.data) user.type = form.data.get('type') # no use type will be active automatically all must be activated by an admin user.active = False # send verifycation mail to check user email verify = EmailVerification.verify(user) db.session.add(user) db.session.add(verify) db.session.commit() send_mail( _("Email verification mail subject"), render_template( "user/verify_mail.txt", user=user, verify=verify, _external=True ), [user.email] ) couch_url = current_app.config.get('COUCH_DB_URL') if user.is_service_provider or user.is_customer: # create couch document and area boxes # and initialize security init_user_boxes(user, couch_url) return redirect(url_for(".verify_wait", id=user.id)) return render_template( "user/new.html", form=form, customer_id=User.Type.CUSTOMER, service_provider_id=User.Type.SERVICE_PROVIDER, )
def new(): form = NewUserForm() form.federal_state.choices = [] form.federal_state.choices.append(('', _('Please select'))) for state in current_app.config['FEDERAL_STATES']: form.federal_state.choices.append(state) form.title.choices = current_app.config['SALUTATIONS'] form.type.choices = [] # add choice wich account types are possible if current_app.config['FEATURE_CUSTOMER_USERS']: form.type.choices.append((User.Type.CUSTOMER, _('customer'))) if current_app.config['FEATURE_CONSULTANT_USERS']: form.type.choices.append((User.Type.CONSULTANT, _('consultant'))) form.type.choices.append( (User.Type.SERVICE_PROVIDER, _('service_provider'))) if form.validate_on_submit(): user = User(form.data['email'], form.data['password']) user.set_user_data(form.data) user.type = form.data.get('type') # no use type will be active automatically all must be activated by an admin user.active = False # send verifycation mail to check user email verify = EmailVerification.verify(user) db.session.add(user) db.session.add(verify) db.session.commit() send_mail( _("Email verification mail subject"), render_template("user/verify_mail.txt", user=user, verify=verify, _external=True), [user.email]) couch_url = current_app.config.get('COUCH_DB_URL') if user.is_service_provider or user.is_customer: # create couch document and area boxes # and initialize security init_user_boxes(user, couch_url) return redirect(url_for(".verify_wait", id=user.id)) return render_template( "user/new.html", form=form, customer_id=User.Type.CUSTOMER, service_provider_id=User.Type.SERVICE_PROVIDER, )
def create_user(): form = CreateUserForm() form.type.choices = [] form.federal_state.choices = current_app.config['FEDERAL_STATES'] form.title.choices = current_app.config['SALUTATIONS'] if current_app.config['FEATURE_CUSTOMER_USERS']: form.type.choices.append((User.Type.CUSTOMER, _('customer'))) form.type.choices.append((User.Type.SERVICE_PROVIDER, _('service_provider'))) if current_app.config['FEATURE_CONSULTANT_USERS']: form.type.choices.append((User.Type.CONSULTANT, _('consultant'))) form.type.choices.append((User.Type.ADMIN, _('admin'))) if form.validate_on_submit(): user = User(form.data['email'], form.data['password']) user.set_user_data(form.data) user.type = form.data.get('type') if not form.data['verified']: verify = EmailVerification.verify(user) db.session.add(verify) send_mail( _("Email verification mail subject"), render_template( "user/verify_mail.txt", user=user, verify=verify, _external=True, ), [user.email] ) else: user.verified = True if form.data['activate']: user.active = True db.session.add(user) db.session.commit() init_user_boxes(user, current_app.config.get('COUCH_DB_URL')) flash(_('User created', email=user.email), 'success') return redirect(url_for('admin.user_list')) return render_template('admin/create_user.html', form=form)