def recover_password_user(self, request): _message = None _status = self.interruption _entity = None _email = None try: _model = userModel() _entity = userEntity() _entity.requestToEmail(request) _entity = _model.get_password_by_id(_entity.mail) if _entity is None: _status = self.failUser _message = self.userDontExist else: _modelLogin = notificationModel() _modelLogin.sen_sms_message(_entity.password, _entity.cellphone) _status = self.OK _message = self.smsSuccess + str(_entity.cellphone) except (Exception) as e: _status = self.interruption _message = self.messageInterruption + str(e) print('error: ' + str(e)) return responseEntity(_status, _message, None).toJSON()
def wa_login_post(): _full_name = request.form.get("idTxtUsusario") _password = request.form.get("idTxtPassword") _entity = userEntity() _entity = loginController().login_user_web(_full_name,_password) if _entity is None: return redirect('/wa_login?error=1') else: session['full_name'] = _full_name return redirect('/wa_list_services')
def wa_change_password_post(): _full_name = request.form.get("idTxtUsusario") _password = request.form.get("idTxtPassword") _new_password = request.form.get("idTxtNewPassword") _confirm_password = request.form.get("idTxtConfirmNewPassword") _status = 0 _entity = userEntity() _entity = loginController().login_user_web(_full_name,_password) if _entity is None: _status = 1 else: if _new_password != _confirm_password: _status = 2 else: _entity = loginController().change_password_user_web(_full_name,_new_password) return redirect('/wa_change_password?status='+str(_status))
def update_user(self, request): _message = '' _status = self.interruption _userEntity = None try: _userEntity = userEntity() _userModel = userModel() _userEntity.requestUpdateToClass(request) _id = _userModel.update_user(_userEntity) _status = self.OK _message = self.messageOK except (Exception) as e: _status = self.interruption _message = self.messageInterruption + str(e) print('error: ' + str(e)) return responseEntity(_status, _message, _id).toJSON()
def delete_user(self, index): _message = None _status = self.interruption _userEntity = None try: _userModel = userModel() _userEntity = userEntity() _id = _userModel.delete_user(index) _userEntity.id = _id _status = self.OK _message = self.messageOK except (Exception) as e: _status = self.interruption _message = self.messageInterruption + str(e) print('error: ' + str(e)) return responseEntity(_status, _message, _userEntity).toJSON()
def add_user(self, request): _message = None _status = self.interruption _entity = None try: _entity = userEntity() _model = userModel() _entity.requestToClass(request) if _model.validate_mail(_entity.mail): _status = self.interruption _message = self.duplicatedMail else: _entity = _model.add_user(_entity) _status = self.OK _message = self.messageOK except (Exception) as e: _status = self.interruption _message = self.messageInterruption + str(e) print('error: ' + str(e)) return responseEntity(_status, _message, _entity).toJSON()
def login_user_web(self, full_name, password): _db = None _status = 1 _entity = None try: _full_name = full_name _password = password _db = Database() _db.connect(self.host, self.port, self.user, self.password, self.database) print('Se conecto a la bd') _con_client = _db.get_client() _sql = """SELECT u.id, u.full_name FROM main.user_web u WHERE u.status = %s AND u.full_name = %s AND u."password" = %s; """ _cur = _con_client.cursor() _cur.execute(_sql, ( _status, _full_name, _password, )) _rows = _cur.fetchall() if len(_rows) >= 1: _entity = userEntity() _entity.id = _rows[0][0] _entity.full_name = _rows[0][1] _cur.close() except (Exception) as e: self.add_log(str(e), type(self).__name__) finally: if _db is not None: _db.disconnect() print("Se cerro la conexion") return _entity
def get_user_by_sub_services(self, request): _message = None _status = self.interruption _data = None try: _model = userModel() _entity = userEntity() _sub_service = _entity.requestSubServiceToString(request) print(_sub_service) _data = _model.get_user_by_sub_services(_sub_service) if _data is None or len(_data) < 1: _status = self.OK _message = self.dontExistValues else: _status = self.OK _message = self.messageOK except (Exception) as e: _status = self.interruption _message = self.messageInterruption + str(e) print('error: ' + str(e)) return responseEntity(_status, _message, _data).toJSON()
def login_user(self, loginEntity): _db = None _status = 1 _userEntity = None try: _mail = loginEntity.mail _password = loginEntity.password _db = Database() _db.connect(self.host, self.port, self.user, self.password, self.database) print('Se conecto a la bd') _con_client = _db.get_client() _sql = """ SELECT up.id, up.mail , up.social_name , up.full_name , up.id_type_document , up.document_number , up.type_user , up.photo, up.cellphone , up.about FROM main.user_p up WHERE up.status = %s and up.mail = %s and up.password = %s;""" _cur = _con_client.cursor() _cur.execute(_sql, ( _status, _mail, _password, )) _rows = _cur.fetchall() if len(_rows) >= 1: _userEntity = userEntity() _userEntity.id = _rows[0][0] _userEntity.mail = _rows[0][1] _userEntity.social_name = _rows[0][2] _userEntity.full_name = _rows[0][3] _userEntity.id_type_document = _rows[0][4] _userEntity.document_number = _rows[0][5] _userEntity.type_user = _rows[0][6] _userEntity.photo = _rows[0][7] _userEntity.cellphone = _rows[0][8] _userEntity.about = _rows[0][9] _sql_fire_base = """UPDATE main.user_p SET id_fire_base_token = %s WHERE id = %s;""" _cur.execute(_sql_fire_base, ( loginEntity.id_fire_base_token, _userEntity.id, )) _con_client.commit() _cur.close() except (Exception) as e: print('error: ' + str(e)) finally: if _db is not None: _db.disconnect() print("Se cerro la conexion") return _userEntity
def get_load(self, id_customer): _db = None _status = 1 _data_row = [] _data_documents = [] _data_users = [] _data_delivery_costs = [] _data_banks = [] _id_customer = id_customer _loadEntity = None try: _loadEntity = loadEntity() _db = Database() _db.connect(self.host, self.port, self.user, self.password, self.database) print('Se conecto a la bd') _con_client = _db.get_client() _sql_services = """SELECT s.id, s.full_name, s.color, encode(s.file_image , 'base64') AS file_image, ss.id AS id_sub_service, ss.full_name AS sub_service_name, ss.in_filter FROM main.service s LEFT JOIN main.sub_service ss ON s.id = ss.id_service ORDER BY 1;""" _cur = _con_client.cursor() _cur.execute(_sql_services) _rows = _cur.fetchall() _id_service_old = None for row in _rows: _serviceEntity = serviceEntity() _serviceEntity.id = row[0] _serviceEntity.full_name = row[1] _serviceEntity.color = row[2] _serviceEntity.file_image = row[3].replace('\n', '') _sub_service = row[4] _sub_services = [] if _id_service_old != _serviceEntity.id: for se in _rows: if row[0] == se[0] and _sub_service is not None: _subServiceEntity = subServiceEntity() _subServiceEntity.id = se[4] _subServiceEntity.full_name = se[5] _subServiceEntity.in_filter = se[6] _subServiceEntity.id_service = se[0] _sub_services.append(_subServiceEntity) _serviceEntity.sub_services = _sub_services _data_row.append(_serviceEntity) _id_service_old = _serviceEntity.id _loadEntity.services = _data_row _sql_services = """SELECT id, full_name FROM main.type_document WHERE status = 1;""" _cur.execute(_sql_services) _rows = _cur.fetchall() for row in _rows: _typeDocumentoEntity = typeDocumentEntity() _typeDocumentoEntity.id = row[0] _typeDocumentoEntity.full_name = row[1] _data_documents.append(_typeDocumentoEntity) _loadEntity.type_documents = _data_documents _sql_delivery = """SELECT from_km, to_km, fixed_cost, delivery FROM main.delivery_cost;""" _cur.execute(_sql_delivery) _rows = _cur.fetchall() for row in _rows: _delivery_cost = deliveryCost() _delivery_cost.from_km = row[0] _delivery_cost.to_km = row[1] _delivery_cost.fixed_cost = row[2] _delivery_cost.delivery = row[3] _data_delivery_costs.append(_delivery_cost) _loadEntity.delivery_costs = _data_delivery_costs _sql_banks = """SELECT id, full_name FROM main.bank WHERE status = 1;""" _cur.execute(_sql_banks) _rows = _cur.fetchall() for row in _rows: _bankEntity = bankEntity() _bankEntity.id = row[0] _bankEntity.full_name = row[1] _data_banks.append(_bankEntity) _loadEntity.banks = _data_banks if (_id_customer != 0): _sql_users = """SELECT u.id, u.mail, u.social_name, u.full_name, u.id_type_document, u.document_number, u.type_user, u.photo, u.cellphone, u.about, us.id AS id_user_store, us.full_name AS name_user_store, us.address, us.longitude, us.latitude, us.main, b.avg_rate::float4 FROM main.user_p u INNER JOIN main.user_store us ON u.id = us.id_user INNER JOIN main.customer_user_favorite cf ON u.id = cf.id_user LEFT JOIN (SELECT cr.id_user, Avg(rate) avg_rate, Count(*) count_rate FROM main.customer_rate cr GROUP BY 1) b ON u.id = b.id_user WHERE cf.id_customer = %s and u.status = %s and cf."enable" = 1 AND us.status = 1 ORDER BY 1;""" _cur.execute(_sql_users, ( _id_customer, _status, )) _rows = _cur.fetchall() _id_user_old = None for row in _rows: _userEntity = userEntity() _userEntity.id = row[0] _userEntity.mail = row[1] _userEntity.social_name = row[2] _userEntity.full_name = row[3] _userEntity.id_type_document = row[4] _userEntity.document_number = row[5] _userEntity.type_user = row[6] _userEntity.photo = row[7] _userEntity.cellphone = row[8] _userEntity.about = row[9] _avg_rate = row[16] if _avg_rate is None: _avg_rate = 0 _userEntity.avg_rate = _avg_rate _user_stores = [] if _id_user_old != _userEntity.id: for se in _rows: if row[0] == se[0] and _userEntity is not None: _userStoreEntity = userStoreEntity() _userStoreEntity.id = se[10] _userStoreEntity.full_name = se[11] _userStoreEntity.address = se[12] _userStoreEntity.longitude = se[13] _userStoreEntity.latitude = se[14] _userStoreEntity.main = se[15] _userStoreEntity.id_user = _userEntity.id _user_stores.append(_userStoreEntity) _userEntity.user_store = _user_stores _data_users.append(_userEntity) _id_user_old = _userEntity.id _loadEntity.preferred_users = _data_users _cur.close() except (Exception) as e: self.add_log(str(e), type(self).__name__) finally: if _db is not None: _db.disconnect() print("Se cerro la conexion") return _loadEntity