def render(): if get_option('initialized') is not None: return redirect('/') form = SetupForm(csrf_enabled=False) if form.validate_on_submit(): site_name = form.site_name.data user_name = form.user_name.data password = form.password.data demo = form.demo.data set_option('site_name', site_name) set_option('site_demo', demo) set_option('site_filespage_limit', 128) set_option('site_postspage_limit', 128) register_user( name=user_name, password=password ) set_option('initialized', 'True') return redirect('/') return render_template('setup.html', form=form)
def render(): if get_option('initialized') is not None: return redirect('/') form = SetupForm(csrf_enabled=False) if form.validate_on_submit(): site_name = form.site_name.data user_name = form.user_name.data password = form.password.data demo = form.demo.data set_option('site_name', site_name) set_option('site_demo', demo, type='boolean') set_option('site_filespage_limit', 128, type='integer') set_option('site_postspage_limit', 128, type='integer') set_option('site_description', 'Your Description', type='textarea') set_option('site_tags', 'cms,site,website,blog', type='tags') register_user( name=user_name, password=password ) set_option('initialized', 'True', type='boolean', editable=False) return redirect('/') return render_template('setup.html', form=form)
def render_publish(id): sidenav = get_sidenav() form = UserForm(csrf_enabled=False) user = None msg = None if form.validate_on_submit(): avatars = request.form.getlist('file_id') avatar = None if avatars is not None: if len(avatars) > 0: avatar = avatars[0] if avatar is not None: avatar_file = db.collections.find_one({'_id': ObjectId(avatar)}) else: avatar_file = None if user_exists(form.user_name.data) and id is None: msg = 'User already exists' return render_template( 'editUser.html', sidenav=sidenav, form=form, user=user, id=id, msg=msg ) new_user = register_user( name=form.user_name.data, password=form.password.data, avatar=avatar_file, id=id) if not id and new_user is not False: return redirect('/admin/edituser/{}'.format(new_user.inserted_id)) if id: user = db.collections.find_one({"_id": ObjectId(id)}) if user and request.method != 'POST': form.user_name.data = user["nick_name"] form.password.data = user["password"] return render_template('editUser.html', sidenav=sidenav, form=form, user=user, id=id, msg=msg)
def test_registration(): nick = 'JohnDoe' user = register_user(name=nick, password='******') assert user != None db_user = db.collections.find( {'structure': '#User', 'nick_name': nick} ) assert db_user != None db.collections.delete_many( {'structure': '#User', 'nick_name': nick} )