def checkUser(username, password, signUp=False, email=False): """ This function takes username and password Returns if one of the following is the Case Case 1 : if user is not found = None Case 2 : if user is found a) if password is correct = True b) if password is incorrect = False """ if email: result = Database.find(collection=User.COLLECTION, query={"email": username}) else: result = Database.find(collection=User.COLLECTION, query={"username": username}) if signUp: if result: return User.getUser(result) return result if result: if check_password_hash(result.get("password"), password): return result else: return False
def isUser(form, field, login=False): Database.initialize('Prosfora') email = field.data.lower() isEmail = re.compile(r"[^@]+@[^@]+\.[^@]+") if len(email) > 100: raise ValidationError('Email or Username is too lengthy!') if isEmail.fullmatch(email): isUser_ = User.isUser(email=email) email = True else: isUser_ = User.isUser(username=email) email = False print(isUser_) if login: if not isUser_: raise ValidationError('Account Does Not exist!') else: if isUser_: if email: raise ValidationError('Email Already Taken!') raise ValidationError('Username Already Taken!')
def callback(): WinLog.update_log(f'<{winstr}> button pressed.') if winstr == 'populate': Database.execute(scripting=True, scriptfile='sample.sql') WinLog.update_log('Database: Populated data using <sample.sql>') else: WinManager.create_window(winstr)
async def log_light(request, current_user): request_json = await request.json() print(request_json) try: login = request_json['login'] except Exception as e: print(e) print("Login needed") if login != current_user: return Response(text="You have no power here!", status=403) redis = Database() llogin = login.lower() if redis.key_exists_in_hash('users:', llogin): db_entry = redis.get_hash('users:', llogin) user_dict = literal_eval(db_entry.decode('utf-8')) uuid = user_dict['id'] print(uuid) user_thingy_raw = redis.get_hash("user:%s" % uuid, "thingy") print("raw: ", user_thingy_raw) user_thingy = user_thingy_raw.decode('utf-8') print(user_thingy) name = 'light' esd_service = EnvironmentSensorDataService() esd_service.run_light_service(user_thingy, current_user, name) return web.Response(status=204)
def export_info(self): query = '''insert into phones (brand, name, storage, color, price, qty) values (?, ?, ?, ?, ?, ?);''' variables = (self.__brand, self.__name, self.__storage, self.__color, self.__price, self.__quantity) Database.execute(query, variables) WinLog.update_log('Database: Export query executed.')
def save_to_mongo(self): if product_idsschema.validate([self.json()]): Database.insert(collection='product_ids', data=self.json()) result = jsonify({'result': self.product_id + 'number added.'}) return result else: return 'Schema Not Matched'
def updateQuoteData(quoteID, quote=None, Download=None): """ Updates quote of Quote (in json) In Quote Collection If quote is updated: Returns True else: Returns None """ print('updateQuoteData being called') quote_ = Quote.GetByQuoteID(quoteID) if quote_: print('Quote found!') if quote: quote_.update({'quote': quote}) print('updating quote') if Download: totalD = quote_.get('totalDownloads', 0) quote_.update({'totalDownloads': totalD + 1}) print('updating downloads') Database.update(collection=Quote.COLLECTION, query={'quoteID': quoteID}, update_query=quote_) return True print('Quote not found!')
def get_energy_data(userid, datestr): print("start to get energy data") date = dateutil.parser.parse(datestr) db = Database() data = db.energy_detail(userid, date, date + datetime.timedelta(days=1)) return jsonify(result=data)
def save_to_mongo(self): if complaintcategoryschema.validate([self.json()]): Database.insert(collection='complaintcategory', data=self.json()) result = jsonify({'complaint_id': self.complaint_id}) return result else: return "Schema Not Matched"
def save_to_mongo(self): if cartschema.validate([self.json()]): Database.insert(collection='cart',data=self.json()) res = {'cart_id' : self.cart_id + ' added'} result= jsonify({'result' : res}) return result else: return "Schema not matched!"
def update_info(self): query = '''update phones set (brand, name, storage, color, price, qty) = (?, ?, ?, ?, ?, ?) where id = ?;''' variables = (self.__brand, self.__name, self.__storage, self.__color, self.__price, self.__quantity, self.__id) Database.execute(query, variables) WinLog.update_log('Database: Update query executed.')
async def logout(cls, login): redis = Database() llogin = login.lower() if redis.get_hash('sessions:', llogin): return redis.delete_hash('sessions:', llogin) return None
def save_to_mongo(self): if userguidanceschema.validate([self.json()]): Database.insert(collection='userguidance', data=self.json()) res = {'guidance_id': self.guidance_id + "Added"} result = jsonify({'result': res}) return result else: return "Schema not matched!"
def save_to_mongo(self): if employeeschema.validate([self.json()]): Database.insert(collection='users', data=self.json()) res = {'email': self.email + ' registered'} result = jsonify({'result': res}) return result else: return "Schema not matched!"
def changeEmail(_id, email): usr = User.getUserByID(_id) if usr: usr.update({'email': email}) Database.update(collection=User.COLLECTION, query={"_id": usr.get('_id')}, update_query=usr) return True
def homepage(): db = Database(url) routes = db.get_all_routes() for i in range(len(routes)): user_id = routes[i][1] username = db.get_username_by_id(user_id) routes[i] = routes[i] + username return render_template("homepage.html", routes=routes)
def save_to_mongo(self): if customersearchesschema.validate([self.json()]): Database.insert(collection='customersearches', data=self.json()) res = {'search_id': self.search_id + "Added"} result = jsonify({'result': res}) return result else: return "Schema not matched!"
def save_to_mongo(self): if productschema.validate([self.json()]): Database.insert(collection='products', data=self.json()) res = {'product_name': self.product_name + ' added'} result = jsonify({'result': res}) return result else: return "Schema not matched!"
def save_to_mongo(self): if tickets_feedbackschema.validate([self.json()]): Database.insert(collection='tickets_feedback', data=self.json()) res = {'ticket_id': self.ticket_id + ' added'} result = jsonify({'result': res}) return result else: return "Schema not matched!"
def save_to_mongo(self): if subcategoryschema.validate([self.json()]): Database.insert(collection='subcategories', data=self.json()) res = {'subcategory_name': self.subcategory_name + " added"} result = jsonify({'result': res}) return result else: return "Schema not matched!"
def get_cost_data(userid, datestr): print("start to get cost data") db = Database() date = dateutil.parser.parse(datestr) data = db.cost_detail(userid, date, date + datetime.timedelta(days=1)) print('ddd') return jsonify(result=data)
def GetByQuoteID(quoteID): JsonQuote = Database.find( collection=Quote.COLLECTION, query={'quoteID': quoteID}) print(quoteID) if JsonQuote: JsonQuote.update( {'created_at': Database.created_at(JsonQuote.get('_id'))}) return JsonQuote
def routes(): db = Database(url) routes = db.get_all_routes() is_admin = db.is_user_admin(current_user.id) for i in range(len(routes)): user_id = routes[i][1] username = db.get_username_by_id(user_id) routes[i] = routes[i] + username return render_template("routes.html", routes=routes, is_admin=is_admin)
def remove_professor(tid): """ remove the specified professor from history table :param tid: specified professor tid to delete :return: success message """ db = Database() db.delete_professor_by_tid(tid) return "deleted successfully!", 204
def changeUsername(_id, username): usr = User.getUserByID(_id) if usr: usr.update({'username': username}) Database.update(collection=User.COLLECTION, query={"_id": usr.get('_id')}, update_query=usr) return True
def fetch_all_professors(): """ get all the professors from the database :return: list of professors """ db = Database() result = db.get_all_professors() return {"data": result}, 200
def savePost(self): """ Saves Post into Database *Uses gridFS for storing binary data seperately for easy access """ if self.AlbumArt: self.AlbumArt = Database.saveFile(self.AlbumArt) self.content = Database.saveFile(self.content) return Database.insert(Post.COLLECTION, self.toJson())
def save_to_mongo(self): if inventoryschema.validate([self.json()]): Database.insert(collection='inventory', data=self.json()) result = jsonify( {'result': { 'product_id': self.product_id + 'added' }}) return result else: return "Schema not matched!"
def update_chosen_results_personal_audio( chosen_inline_result: types.ChosenInlineResult, db_conn: Database) -> None: sql_read = Constants.DBStatements.DB_AUDIOS_READ_FOR_CHOSEN_RESULT % \ (str(chosen_inline_result.from_user.id), int(chosen_inline_result.result_id)) result = db_conn.read_one(sql_read) if result: sql_update = Constants.DBStatements.DB_AUDIO_UPDATE_FOR_CHOSEN_RESULT % ( result[1] + 1, result[0]) db_conn.write_all(sql_update)
def updateUploads(_cu, val=1): usr = User.verifySession(_cu) if usr: totalUploads = usr.get('totalUploads') totalUploads += val usr.update({'totalUploads': totalUploads}) Database.update(collection=User.COLLECTION, query={"_id": usr.get('_id')}, update_query=usr) return True
__author__ = 'phoehne' import time from requests.auth import HTTPDigestAuth from models.database import Database from models.connection import Connection from models.server import HttpServer conn = Connection("localhost", HTTPDigestAuth("admin", "admin")) srvr = HttpServer.lookup("test-one-http", conn) if srvr: srvr.remove(conn) # TODO determine if the server is restarted time.sleep(30) db = Database.lookup("test-one", conn) db.remove(conn) mod = Database.lookup("test-one-modules", conn) mod.remove(conn)
#coding=utf-8 ''' Tables mapper ''' from sqlalchemy import Column, Integer, String, DateTime, Boolean from models.database import Base from models.database import Database Database.instance().create_db()