def get_token(): """Get user token. .. note:: The body need to be json type. :url: http://3.9.215.67:9999/api/v1/token :method: POST :param account: email. :type account: str :param password: at least 6 digits. :type password: str :return: token, expiration, scope :example: `{ "Authorization": "Bearer", "Expire_in": "12 Jun 2020 21:35:23 Localtime", "Scope": "UserScope", "Token": "eyJlA..."}` """ form = ClientForm(data=request.json) form.validate_for_api() switch = { ClientTypeEnum.Email: User.verify, } identity = switch[form.type.data](form.account.data, form.password.data) expiration = 30 * 24 * 3600 token, expires_in = generate_auth_token(identity['uid'], form.type.data.name, identity['scope'], expiration) t = combine_token_info(token, expires_in, scope=identity['scope']) return jsonify(t), 201
def storeClient(request): if request.method == 'POST': form = ClientForm(request.POST) if form.is_valid(): form.save() return redirect('clients.index') else: return redirect('clients.create')
def add_client(): form = ClientForm(request.form) if form.validate_on_submit(): client = Client(form.name.data, form.adress.data) db_session.add(client) db_session.commit() flash('Thanks for registering') return redirect(url_for('settings')) return redirect(url_for('settings'))
def edit_client(id): form = ClientForm() if form.validate_on_submit(): print('cont') client = controllers.edit_client(id, form) print('/cont') return redirect(url_for('client', id=client.id)) elif request.method == 'GET': client = controllers.find_client(id) controllers.fill_client_form(client, form) return render_template('edit_client.html', client=client, form=form)
def add_client(request): if request.method == 'GET': return render(request, 'app/clients/add.html') elif request.method == 'POST': client_form = ClientForm(request.POST) if client_form.is_valid(): client = client_form.save(commit=False) client.from_home = request.POST.get('client_type') == 'home' client.save() return redirect('client', client_id=client.id) else: return render(request, 'app/clients/add.html', {'form': client_form})
def get_controller(): """responds with the form for the example""" if views.ds_token_ok(): form = ClientForm() if form.validate() == False: flash:('All fields are required.') return render_template('form.html', form = form) else: # Save the current operation so it will be resumed after authentication session["eg"] = url_for(eg) return redirect(url_for("ds_login"))
def create_entry(x): w = x cliform = ClientForm() proform = ProductForm() addform = AddsForm() patform = PathForm() wriform = WritingForm() heaform = HeadForm() errors = None if request.method == 'POST': wb = load_workbook('order.xlsx') entrys(cliform) fill_clear(wb) fill_cli(cliform, wb) fill_pro(proform, wb) fill_adds(addform, wb) fill_hea(heaform, wb) fill_wri(wriform, wb) fill_pat(patform, wb) fill_img(w, wb) wb.save(filename='order.xlsx') return redirect(url_for('index')) return render_template("order.html", cliform=cliform, proform=proform, addform=addform, patform=patform, wriform=wriform, heaform=heaform, w=w, errors=errors)
def client(): form = ClientForm() client = Client() if form.validate_on_submit(): client.service_to_client = Service.query.filter_by(name=form.service.data).first() client.name = form.username.data.strip() client.tel = form.phone.data.strip() client.metro, client.exit_num = form.station.data.split('(') client.metro = client.metro.strip() if client.exit_num: client.exit_num = client.exit_num.replace(')', '').strip() client.info = form.about.data client.cost = form.cost.data db.session.add(client) db.session.commit() return redirect(url_for('client')) return render_template('client.html', form=form, service_data=Service.query.all())
def edit_entry(entry_id): entry = Client.query.filter_by(id=entry_id).first_or_404() form = ClientForm(obj=entry) errors = None if request.method == 'POST': entrys(form, klient_id=entry_id, klient=entry) return redirect(url_for('index')) return render_template("entry_form.html", form=form, errors=errors)
def home(request): if request.method == "POST": form = ClientForm(request.POST) if form.is_valid(): global client_id global client_secret global redirect_uri redirect_uri = "http://127.0.0.1:8000/callback" client_id = request.POST["client_id"] client_secret = request.POST["client_secret"] return redirect( "http://join.agiliq.com/oauth/authorize?client_id=" + client_id + "&redirect_uri=" + redirect_uri, request_context=RequestContext(request), ) else: form = ClientForm() return render_to_response("home.html", {"form": form}, context_instance=RequestContext(request))
def add_client(data): key, secret = data['form'].split('&') key = key.split('=')[-1] secret = secret.split('=')[-1] form = ClientForm(apiKey=key, secret=secret) if form.validate(): try: table.add_client(key, secret) table.update_all() table.view() emit('data success', {'msg': 'Successfully added!', 'income': 'Client!'}) emit('reload-table', table.gen_data()) return except sqlalchemy.exc.IntegrityError: emit('data error', {'msg': 'already exists!', 'income': 'Client'}) return emit('data error', {'msg': 'fail!', 'income': 'Client'}) return
def edit_client(request, client_id): client = get_object_or_404(Client, pk=client_id) if request.method == 'GET': return render(request, 'app/clients/edit.html', {'client': client}) elif request.method == 'POST': edit_form = ClientForm(request.POST, instance=client) if edit_form.is_valid(): client = edit_form.save(commit=False) client.from_home = request.POST.get('client_type') == 'home' client.save() return redirect('client', client_id=client_id) else: return render(request, 'app/clients/edit.html', { 'client': client, 'form': edit_form })
def edit(request): forms = [] if request.user.role.name == "client": client = Client.objects.get(user=request.user) forms.append(ClientForm(request.POST or None, instance=client)) elif request.user.role.name == "partner": partner = Partner.objects.get(user=request.user) forms.append(PartnerForm(request.POST or None, instance=partner)) user_form = UserForm(request.POST or None, instance=request.user) forms += [user_form, PasswordForm] if request.method == "GET": return render(request, "shared/editor.html", { "forms": forms, "index_link": reverse("index") }) elif request.method == "POST": password_form = PasswordForm(request.POST) additional = True if request.user.role.name == "client": client = Client.objects.get(user=request.user) form = ClientForm(request.POST or None, instance=client) forms.append(form) additional = form.is_valid() elif request.user.role.name == "partner": partner = Partner.objects.get(user=request.user) form = PartnerForm(request.POST or None, instance=partner) forms.append(form) additional = form.is_valid() if user_form.is_valid() and password_form.is_valid() and additional: if request.user.role.name in ("client", "partner"): form.save() user = user_form.save(commit=False) password = password_form.cleaned_data.get("password") if password and not user.check_password(password): user.set_password(password) user.save() return redirect("auth:logout") user.save() return redirect("index") else: return render(request, "shared/editor.html", { "forms": forms, "index_link": reverse("index") })
def dashboard(): if 'user' not in session: return redirect("/"), 302 user = load_user(session['user']) return render_template("dashboard.html", user=user, forms=dict(users=UserForm(), requests=RequestForm(), clients=ClientForm(), productions=ProductionForm(), roles=RoleForm()))
def register(): form = ClientForm() if form.validate_on_submit(): # hash the password of the form hashed = bcrypt.generate_password_hash( form.password.data).decode('utf-8') # create a new user/client instance with the form fields and commit to our database user = UserInfo(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, password=hashed) db.session.add(user) db.session.commit() flash( f'User {form.first_name.data} {form.last_name.data}has been created!You can now login in' ) return redirect(url_for('login')) else: flash('Failed') return render_template('register.html', form=form)
def new_client(): # TODO db = get_db() aids = [(x['name'], x['name']) for x in db.do_get_aid()] bags = [(x['bag_name'], x['bag_name']) for x in db.do_attenuator()] form = ClientForm(request.form) form.aid.choices = aids form.bag.choices = bags if request.method == 'GET': return render_template('new_client.html', form=form) elif request.method == 'POST' and form.validate(): db = get_db() db.do_new_client({ 'gender': 'M' if form.gender.data == 'Male' else 'F', 'dob': form.birthdate.data, 'start_date': form.start_date.data, 'street': form.street.data, 'city': form.city.data, 'state': form.state.data, 'zip': form.zipcode.data, 'apartment': form.apartment_num.data, 'firstname': form.first_name.data, 'lastname': form.last_name.data, 'phone': form.phone.data, 'bag_name': form.bag.data, 'pickup_day': form.pick_up_day.data }) flash("New client created!") # hack - pull the client-id result = db._sqlconn.execute( ''.join([ 'SELECT * FROM clients WHERE firstname = ? ', 'AND lastname = ?' ]), (form.first_name.data, form.last_name.data)) client_id = db._row_to_dict(result)[0]['id'] if form.aid.data: db.do_client_add_aid(client_id, form.aid.data) return redirect('clients/family/{}/'.format(client_id)) else: print "validation failed" return render_template('new_client.html', form=form)
def cadastrar_propriedade(): if 'logged_in' in session: print(session['id_usuario']) admin = Administrador.query.filter_by(id_usuario=session['id_usuario']).first() if admin is not None and admin.client is None: form = ClientForm() if form.validate_on_submit(): admin.client = Client() admin.client.component = ModuloPrivado(form.nome.data) db.session.commit() flash('Propriedade cadastrada') return redirect(url_for('dashboard.index')) return render_template('dashboard/cadastrar_propriedade.html', form=form) else: flash('Você já tem uma propriedade ou não é administrador do sistema') return redirect('/dashboard/') else: flash('Entre primeiro') return redirect('/')
def new_client(): # TODO db = get_db() aids = [(x['name'], x['name']) for x in db.do_get_aid()] bags = [(x['bag_name'], x['bag_name']) for x in db.do_bag_list()] form = ClientForm(request.form) form.aid.choices = aids form.bag.choices = bags if request.method == 'GET': return render_template('new_client.html', form=form) elif request.method == 'POST' and form.validate(): db = get_db() db.do_new_client({ 'gender': 'M' if form.gender.data == 'Male' else 'F', 'dob': form.birthdate.data, 'start_date': form.start_date.data, 'street': form.street.data, 'city': form.city.data, 'state': form.state.data, 'zip': form.zipcode.data, 'apartment': form.apartment_num.data, 'firstname': form.first_name.data, 'lastname': form.last_name.data, 'phone': form.phone.data, 'bag_name': form.bag.data, 'pickup_day': form.pick_up_day.data }) flash("New client created!") # hack - pull the client-id result = db._sqlconn.execute(''.join([ 'SELECT * FROM clients WHERE firstname = ? ', 'AND lastname = ?' ]), (form.first_name.data, form.last_name.data)) client_id = db._row_to_dict(result)[0]['id'] if form.aid.data: db.do_client_add_aid(client_id, form.aid.data) return redirect('clients/family/{}/'.format(client_id)) else: print "validation failed" return render_template('new_client.html', form=form)
def create_client(): """Register user. .. note:: The body need to be json type. :url: http://3.9.215.67:9999/api/v1/register :method: POST :param account: email. :type account: str :param password: at least 6 digits. :type password: str :return: result :example: `{ "account": "*****@*****.**", "password":"******"}` """ form = ClientForm(data=request.json) form.validate_for_api() switch = { ClientTypeEnum.Email: _register_user_by_email, } switch[form.type.data]() return Success()
def hello_world(): form = ClientForm(request.form) return render_template('index.html', async_mode=socketio.async_mode, form=form)
def createClient(request): form = ClientForm() return render(request, 'clients/create.html', {'form': form})
def create_client(): form = ClientForm() if form.validate_on_submit(): form.save(current_user) return redirect(url_for('home.index')) return render_template('auth/create_client.html', form=form)
def add_client(): form = ClientForm() if form.validate_on_submit(): client = controllers.add_client(form) return redirect(url_for('client', id=client.id)) return render_template('new_client.html', form=form)