def post(self): user = users.get_current_user() a = Accounts(name=self.request.get('name'), amount=float(self.request.get('amount'))) a.put() logging.info('************ ' + user.nickname() + ' Added Account ' + a.name + ' *******') return webapp2.redirect('/view_accounts')
def add_hairdressers(session): session.add( Accounts(id=uuid.uuid4().hex, email="*****@*****.**", hashed_password="******", created_at=datetime.datetime(2020, 5, 17), first_name="Jan", last_name="Testowy", account_type="hairdresser", salon_id=None)) session.add( Accounts(id=uuid.uuid4().hex, email="*****@*****.**", hashed_password="******", created_at=datetime.datetime(2020, 5, 17), first_name="Marcin", last_name="Testowin", account_type="hairdresser", salon_id=None)) session.add( Accounts(id=uuid.uuid4().hex, email="*****@*****.**", hashed_password="******", created_at=datetime.datetime(2020, 5, 17), first_name="Krzysztof", last_name="Nowak", account_type="hairdresser", salon_id=None))
def post(self): username = self.request.get("uName") password = self.request.get("pass") acc = Accounts(Username=username, Password=password) acc.put() var_dict = { "all_acc": Accounts.query().fetch(), "user": username, "pass": password } print(var_dict["all_acc"]) result_template = the_jinja_env.get_template('/HTML/search.html') self.response.write(result_template.render(var_dict))
def signUp(): # 处理从微信小程序端传来的注册请求 result = {} if request.method == "POST": form = request.json print(form) session = sessionmaker(bind=engine) sess = session() if sess.query(Accounts).filter_by(usr_open_id=form['openid']).count() >= 1: sess.close() result['result'] = 'double sign' return jsonify(result) else: if sess.query(Accounts).filter_by(usr_name=form['author']).count() >= 1: sess.close() result['result'] = 'same user name' return jsonify(result) else: pwd = generate_password_hash(form['pwd']) obj1 = Accounts(usr_name=form['author'], usr_authority=1, usr_open_id=form['openid'], usr_pwd=pwd) sess.add(obj1) sess.commit() sess.close() result['result'] = 'success' return jsonify(result)
def post(self): token = self.request.get("current_user") logged = Accounts.query(Accounts.tokens == token).get() id = self.request.get("id") i = product = Products.query(Products.id == id).get() self.redirect("/counterupload?current_user="******"&id=" + i.id)
def post(self): college = self.request.get("college") size = self.request.get("size") color = self.request.get("color") wid = self.request.get("id") i = Products.query(Products.id == wid).get() counter = i.id neck_type = self.request.get("neck_type") sleeve_type = self.request.get("sleeve_type") picture = self.request.get('img') picture = images.resize(picture, 256, 256) token = self.request.get("current_user") logged = Accounts.query(Accounts.tokens == token).get() id = id_generator() current_account = {"logged": logged} product = Products(college=college, size=size, color=color, counter=counter, neck_type=neck_type, sleeve_type=sleeve_type, picture=picture, tokens=token, id=id) product.put() self.redirect("/welcome?current_user=" + logged.tokens)
def dbtest_init(): # f = open('article1.txt') # str = f.read().decode('ascii').encode('utf-8') # f.close() Connection = sessionmaker(bind=engine) conn = Connection() obj1 = Accounts(usr_name='郭省五', usr_authority=1) obj2 = Accounts(usr_name='郭省四', usr_authority=1) obj3 = Accounts(usr_name='郭省六', usr_authority=1) conn.add(obj1) conn.add(obj2) conn.add(obj3) conn.commit() conn.close()
def check_revenue_acct(fd): fdat = Focusareas.query.filter(Focusareas.Focusid == fd).first() if fdat is not None: focus = stripper(fdat.Name) co = fdat.Co revacct = f'{focus} Revenues' adat = Accounts.query.filter((Accounts.Name == revacct) & (Accounts.Co == co)).first() if adat is not None: return revacct else: #Need to add this revenue account input = Accounts(Name=revacct, Balance=0.00, AcctNumber=None, Routing=None, Payee=None, Type='Income', Description='Focus Area Revenue', Category='Direct', Subcategory=focus, Taxrollup='Income:Gross receipts or sales', Co=co, QBmap=None, Shared=None) db.session.add(input) db.session.commit() return revacct else: return 'Error'
def post(self): token = self.request.get("current_user") logged = Accounts.query(Accounts.tokens == token).get() dele = self.request.get("del") d = Products.query(Products.id == dele).get() d.key.delete() self.redirect('/welcome?current_user=' + logged.tokens)
def get(self): home_template = \ jinja_current_directory.get_template('templates/home.html') token = self.request.get("current_user") logged = Accounts.query(Accounts.username == token).get() current_account = {"logged": logged} self.response.write(home_template.render(current_account))
def get(self): upload_template = \ jinja_current_directory.get_template('templates/upload.html') token = self.request.get("current_user") logged = Accounts.query(Accounts.tokens == token).get() current_account = {"logged": logged} self.response.write(upload_template.render(current_account))
def account_register(request): response = {} try: hasAccount = Accounts.objects.filter(telphone=request.POST['telphone']) if (hasAccount): response['msg'] = 'registerd telphone' response['error_num'] = 0 return JsonResponse(response) account = Accounts(telphone=request.POST['telphone'], password=request.POST['password'], nickname=request.POST['nickname']) account.save() response['msg'] = 'success' response['error_num'] = 0 except Exception, e: response['msg'] = str(e) response['error_num'] = 1
def post(self): for i in Products.query().fetch(): if i.id == self.request.get("tag"): token = self.request.get("current_user") logged = Accounts.query(Accounts.tokens == token).get() self.redirect("/desc?current_user="******"&id=" + i.id) elif self.request.get("search_btn") == "Search": token = self.request.get("current_user") logged = Accounts.query(Accounts.tokens == token).get() self.redirect("/marketplace?current_user="******"&size_=" + self.request.get("size") + "&color_=" + self.request.get("color") + "&neck_type_=" + self.request.get("neck_type") + "&sleeve_type_=" + self.request.get("sleeve_type") + "&college_=" + self.request.get("college"))
def test_account_obj(): return Accounts(id=uuid.uuid4().hex, email="*****@*****.**", hashed_password="******", created_at=datetime.datetime(2020, 5, 17), first_name="Marco", last_name="Polo", account_type="customer", salon_id=uuid.uuid4().hex)
def post(self): username = self.request.get("username") password = self.request.get("password") query = Accounts.query(Accounts.username == username, Accounts.password == password).fetch() if not query: self.redirect("/loginerror") else: self.redirect("/home?current_user=" + username)
def post(self): email = self.request.get("email") logged = Accounts.query(Accounts.email == email).get() if self.request.get( "login_btn" ) == "Login" and logged.password == self.request.get("password"): self.redirect('/welcome?current_user='******'/creation')
def get(self): user = users.get_current_user() nickname = user.nickname() logging.info('************ ' + user.nickname() + ' on View Accounts*******') if user: accts = Accounts.all().filter('owner =', user).order('name') self.render_template('view_accounts.html', {'accts': accts,'nickname':nickname},) else: self.redirect(users.create_login_url(self.request.uri))
def add_account(name, password): password = generate_password_hash(password) try: user = Accounts(name, str(password), USER_ACCOUNT) db.session.add(user) db.session.commit() except: db.session.rollback() raise
def post(self, customer_id): """ post: summary: Create a new account for given customer. parameters: "account_type": <string> "balance": <float> "account_number": <string> "routing_number": <string> "status": <string> "active": <bool> responses: 200: Returns JSON object of the account that was created. 400: Bad Request: Most likely a param is missing 500: Internal Server Error """ try: customer = Customers.query.filter_by(id=customer_id).first() account = Accounts( customer=customer, customer_id=customer.id, account_type=request.values['account_type'], balance=request.values['balance'], account_number=request.values['account_number'], routing_number=request.values['routing_number'], status=request.values['status'], active=bool(request.values['active']) ) db.session.add(account) db.session.commit() return jsonify(account.serialize()) except BadRequestKeyError as e: app.logger.error(str(e)) return{"error": "Bad Request"}, status.HTTP_400_BAD_REQUEST except Exception as e: app.logger.error(str(e)) return {"error": "Internal Server Error"}, status.HTTP_500_INTERNAL_SERVER_ERROR
def post(self): if self.request.get("create_btn") == "Submit": email = self.request.get("email") password = self.request.get("password") mailing_address = self.request.get("mailing_address") first_name = self.request.get("first_name") last_name = self.request.get("last_name") token = id_generator() account = Accounts(email=email, password=password, mailing_address=mailing_address, first_name=first_name, last_name=last_name, tokens=token) account.put() self.redirect('/') else: self.redirect('/')
def add_customers(session): session.add( Accounts(id=uuid.uuid4().hex, email="*****@*****.**", hashed_password="******", created_at=datetime.datetime(2020, 5, 17), first_name="Marco", last_name="Polo", account_type="customer", salon_id=None))
def post(self): for i in Products.query().fetch(): if i.id == self.request.get("tag"): token = self.request.get("current_user") logged = Accounts.query(Accounts.tokens == token).get() self.redirect("/desc?current_user="******"&id=" + i.id) elif self.request.get("back_btn") == "Go Back": token = self.request.get("current_user") self.redirect("/defmarketplace?current_user=" + token)
def signup(request, sse): try: data = json.loads(request.data) if not data: return jsonify(error=True, message='request body is empty, check headers/data') print(data) username = str(data['username']).encode() account_email = str(data['account_email']).encode() booking_email = str(data['booking_email']).encode() account_type = str(data['account_type']).encode() password = str(data['password']).encode() hashed = bcrypt.hashpw(password, bcrypt.gensalt()) check_username = db_session.query(Accounts).filter_by( username=username).first() check_account_email = db_session.query(Accounts).filter_by( email=account_email).first() check_booking_email = db_session.query(Accounts).filter_by( booking_email=booking_email).first() if check_username: return jsonify(error=True, message='username is already in use') if check_account_email: return jsonify(error=True, message='account email is already in use') if check_booking_email: return jsonify(error=True, message='booking email is already in use') new_account = Accounts(username=username, email=account_email, booking_email=booking_email, password=hashed, type=account_type) db_session.add(new_account) db_session.commit() session_id = chamber.uniqueValue() user_session['session_id'] = session_id user_session['account_id'] = new_account.id user_session['account_type'] = new_account.type return jsonify(message='Signed Up!') except Exception as err: print(err) return jsonify(error=True, errorMessage=str(err), message='error signing up...')
def get(self): confirm_template = \ jinja_current_directory.get_template('templates/confirm.html') id = self.request.get("id") dele = self.request.get("del") d = Products.query(Products.id == dele).get() product = Products.query(Products.id == id).get() logged = Accounts.query(Accounts.tokens == product.tokens).get() dict = {"product": product, "logged": logged, "dele": dele} self.response.write(confirm_template.render(dict))
def get(self): reply_template = \ jinja_current_directory.get_template('templates/reply.html') token = self.request.get("current_user") ids = self.request.get("id") logged = Accounts.query(Accounts.tokens == token).get() id = self.request.get("id") offers = Products.query().filter(Products.counter == id).fetch() dict = {"offers": offers, "token": token, "ids": ids} self.response.write(reply_template.render(dict))
def post(self): token = self.request.get("current_user") logged = Accounts.query(Accounts.tokens == token).get() current_account = {"logged": logged} if self.request.get("upload_btn") == "upload": self.redirect("/upload?current_user="******"status_btn") == "status": self.redirect("/status?current_user="******"market_btn") == "marketplace": self.redirect("/defmarketplace?current_user="******"log_btn") == "Logout": self.redirect("/")
def get(self): status_template = \ jinja_current_directory.get_template('templates/status.html') token = self.request.get("current_user") logged = Accounts.query(Accounts.tokens == token).get() request = Products.query().filter(Products.tokens == logged.tokens, Products.counter != "").fetch() requests = [] for i in request: requests.append( Products.query().filter(Products.id == i.counter).get()) offers = Products.query().filter(Products.tokens == logged.tokens, Products.counter == "").fetch() dict = {"requests": requests, "offers": offers, "token": token} self.response.write(status_template.render(dict))
def register_user( email: str, raw_password: str, first_name: str, last_name: str, account_type: str, salon_id: str, ) -> dict: """ Registers the user by creating an account record in the database :param email: email of the user :param raw_password: direct password provided by the user into the form :param first_name: first name of the user :param last_name: last name of the user :param account_type: user or hairdresser :param salon_id: ID of the salon, in case the user is a hairdresser :return: Payload with data regarding the registration """ payload = dict() payload["success"] = False payload["email_taken"] = user_with_given_email_exists(email) if payload["email_taken"]: return payload if account_type == "hairdresser": if not salon_has_hairdresser_spot(salon_id): return payload account_id = uuid.uuid4().hex password = sha256_crypt.hash(raw_password) new_user = Accounts(id=account_id, email=email, hashed_password=password, created_at=datetime.datetime.utcnow(), first_name=first_name, last_name=last_name, account_type=account_type, salon_id=salon_id) try: with session_scope() as session: session.add(new_user) payload["success"] = True except IntegrityError: return payload return payload
def signUp(): global users if request.method == "POST": form = request.json session = sessionmaker(bind=engine) sess = session() if sess.query(Accounts).filter_by( usr_open_id=form['openid']).count() >= 1: abort(500) else: pwd = generate_password_hash(form['pwd']) obj1 = Accounts(usr_name=form['author'], usr_authority=1, usr_open_id=form['openid'], usr_pwd=pwd) sess.add(obj1) sess.commit() sess.close() # print(request.json) # users[request.json['openid']] = request.json # print(users) return "signup success"
def signup(signup_request): same_name_count = session.query(Accounts).filter_by( name=signup_request['name']).count() same_email_count = session.query(Accounts).filter_by( email=signup_request['email']).count() if same_email_count > 0 or same_name_count > 0: return 'CREDENTIALS_ALREADY_EXIST' index = ''.join( random.choice(string.ascii_lowercase + string.digits) for _ in range(40)) elasticsearch_service.create_index(index) new_account = Accounts( name=signup_request['name'], email=signup_request['email'], password=hashlib.sha256( signup_request['password'].encode('utf=8')).hexdigest(), index=index) session.add(new_account) session.commit() return 'ACCOUNT_CREATED'
def isoAM(): if request.method == 'POST': # ____________________________________________________________________________________________________________________B.FormVariables.General from viewfuncs import parseline, popjo, jovec, newjo, timedata, nonone, nononef, stripper, check_shared, check_mirror_exp from viewfuncs import numcheck, numcheckv, viewbuttons, get_ints, numcheckvec, erud, hasinput, get_tmap, get_qmap #Zero and blank items for default username = session['username'].capitalize() cache=0 modata=0 modlink=0 scdata=0 tmap = None fmap = None qmap = None gmap = None today = datetime.date.today() now = datetime.datetime.now().strftime('%I:%M %p') modify = request.values.get('Qmod') shared = request.values.get('Shared') returnhit = request.values.get('Return') deletehit = request.values.get('Delete') # hidden values update = request.values.get('Update') newact=request.values.get('NewA') thisjob=request.values.get('ThisJob') oder=request.values.get('oder') modlink = request.values.get('modlink') companyon = request.values.get('actype') if companyon is None: companyon='Show All Accounts' oder=nonone(oder) modlink=nonone(modlink) leftscreen=1 err=[] if returnhit is not None: modlink=0 # ____________________________________________________________________________________________________________________E.FormVariables.General # ____________________________________________________________________________________________________________________B.DataUpdates.General if modlink==1: if oder > 0: modata=Accounts.query.get(oder) vals=['acctname','accttype','acctcat','acctsub','acctnumb','acctrout','acctpaye','acctdesc','accttax','acctco','qbmap'] a=list(range(len(vals))) for i,v in enumerate(vals): a[i]=request.values.get(v) modata.Name=a[0] modata.Type=a[1] if a[1] is not None: adat = Accttypes.query.filter(Accttypes.Name==a[1]).first() if adat is not None: defcat = adat.Category defsub = adat.Subcategory if a[2] is None: modata.Category = defcat else: modata.Category=a[2] if a[3] is None: modata.Subcategory = defsub else: modata.Subcategory=a[3] modata.AcctNumber=a[4] modata.Routing=a[5] modata.Payee=a[6] modata.Description=a[7] modata.Taxrollup=a[8] modata.Co=a[9] modata.QBmap = a[10] db.session.commit() err.append('Modification to Account id ' + str(modata.id) + ' completed.') # Narrow the selection boxes for company and type print('a[1]', a[1]) print(hasinput(a[1])) if hasinput(a[1]): fmap = Focusareas.query.filter(Focusareas.Co == a[9]).all() gmap = Taxmap.query.filter(Taxmap.Category.contains('deductions')).all() tmap = get_tmap(a[1], a[2]) qmap = get_qmap(a[1], a[2]) if update is not None: modlink=0 leftsize=10 else: leftsize=6 modata=Accounts.query.get(oder) # ____________________________________________________________________________________________________________________B.GetData.General if companyon == 'Show All Accounts': odata = Accounts.query.all() elif companyon == 'Show Shared Accounts': odata = Accounts.query.filter(Accounts.Shared != None).all() elif ':' in companyon: comp,focus = companyon.split(':') print(comp,focus) odata = Accounts.query.filter( (Accounts.Co==comp) & (Accounts.Subcategory==focus) ).all() else: odata = Accounts.query.filter((Accounts.Co.contains(companyon))).all() # ____________________________________________________________________________________________________________________B.Search.General if modlink==0: oder,numchecked=numcheck(1,odata,0,0,0,0,['oder']) else: numchecked = 0 # ____________________________________________________________________________________________________________________E.Search.General if shared is not None: if oder > 0 and numchecked == 1: odat = Accounts.query.get(oder) atype = odat.Type if atype == 'Expense': co1 = odat.Co thisdat = Divisions.query.filter(Divisions.Co == co1).first() co1name = thisdat.Name otherdat = Divisions.query.filter(Divisions.Co != co1).first() sid = otherdat.id co2 = otherdat.Co co2name = otherdat.Name err.append(f'Account **{odat.Name}** owned by code {odat.Co}') err.append(f'Is now set up for share with {otherdat.Name} code {otherdat.Co}') # Now check to see if the sharing accounts exist and if not create them fromtoid, err = check_shared(co1,co2name, err) tofromid, err = check_shared(co2,co1name, err) mirrorexpid, err = check_mirror_exp(co2,odat.id,odat.Name,err) slist = json.dumps([sid,fromtoid,tofromid,mirrorexpid]) odat.Shared = slist db.session.commit() mirrordat = Accounts.query.get(mirrorexpid) mirrordat.Shared = slist db.session.commit() if companyon == 'Show All Accounts': odata = Accounts.query.all() elif companyon == 'Show Shared Accounts': odata = Accounts.query.filter(Accounts.Shared != None).all() else: odata = Accounts.query.filter((Accounts.Co.contains(companyon))).all() else: err.append(f'Cannot share: {odat.Name} of type {atype}') err.append(f'Can only share and apportion **Expense** accounts') else: err.append(f'Must select one account to use this option') # ____________________________________________________________________________________________________________________B.Modify.General if modify is not None and numchecked==1 : modlink=1 leftsize=6 if oder>0: modata=Accounts.query.get(oder) err.append(f'Modify {modata.Name}:{modata.Co}:{modata.Type}') if hasinput(modata.Type): fmap = Focusareas.query.filter(Focusareas.Co == modata.Co).all() gmap = Taxmap.query.filter(Taxmap.Category.contains('deductions')).all() tmap = get_tmap(modata.Type, modata.Category) qmap = get_qmap(modata.Type, modata.Category) if modify is not None and numchecked!=1: modlink=0 err.append('Must check exactly one box to use this option') # ____________________________________________________________________________________________________________________E.Modify.General # ____________________________________________________________________________________________________________________B.Delete.General if deletehit is not None and numchecked==1: if oder>0: #This section is to determine if we can delete the source file along with the data. If other data is pointing to this #file then we need to keep it. modata=Accounts.query.get(oder) Accounts.query.filter(Accounts.id == oder).delete() db.session.commit() if companyon == 'Show All Accounts': odata = Accounts.query.all() elif companyon == 'Show Shared Accounts': divdata = Divisions.query.all() tester = '' for div in divdata: tester = tester + div.Co odata = Accounts.query.filter(Accounts.Co.like(tester)).all() else: odata = Accounts.query.filter((Accounts.Co.contains(companyon))).all() if deletehit is not None and numchecked != 1: err.append('Must have exactly one item checked to use this option') # ____________________________________________________________________________________________________________________E.Delete.General # ____________________________________________________________________________________________________________________B.Newjob.General if newact is not None: modlink=10 leftsize=6 modata=Accounts.query.get(1) if modata is not None: modata.Name='' modata.Type=None modata.Category=None modata.Subcategory=None modata.AcctNumber='' modata.Routing='' modata.Payee='' modata.Description='' modata.Taxrollup=None modata.Co=None modata.QBmap = None if newact is None and modlink==10: #Create the new database entry for the source document acctname=request.values.get('acctname') acctnumb=request.values.get('acctnumb') acctrout=request.values.get('acctrout') acctpaye=request.values.get('acctpaye') accttype=request.values.get('accttype') acctdesc=request.values.get('acctdesc') acctcat=request.values.get('acctcat') acctsub=request.values.get('acctsub') accttax=request.values.get('accttax') acctco=request.values.get('acctco') qbmap = request.values.get('qbmap') acctname = stripper(acctname) adat = Accounts.query.filter((Accounts.Name==acctname) & (Accounts.Co==acctco)).first() if adat is not None: err.append(f'Account with name {acctname} for {acctco} already exists') else: input = Accounts(Name=acctname,Balance=0.00,AcctNumber=acctnumb,Routing=acctrout,Payee=acctpaye,Type=accttype, Description=acctdesc,Category=acctcat,Subcategory=acctsub,Taxrollup=accttax,Co=acctco,QBmap=qbmap, Shared=None) db.session.add(input) db.session.commit() # Narrow the selection boxes for company and type if hasinput(accttype): print('acctco',acctco) fmap = Focusareas.query.filter(Focusareas.Co == acctco).all() gmap = Taxmap.query.filter(Taxmap.Category.contains('deductions')).all() tmap = get_tmap(accttype, 0) qmap = get_qmap(accttype, 0) odata = Accounts.query.all() modata = odata[-1] oder=modata.id modlink=1 # ____________________________________________________________________________________________________________________E.Newjob.General #This is the else for 1st time through (not posting data from overseas.html) else: from viewfuncs import popjo, jovec, timedata, nonone, nononef, init_truck_zero, erud today = datetime.date.today() #today = datetime.datetime.today().strftime('%Y-%m-%d') now = datetime.datetime.now().strftime('%I:%M %p') oder=0 cache=0 modata=0 modlink=0 scdata=0 odata = Accounts.query.all() companyon = 'Show All Accounts' leftscreen=1 leftsize=10 tmap = None fmap = None qmap = None gmap = None err = [] scdata=[] for odat in odata: catitem=odat.Category additem=odat.Subcategory if additem is not None and catitem is not None: if catitem=='G-A' and additem not in scdata: scdata.append(additem) scdata.sort() leftsize = 8 divdata = Divisions.query.all() colordict = {} for div in divdata: colordict.update({div.Co:div.Color}) print(colordict) err = erud(err) atypes = Accttypes.query.all() if fmap is None: fmap = Focusareas.query.all() return odata,oder,err,modata,modlink,leftscreen,leftsize,today,now,scdata,companyon,divdata,atypes,tmap,fmap,qmap, gmap, colordict
def accounts_test_addaccount(self): accounts = Accounts() account = accounts.addAccount("lqntest","katz") self.assertEqual(account.balance(),account.__startbalance__) self.assertEqual(account.realname, "lqntest") self.assertEqual(account.password, "katz")