def create_user(): form = EnterForms.CreateUser(request.form) data = EnterpriseAPI.GetUsers() if request.method == 'POST': if request.form['submit'] == 'Submit' and form.validate(): try: usrname, pswd = EnterpriseAPI.CreateUser( session['username'], session['password'], request.form['firstname'], request.form['lastname'], request.form['company'], request.form['position'], request.form['department'], request.form['email'], request.form['phone1'], request.form['phone2'], request.form.getlist('role-check'), request.form.getlist('appr-check')) msg = Message('New Enterprise Account', recipients=[str(request.form['email'])]) msg.body = "Dear {}, \n Thank you for using Enterprise. please note that your username is: {} and your password is {}. \n It is highly recommended that you change your password as soon as possible. \n Thank you for using Enterprise.".format( str(request.form['firstname']), str(usrname), str(pswd)) app.mail.send(msg) flash('User Created Successfully', category='success') return redirect(url_for('users.create_user')) except Exception as e: flash(str(e), category='fail') return render_template('users/create_user.html', username=session['username'], role=session['role'], data=data, form=form) return render_template('users/create_user.html', username=session['username'], role=session['role'], data=data, form=form)
def edit_provider(prv): form = EnterForms.ProvidersForm(request.form) data = EnterpriseAPI.GetProviders() data1 = EnterpriseAPI.FetchProvider(session['username'], session['password'], prv) if request.method == 'POST': if request.form['submit'] == 'Submit' and form.validate(): try: EnterpriseAPI.UpdateProvider( session['username'], session['password'], prv, request.form['name'], request.form['address'], request.form['phone1'], request.form['phone2'], request.form['email'], request.form['pobox'], request.form['description']) flash('Provider updated successfully', category='success') return redirect(url_for('invoices.Providers')) except Exception as e: flash(str(e), category='fail') return redirect(url_for('invoices.Providers')) return render_template('invoices/edit_provider.html', username=session['username'], role=session['role'], form=form, data=data, data1=data1)
def items(): form = EnterForms.ItemsForm(request.form) data = EnterpriseAPI.GetItems() form.Group.choices = EnterpriseAPI.Groups() form.SecondaryUnit.choices = EnterpriseAPI.SecondaryUnits() form.Provider.choices = EnterpriseAPI.ProvidersList() if request.method == 'POST': if request.form['submit'] == 'Submit' and form.validate(): try: EnterpriseAPI.CreateItem( session['username'], session['password'], request.form['ItemName'], request.form['Brand'], request.form['Provider'], request.form['Unit'], request.form['UnitPrice'], request.form['UnitCost'], request.form['Description'], request.form['Size'], request.form['Color'], request.form['SKU'], request.form['PartNumber'], request.form['IEME'], request.form['Length'], request.form['Width'], request.form['Height'], request.form['Diameter'], request.form['LengthUnit'], request.form['WidthUnit'], request.form['HeightUnit'], request.form['DiamaterUnit'], request.form['Group'], request.form['Category'], request.form['SecondaryUnit']) flash('Item added successfully', category='success') return redirect(url_for('invoices.items')) except Exception as e: flash(str(e), category='fail') return redirect(url_for('invoices.items')) return render_template('invoices/items.html', username=session['username'], role=session['role'], form=form, data=data)
def ForgotPassword(): form = EnterForms.ForgotPassword(request.form) if request.method == 'POST': if request.form['submit'] == 'Submit': try: usr, token = ForgotPasswordToken(request.form['email']) if token is not None: msg = Message('New Enterprise Account', recipients=[str(request.form['email'])]) msg.body = "Dear {}:\n please follow the link below to change your password. \n Thank you for using Enterprise. \n {}".format( usr[0], url_for('ChangeForgotPassword', usr=usr[1], token=token, _external=True)) mail.send(msg) flash('An email was sent to your email account', category='success') return redirect(url_for('ForgotPassword')) else: flash('Email not found', category='fail') return redirect(url_for('ForgotPassword')) except Exception as e: flash(str(e), category='fail') return redirect(url_for('ForgotPassword')) return render_template('forgot_password.html', form=form)
def edit_warehouse(code): form = EnterForms.BinsForm(request.form) whh = EnterpriseAPI.FetchWarehouse(code) wh = EnterpriseAPI.GetWareHouses() bins = EnterpriseAPI.GetBins(code) if request.method == 'POST': if request.form['submit'] == 'Submit': try: EnterpriseAPI.UpdateWarehouse(session['username'], session['password'], code, request.form['Name'], request.form['Location'], request.form['Description']) flash('Warehouse Updated Successfully', category='success') return redirect(url_for('logistics.create_warehouse')) except Exception as e: flash(str(e), category='fail') return redirect(url_for('logistics.create_warehouse')) return render_template('logistics/edit_warehouse.html', whh=whh, wh=wh, bins=bins, username=session['username'], role=session['role'], form=form, code=code)
def change_password(user): form = EnterForms.ChangePassword(request.form) if request.method == 'POST': if request.form['submit'] == 'Submit' and form.validate(): try: EnterpriseAPI.ChangePassword(user, request.form['currentpswd'], request.form['newpswd']) flash('Password changed successfully', category = 'success') return redirect(url_for('profile.change_password', user = user)) except Exception as e: flash(str(e), category = 'fail') else: flash('Passwords must match', category = 'fail') return render_template('profile/change_password.html', username = session['username'], role = session['role'], user = user, form = form) return render_template('profile/change_password.html', username = session['username'], role = session['role'], user = user, form = form)
def login(): form = EnterForms.LoginForm(request.form) if request.method == 'POST': if request.form['submit'] == 'Login' and form.validate(): username = request.form['usrname'] passwd = request.form['passwd'] logger = Logger(username, passwd) if logger['logged'] == True: session['username'] = logger['username'] session['password'] = logger['password'] session['role'] = logger['role'] return redirect(url_for('home')) elif logger['logged'] == False: flash('LOGIN ERROR: Bad username or password', category='fail') return render_template('login.html', form=form) return render_template('login.html', form=form)
def ChangeForgotPassword(token): form = EnterForms.ChangePassword(request.form) usr = VerifyToken(token) if usr: if request.method == 'POST': if request.form['submit'] == 'Submit' and request.form[ 'newpswd'] == request.form['confirm']: try: ChangePassword1(usr, request.form['newpswd']) flash('Password changed...', category='success') return redirect(url_for('login')) except Exception as e: flash(str(e), category='fail') return redirect(url_for('login')) return render_template('change_forgot_password.html', form=form, token=token) else: return render_template('invalid_token.html')
def Services(): AllServices = InvoicesAPI.GetAllServices() form = EnterForms.Services(request.form) if request.method == 'POST': if request.form['submit'] == 'Submit': try: InvoicesAPI.CreateService( session['username'], session['password'], request.form['servicename'], request.form['servicetype'], request.form['servicecost'], request.form['serviceprice'], request.form['description']) flash('Service Successfully created...', category='success') return redirect(url_for('invoices.Services')) except Exception as e: flash(str(e), category='fail') return redirect(url_for('inoices.Services')) return render_template('invoices/services.html', username=session['username'], role=session['role'], form=form, AllServices=AllServices)
def Customers(): form = EnterForms.CustomersForm(request.form) data = InvoicesAPI.GetAllCustomers() if request.method == 'POST': if request.form['submit'] == 'Submit' and form.validate(): try: InvoicesAPI.CreateCustomer( session['username'], session['password'], request.form['name'], request.form['address'], request.form['phone1'], request.form['phone2'], request.form['email'], request.form['pobox'], request.form['description']) flash('Provider added Successfully', category='success') return redirect(url_for('invoices.Customers')) except Exception as e: flash(str(e), category='fail') return redirect(url_for('invoices.Customers')) return render_template('invoices/customers.html', username=session['username'], role=session['role'], form=form, data=data)
def create_warehouse(): form = EnterForms.WarehouseForm(request.form) wh = EnterpriseAPI.GetWareHouses() if request.method == 'POST': if request.form['submit'] == 'Submit': try: EnterpriseAPI.CreateWarehouse(session['username'], session['password'], request.form['Name'], request.form['Code'], request.form['Location'], request.form['Description']) flash('Warehouse Created Successfully', category='success') return redirect(url_for('logistics.create_warehouse')) except Exception as e: flash(str(e), category='fail') return redirect(url_for('logistics.create_warehouse')) return render_template('logistics/create_warehouse.html', form=form, wh=wh, username=session['username'], role=session['role'])
def Providers(): form = EnterForms.ProvidersForm(request.form) data = EnterpriseAPI.GetProviders() wh = EnterpriseAPI.GetWareHouses() if request.method == 'POST': if request.form['submit'] == 'Submit' and form.validate(): try: EnterpriseAPI.CreateProvider( session['username'], session['password'], request.form['name'], request.form['address'], request.form['phone1'], request.form['phone2'], request.form['email'], request.form['pobox'], request.form['description']) flash('Provider added Successfully', category='success') return redirect(url_for('logistics.Providers')) except Exception as e: flash(str(e), category='fail') return redirect(url_for('logistics.Providers')) return render_template('logistics/providers.html', username=session['username'], role=session['role'], form=form, data=data, wh=wh)