def MenuDefectoUsuario(self): token = request.headers['Authorization'] if token: validacionSeguridad.ValidacionToken(token) if validacionSeguridad : DatosUsuario = jwt.decode(token, conf.SS_TKN_SCRET_KEY, 'utf-8') id_lgn_prfl_scrsl = validacionSeguridad.validaUsuario(DatosUsuario['lgn']) if type(id_lgn_prfl_scrsl) is not dict: return id_lgn_prfl_scrsl strQuery = 'SELECT a."text",a.id,a.parentid,a.lnk as enlace,(d.id is Not Null) favorito '\ 'FROM (select c.dscrpcn as text , b.id_mnu as id , c.id_mnu as parentid , c.lnk ,a.id Mid,c.ordn '\ 'FROM ssi7x.tblogins_perfiles_menu a INNER JOIN '\ 'ssi7x.tbmenu_ge b on a.id_mnu_ge=b.id INNER JOIN '\ 'ssi7x.tbmenu c ON b.id_mnu = c.id '\ 'where a.estdo=true and b.estdo=true and a.id_lgn_prfl_scrsl =' +str(id_lgn_prfl_scrsl['id_prfl_scrsl'])+ ' '\ ' )a LEFT JOIN ssi7x.tbfavoritosmenu d on d.id_lgn_prfl_mnu = a.Mid ORDER BY cast(a.ordn as integer)' Cursor = lc_cnctn.queryFree(strQuery) if Cursor : data = json.loads(json.dumps(Cursor, indent=2)) return Utils.nice_json(data,200) else: return Utils.nice_json({"error":errors.ERR_NO_USRO_SN_MNU},400) else: return Utils.nice_json({"error":errors.ERR_NO_SN_SSN},400) else: return Utils.nice_json({"error":errors.ERR_NO_SN_PRMTRS},400)
def login(self): ingreso=False u = UsuarioAcceso(request.form) if not u.validate(): return Utils.nice_json({"error":u.errors},400) IpUsuario = IP(socket.gethostbyname(socket.gethostname())) if IpUsuario.iptype() == 'PUBLIC': md5= hashlib.md5(request.form['password'].encode('utf-8')).hexdigest() Cursor = lc_cnctn.querySelect(dbConf.DB_SHMA +'.tblogins', 'lgn,cntrsna', "lgn='"+ request.form['username']+ "' and cntrsna='"+md5+"'") if Cursor : if type(validacionSeguridad.validaUsuario(request.form['username'])) is dict: ingreso=True else: return validacionSeguridad.validaUsuario(request.form['username']) else: ingreso elif IpUsuario.iptype() == 'PRIVATE': Cldap = Conexion_ldap() VerificaConexion = Cldap.Conexion_ldap(request.form['username'], request.form['password']) if VerificaConexion : if type(validacionSeguridad.validaUsuario(request.form['username'])) is dict: ingreso=True else: error = str(validacionSeguridad.validaUsuario(request.form['username'])) return Utils.nice_json({"error":error},400) else: ingreso if ingreso: tmpData = validacionSeguridad.ObtenerDatosUsuario(request.form['username'])[0] data = json.loads(json.dumps(tmpData, indent=2)) _cookie_data =json.dumps(tmpData, sort_keys = True, indent=4) token = jwt.encode(data, conf.SS_TKN_SCRET_KEY, algorithm=conf.ENCRYPT_ALGORITHM).decode('utf-8') arrayValues={} device=Utils.DetectarDispositivo(request.headers.get('User-Agent')) arrayValues['key']= str(token) arrayValues['ip']=str(IpUsuario) arrayValues['dspstvo_accso']=str(device) arrayValues['id_lgn_ge']=str(data['id_lgn_ge']) self.InsertGestionAcceso(arrayValues) response = make_response( '{"access_token":"'+str(token)+'","cookie_higia":'+ str(_cookie_data) +'}',200) response.headers['Content-type'] = "application/json" response.headers['charset']="utf-8" response.headers["Access-Control-Allow-Origin"]= "*" return response else: return Utils.nice_json({"error":errors.ERR_NO_USRO_CNTSN_INVLD},400)
def ObtenerPreguntas(self): ln_opcn_mnu = request.form["id_mnu_ge"] token = request.headers['Authorization'] validacionSeguridad = ValidacionSeguridad() val = validacionSeguridad.Principal(token, ln_opcn_mnu, optns.OPCNS_MNU['PreguntaSg']) arrayParametros = {} prmtrs = '' try: arrayParametros['cdgo'] = request.form['cdgo'] cdgo = arrayParametros['cdgo'] prmtrs += " and a.cdgo like '%" + cdgo + "%'" except: pass try: arrayParametros['dscrpcn'] = request.form['dscrpcn'] dscrpcn = arrayParametros['dscrpcn'] prmtrs += " and a.dscrpcn like '%" + dscrpcn + "%' " except: pass try: arrayParametros['id_prgnta_ge'] = request.form['id_prgnta_ge'] id_prgnta_ge = arrayParametros['id_prgnta_ge'] prmtrs += " and b.id = '" + id_prgnta_ge + "'" except: pass if val: StrSql=" select "\ " b.id,a.cdgo,a.dscrpcn "\ " from "\ " ssi7x.tbpreguntas_seguridad a inner join ssi7x.tbpreguntas_seguridad_ge b on "\ " a.id=b.id_prgnta_sgrdd "\ " where "\ " b.estdo = true "\ + str(prmtrs) print(StrSql) Cursor = C.queryFree(StrSql) if Cursor: data = json.loads(json.dumps(Cursor, indent=2)) return Utils.nice_json(data, 200) else: return Utils.nice_json({"error": errors.ERR_NO_RGSTRS}, 400) else: return Utils.nice_json({"error": errors.ERR_NO_ATRZCN}, 400)
def ObtenerUsuarios(self): token = request.headers['Authorization'] ln_opcn_mnu = request.form["id_mnu_ge"] validacionSeguridad = ValidacionSeguridad() val = validacionSeguridad.Principal(token, ln_opcn_mnu, optns.OPCNS_MNU['Usuarios']) prmtrs = '' try: id_lgn_ge = request.form['id_login_ge'] prmtrs = prmtrs + " and a.id = " + id_lgn_ge except Exception: pass try: lgn = request.form['login'] prmtrs = prmtrs + " and lgn like '%" + lgn + "%' " except Exception: pass try: id_grpo_emprsrl = request.form['id_grpo_emprsrl'] prmtrs = prmtrs + " and id_grpo_emprsrl = " + id_grpo_emprsrl + " " except Exception: pass if val: Cursor = lc_cnctn.queryFree(" select "\ " a.id, b.lgn, b.nmbre_usro, b.fto_usro, case when b.estdo = true then 'ACTIVO' else 'INACTIVO' end as estdo "\ " from "\ " "+str(dbConf.DB_SHMA)+".tblogins_ge a inner join "+str(dbConf.DB_SHMA)+".tblogins b on "\ " a.id_lgn = b.id "\ " where "\ " a.estdo = true "\ + prmtrs + " order by "\ " b.lgn") if Cursor: data = json.loads(json.dumps(Cursor, indent=2)) return Utils.nice_json(data, 200) else: return Utils.nice_json({"error": errors.ERR_NO_RGSTRS}, 400) else: return Utils.nice_json({"error": errors.ERR_NO_ATRZCN}, 400)
def ActualizarPreguntas(self): token = request.headers['Authorization'] ln_opcn_mnu = request.form["id_mnu_ge"] validacionSeguridad = ValidacionSeguridad() val = validacionSeguridad.Principal(token, ln_opcn_mnu, optns.OPCNS_MNU['PreguntaSg']) u = ActualizarAcceso(request.form) if not u.validate(): return Utils.nice_json({"error": u.errors}, 400) if val: DatosUsuarioToken = jwt.decode(token, conf.SS_TKN_SCRET_KEY, 'utf-8') id_lgn_ge_ssn = validacionSeguridad.ObtenerDatosUsuario( DatosUsuarioToken['lgn'])[0] print(id_lgn_ge_ssn['id_lgn_ge']) arrayValues = {} arrayValues2 = {} #Actualizo tabla ge arrayValues['id'] = request.form['id_prgnta_ge'] arrayValues['fcha_mdfccn'] = str(fecha_act) arrayValues['id_lgn_mdfccn_ge'] = str(id_lgn_ge_ssn['id_lgn_ge']) self.PreguntaActualizaRegistro(arrayValues, 'tbpreguntas_seguridad_ge') #obtengo id_prgnta a partir del id Cursor = C.querySelect( dbConf.DB_SHMA + '.tbpreguntas_seguridad_ge', 'id_prgnta_sgrdd', "id=" + str(request.form['id_prgnta_ge'])) if Cursor: data = json.loads(json.dumps(Cursor[0], indent=2)) id_prgnta = data['id_prgnta_sgrdd'] #Actualizo tabla principal arrayValues2['id'] = id_prgnta arrayValues2['cdgo'] = request.form['cdgo'] arrayValues2['dscrpcn'] = request.form['dscrpcn'] arrayValues2['fcha_mdfccn'] = str(fecha_act) arrayValues2['id_lgn_mdfccn_ge'] = str(id_lgn_ge_ssn['id_lgn_ge']) self.PreguntaActualizaRegistro(arrayValues2, 'tbpreguntas_seguridad') return Utils.nice_json({"error": labels.SCCSS_ACTLZCN_EXTSA}, 200) else: return Utils.nice_json({"error": errors.ERR_NO_ATRZCN}, 400)
def BusquedaImagenUsuario(self): lc_url = request.url lc_prtcl = urlparse(lc_url) Cursor = lc_cnctn.queryFree(" select "\ " id ,"\ " lgn ,"\ " fto_usro,"\ " nmbre_usro, "\ " estdo "\ " from ssi7x.tblogins where lgn = '"+str(request.form['username'])+"'") if Cursor : data = json.loads(json.dumps(Cursor[0], indent=2)) if data['estdo']: if data['fto_usro']: return Utils.nice_json({"fto_usro":lc_prtcl.scheme+'://'+conf.SV_HOST+':'+str(conf.SV_PORT)+'/static/img/'+data['fto_usro']},200) else: return Utils.nice_json({"fto_usro":"null"},200) else: return Utils.nice_json({"error":errors.ERR_NO_TNE_PRFL,lc_prtcl.scheme+'://'+"fto_usro":conf.SV_HOST+':'+str(conf.SV_PORT)+'/static/img/'+data['fto_usro']},200) else: return Utils.nice_json({"error":errors.ERR_NO_TNE_PRMTDO_ACCDR},400)
def crearPregunta(self): ln_opcn_mnu = request.form["id_mnu_ge"] token = request.headers['Authorization'] validacionSeguridad = ValidacionSeguridad() val = validacionSeguridad.Principal(token, ln_opcn_mnu, optns.OPCNS_MNU['PreguntaSg']) u = Acceso(request.form) if not u.validate(): return self.Utils.nice_json({"error": u.errors}, 400) if val: DatosUsuarioToken = jwt.decode(token, conf.SS_TKN_SCRET_KEY, 'utf-8') datosUsuario = validacionSeguridad.ObtenerDatosUsuario( DatosUsuarioToken['lgn'])[0] arrayValues = {} arrayValues2 = {} arrayValues['cdgo'] = request.form['cdgo'] arrayValues['dscrpcn'] = request.form['dscrpcn'] arrayValues['fcha_crcn'] = str(fecha_act) arrayValues['fcha_mdfccn'] = str(fecha_act) arrayValues['id_lgn_crcn_ge'] = str(datosUsuario['id_lgn_ge']) arrayValues['id_lgn_mdfccn_ge'] = str(datosUsuario['id_lgn_ge']) id_prgnta = self.crearPregunta_seguridad(arrayValues, 'tbpreguntas_seguridad') arrayValues2['id_prgnta_sgrdd'] = str(id_prgnta) arrayValues2['id_lgn_crcn_ge'] = str(datosUsuario['id_lgn_ge']) arrayValues2['id_lgn_mdfccn_ge'] = str(datosUsuario['id_lgn_ge']) arrayValues2['fcha_crcn'] = str(fecha_act) arrayValues2['fcha_mdfccn'] = str(fecha_act) arrayValues2['id_lgn_ge'] = str(datosUsuario['id_lgn_ge']) self.crearPregunta_seguridad(arrayValues2, 'tbpreguntas_seguridad_ge') return Utils.nice_json({"error": labels.SCCSS_RGSTRO_EXTSO}, 200) return Utils.nice_json({"error": errors.ERR_NO_ATRZCN}, 400)
def CmboCntrsna(self): u = UsroCmbioCntrsna(request.form) if not u.validate(): return Utils.nice_json({"status":"Error","error":u.errors,"user":"******"},200)
from SSI7X.Static.ConnectDB import ConnectDB # @UnresolvedImport from SSI7X.Static.Utils import Utils # @UnresolvedImport from SSI7X.Static.Ldap_connect import Conexion_ldap # @UnresolvedImport from urllib.parse import urlparse import SSI7X.Static.errors as errors # @UnresolvedImport import SSI7X.Static.labels as labels # @UnresolvedImport import SSI7X.Static.config as conf # @UnresolvedImport import SSI7X.Static.config_DB as dbConf # @UnresolvedImport import jwt #@UnresolvedImport from SSI7X.ValidacionSeguridad import ValidacionSeguridad # @UnresolvedImport ''' Declaracion de variables globales ''' lc_cnctn = ConnectDB() Utils = Utils() validacionSeguridad = ValidacionSeguridad() ''' clase para la validacion de datos provenientes del POST en el login ''' class UsuarioAcceso(Form): username = StringField(labels.lbl_nmbr_usrs,[validators.DataRequired(message=errors.ERR_NO_INGSA_USRO)]) password = StringField(labels.lbl_cntrsna_usrs,[validators.DataRequired(message=errors.ERR_NO_INGRSA_CNTRSNA)]) ''' clase para la validacion de datos del POST en el cambio de contrasenna ''' class UsroCmbioCntrsna(Form): cntrsna = StringField(labels.lbl_cntrsna_usrs,[validators.DataRequired(message=errors.ERR_NO_INGRSA_CNTRSNA)]) cntrsna_nva = StringField(labels.lbl_nva_cntrsna,[validators.DataRequired(message=errors.ERR_NO_DB_INGRSR_NVA_CNTRSNA),validators.Length(min=conf.PW_MN_SIZE,message=errors.ERR_NO_MNM_CRCTRS),validators.Regexp('(?=.*\d)',message=errors.ERR_NO_MNMO_NMRO),validators.Regexp('(?=.*[A-Z])',message=errors.ERR_NO_MNMO_MYSCLA)])
class ValidacionSeguridad(Resource): Utils = Utils() C = ConnectDB() def Principal(self, token, id_mnu_ge, sttc_mnu): if not token and id_mnu_ge: return False DatosUsuario = jwt.decode(token, conf.SS_TKN_SCRET_KEY, 'utf-8') if DatosUsuario: if int(sttc_mnu) == int(id_mnu_ge): lo_datos = self.validaUsuario(DatosUsuario['lgn']) return self.ValidaOpcionMenu(lo_datos['id_prfl_scrsl'], id_mnu_ge) else: return False else: False def validaUsuario(self, usuario): IdUsuarioGe = json.loads( json.dumps(self.ObtenerDatosUsuario(usuario)[0], indent=2)) strQuery = "SELECT "\ " a.id as id_prfl_scrsl,"\ " b.nmbre_scrsl as nmbre_scrsl,"\ " c.estdo as estdo "\ " FROM ssi7x.tblogins_perfiles_sucursales a"\ " left JOIN ssi7x.tbsucursales b on a.id_scrsl=b.id"\ " left join ssi7x.tblogins_ge c on c.id = a.id_lgn_ge"\ " WHERE a.id_lgn_ge = "+str(IdUsuarioGe['id_lgn_ge'])+" and a.mrca_scrsl_dfcto is true" Cursor = self.C.queryFree(strQuery) if Cursor: data = json.loads(json.dumps(Cursor[0], indent=2)) if data['estdo']: return data else: return errors.ERR_NO_USRO_INCTVO else: return errors.ERR_NO_TNE_PRFL def ValidacionToken(self, token): try: decode = jwt.decode(token, conf.SS_TKN_SCRET_KEY, 'utf-8') return True except jwt.exceptions.ExpiredSignatureError: return False def ValidaOpcionMenu(self, id_lgn_prfl_scrsl, id_mnu_ge): Cursor = self.C.queryFree(" select a.id "\ " from ssi7x.tblogins_perfiles_menu a inner join "\ " ssi7x.tblogins_perfiles_sucursales b "\ " on a.id_lgn_prfl_scrsl = b.id inner join "\ " ssi7x.tblogins_ge c on c.id = b.id_lgn_ge inner join "\ " ssi7x.tbmenu_ge d on d.id = a.id_mnu_ge inner join "\ " ssi7x.tbmenu e on e.id = d.id_mnu "\ " where c.estdo=true "\ " and b.estdo=true "\ " and a.estdo=true "\ " and d.id = "+str(id_mnu_ge)+" and a.id_lgn_prfl_scrsl = "+str(id_lgn_prfl_scrsl)) if Cursor: return True else: return False def ObtenerDatosUsuario(self, usuario): cursor = self.C.queryFree(" select " \ " case when emplds_une.id is not null then "\ " concat_ws("\ " ' ',"\ " emplds.prmr_nmbre,"\ " emplds.sgndo_nmbre,"\ " emplds.prmr_aplldo,"\ " emplds.sgndo_aplldo)"\ " else" \ " prstdr.nmbre_rzn_scl" \ " end as nmbre_cmplto," \ " case when emplds_une.id is not null then" \ " emplds.crro_elctrnco" \ " else" \ " prstdr.crro_elctrnco" \ " end as crro_elctrnco," \ " lgn_ge.id as id_lgn_ge, " \ " lgn.lgn as lgn, " \ " crgo.dscrpcn as crgo, " \ " lgn.fto_usro as fto_usro, "\ " emplds_une.id_undd_ngco as id_undd_ngco, "\ " undd_ngco.id_grpo_emprsrl as id_grpo_emprsrl " " from ssi7x.tblogins_ge lgn_ge " \ " left join ssi7x.tblogins lgn on lgn.id = lgn_ge.id_lgn " \ " left join ssi7x.tbempleados_une emplds_une on emplds_une.id_lgn_accso_ge = lgn_ge.id " \ " left join ssi7x.tbempleados emplds on emplds.id = emplds_une.id_empldo " \ " left join ssi7x.tbprestadores prstdr on prstdr.id_lgn_accso_ge = lgn_ge.id " \ " left join ssi7x.tbcargos_une crgo_une on crgo_une.id = emplds_une.id_crgo_une " \ " left join ssi7x.tbcargos crgo on crgo.id = crgo_une.id_crgo " \ " left join ssi7x.tbunidades_negocio undd_ngco on undd_ngco.id = emplds_une.id_undd_ngco " \ " where lgn.lgn = '"+usuario+"' and id_mtvo_rtro_une is null") return cursor
class Perfiles(Resource): Utils = Utils() lc_cnctn = ConnectDB() fecha_act = time.ctime() def post(self, **kwargs): if kwargs['page'] == 'crear': return self.crear() if kwargs['page'] == 'ListarPerfiles': return self.ListarPerfiles() if kwargs['page'] == 'ActualizarPerfil': return self.ActualizarPerfil() def crear(self): lob_rspsta = DatosPerfil(request.form) if not lob_rspsta.validate(): return self.Utils.nice_json({"error": lob_rspsta.errors}, 400) ln_opcn_mnu = request.form["id_mnu_ge"] token = request.headers['Authorization'] validacionSeguridad = ValidacionSeguridad() if validacionSeguridad.Principal(token, ln_opcn_mnu, optns.OPCNS_MNU['Perfiles']): DatosUsuarioToken = jwt.decode(token, conf.SS_TKN_SCRET_KEY, 'utf-8') datosUsuario = validacionSeguridad.ObtenerDatosUsuario( DatosUsuarioToken['lgn'])[0] arrayValues = {} arrayValues['cdgo'] = request.form["cdgo"] arrayValues['dscrpcn'] = request.form["dscrpcn"] ld_id_prfl = self.lc_cnctn.queryInsert( dbConf.DB_SHMA + ".tbperfiles", arrayValues, 'id') if ld_id_prfl: arrayValuesDetalle = {} arrayValuesDetalle['id_prfl'] = str(ld_id_prfl) arrayValuesDetalle['id_undd_ngco'] = str(3) arrayValuesDetalle['id_lgn_crcn_ge'] = str( datosUsuario['id_lgn_ge']) arrayValuesDetalle['id_lgn_mdfccn_ge'] = str( datosUsuario['id_lgn_ge']) arrayValuesDetalle['fcha_mdfccn'] = str(self.fecha_act) arrayValuesDetalle['fcha_mdfccn'] = str(self.fecha_act) self.lc_cnctn.queryInsert(dbConf.DB_SHMA + ".tbperfiles_une", arrayValuesDetalle) else: return self.Utils.nice_json({"error": "null"}, 400) else: return self.Utils.nice_json({"error": "null"}, 400) def ListarPerfiles(self): ln_opcn_mnu = request.form["id_mnu_ge"] token = request.headers['Authorization'] validacionSeguridad = ValidacionSeguridad() if validacionSeguridad.Principal(token, ln_opcn_mnu, optns.OPCNS_MNU['Perfiles']): lc_dta = '' lc_cdgo = '' try: lc_cdgo = request.form["cdgo"] lc_dta = lc_dta + " and a.cdgo = '" + lc_cdgo + "' " except Exception: pass lc_dscrpcn = '' try: lc_dscrpcn = request.form["dscrpcn"] lc_dta = lc_dta + " and a.dscrpcn like '%" + lc_dscrpcn + "%' " except Exception: pass ln_id_undd_ngco = request.form["id_undd_ngco"] strSql = " select b.id, "\ " a.cdgo ,a.dscrpcn "\ " ,case when b.estdo = true then 'ACTIVO' else 'INACTIVO' end as estdo "\ " from "\ " ssi7x.tbperfiles a inner join ssi7x.tbperfiles_une b on "\ " a.id=b.id_prfl "\ " where "\ " b.id_undd_ngco = "+str(ln_id_undd_ngco) +" "+ lc_dta +""\ " order by a.dscrpcn" Cursor = self.lc_cnctn.queryFree(strSql) if Cursor: data = json.loads(json.dumps(Cursor, indent=2)) return self.Utils.nice_json(data, 200) else: return self.Utils.nice_json({"error": labels.INFO_NO_DTS}, 200) else: return self.Utils.nice_json({"error": "null"}, 400) def ActualizarPerfil(self): lob_rspsta = DatosUpdate(request.form) if not lob_rspsta.validate(): return self.Utils.nice_json({"error": lob_rspsta.errors}, 400) ln_opcn_mnu = request.form["id_mnu_ge"] token = request.headers['Authorization'] validacionSeguridad = ValidacionSeguridad() if validacionSeguridad.Principal(token, ln_opcn_mnu): DatosUsuarioToken = jwt.decode(token, conf.SS_TKN_SCRET_KEY, 'utf-8') datosUsuario = validacionSeguridad.ObtenerDatosUsuario( DatosUsuarioToken['lgn'])[0] lc_cdgo = request.form["cdgo"] lc_dscrpcn = request.form["dscrpcn"] ln_id_prfl_une = request.form["id_prfl_une"] lb_estdo = request.form["estdo"] arrayValues = {} arrayValuesDetalle = {} #Actualizo tabla une arrayValuesDetalle['id_lgn_mdfccn_ge'] = str( datosUsuario['id_lgn_ge']) arrayValuesDetalle['estdo'] = lb_estdo arrayValuesDetalle['fcha_mdfccn'] = str(self.fecha_act) self.lc_cnctn.queryUpdate( dbConf.DB_SHMA + "." + str('tbperfiles_une'), arrayValuesDetalle, 'id=' + str(ln_id_prfl_une)) #obtengo id_lgn a partir del id_lgn_ge Cursor = self.lc_cnctn.querySelect( dbConf.DB_SHMA + '.tbperfiles_une', 'id_prfl', "id=" + ln_id_prfl_une) if Cursor: data = json.loads(json.dumps(Cursor[0], indent=2)) ln_id_prfl = data['id_prfl'] #Actualizo tabla principal arrayValues['id'] = ln_id_prfl arrayValues['cdgo'] = str(lc_cdgo) arrayValues['dscrpcn'] = lc_dscrpcn arrayValues['estdo'] = lb_estdo self.lc_cnctn.queryUpdate( dbConf.DB_SHMA + "." + str('tbperfiles'), arrayValues, 'id=' + str(ln_id_prfl)) else: return self.Utils.nice_json({"error": "null"}, 400)
def ActualizarUsuario(self): token = request.headers['Authorization'] fcha_actl = time.ctime() ln_opcn_mnu = request.form["id_mnu_ge"] validacionSeguridad = ValidacionSeguridad() val = validacionSeguridad.Principal(token, ln_opcn_mnu, optns.OPCNS_MNU['Usuarios']) #Validar los campos requeridos. u = ActualizarAcceso(request.form) if not u.validate(): return Utils.nice_json({"error": u.errors}, 400) if val: md5 = hashlib.md5( request.form['password'].encode('utf-8')).hexdigest() ''' INSERTAR DATOS ''' arrayValues = {} arrayValues2 = {} #Actualizo tabla ge arrayValues2['id'] = request.form['id_login_ge'] arrayValues2['fcha_mdfccn'] = str(fcha_actl) arrayValues2[ 'id_grpo_emprsrl'] = '2' #pendiente traer esta variable de una cookie arrayValues['lgn'] = request.form['login'] arrayValues['cntrsna'] = md5 #pendiente encriptar la contraseña arrayValues['nmbre_usro'] = request.form['nombre_usuario'] ''' Validar repetidos ''' lc_tbls_query = dbConf.DB_SHMA + ".tblogins_ge a INNER JOIN " + dbConf.DB_SHMA + ".tblogins b on a.id_lgn=b.id " CursorValidar = lc_cnctn.querySelect( lc_tbls_query, ' b.id ', " a.id <> " + str(arrayValues2['id']) + " AND b.lgn = '" + str(arrayValues['lgn']) + "' ") if CursorValidar: return Utils.nice_json( {"error": labels.lbl_lgn + " " + errors.ERR_RGSTRO_RPTDO}, 400) ''' Insertar en la tabla auxiliar y obtener id de creacion ''' self.UsuarioActualizaRegistro(arrayValues2, 'tblogins_ge') #obtengo id_lgn a partir del id_lgn_ge Cursor = lc_cnctn.querySelect(dbConf.DB_SHMA + '.tblogins_ge', 'id_lgn', "id=" + str(arrayValues2['id'])) if Cursor: data = json.loads(json.dumps(Cursor[0], indent=2)) id_lgn = data['id_lgn'] #Actualizo tabla principal arrayValues['id'] = id_lgn ''' Guardar la imagen en la ruta especificada ''' lc_nmbre_imgn = str( hashlib.md5(str( arrayValues['id']).encode('utf-8')).hexdigest()) + '.jpg' arrayGuardarArchivo = self.GuardarArchivo(request.files, 'imge_pth', conf.SV_DIR_IMAGES, lc_nmbre_imgn, True) if arrayGuardarArchivo['status'] == 'error': return Utils.nice_json( {"error": arrayGuardarArchivo['retorno']}, 400) else: arrayValues['fto_usro'] = str(arrayGuardarArchivo["retorno"]) #ACTUALIZACION TABLA LOGINS OK self.UsuarioActualizaRegistro(arrayValues, 'tblogins') return Utils.nice_json({"error": labels.SCCSS_ACTLZCN_EXTSA}, 200) ''' FIN INSERTAR DATOS ''' else: return Utils.nice_json({"error": errors.ERR_NO_ATRZCN}, 400)
def InsertarUsuarios(self): token = request.headers['Authorization'] fcha_actl = time.ctime() ln_opcn_mnu = request.form["id_mnu_ge"] validacionSeguridad = ValidacionSeguridad() val = validacionSeguridad.Principal(token, ln_opcn_mnu, optns.OPCNS_MNU['Usuarios']) lc_cntrsna = hashlib.md5( request.form['password'].encode('utf-8')).hexdigest() #Validar los campos requeridos. u = AcInsertarAcceso(request.form) if not u.validate(): return Utils.nice_json({"error": u.errors}, 400) if val: ''' Aqui insertamos los datos del usuario ''' arrayValues = {} arrayValues3 = {} arrayValues['lgn'] = request.form['login'] arrayValues[ 'cntrsna'] = lc_cntrsna #pendiente encriptar la contraseña arrayValues['nmbre_usro'] = request.form['nombre_usuario'] arrayValues3['fcha_crcn'] = str(fcha_actl) arrayValues3['fcha_mdfccn'] = str(fcha_actl) arrayValues3[ 'id_grpo_emprsrl'] = '2' #pendiente traer esta variable de una cookie ''' Validar repetidos ''' lc_tbls_query = dbConf.DB_SHMA + ".tblogins_ge a INNER JOIN " + dbConf.DB_SHMA + ".tblogins b on a.id_lgn=b.id " CursorValidar = lc_cnctn.querySelect( lc_tbls_query, ' b.id ', " b.lgn = '" + str(arrayValues['lgn']) + "' ") if CursorValidar: return Utils.nice_json( {"error": labels.lbl_lgn + " " + errors.ERR_RGSTRO_RPTDO}, 400) id_lgn = self.UsuarioInsertaRegistro(arrayValues, 'tblogins') arrayValues3['id_lgn'] = str(id_lgn) lc_nmbre_imgn = str( hashlib.md5(str(id_lgn).encode('utf-8')).hexdigest()) + '.jpg' arrayGuardarArchivo = self.GuardarArchivo(request.files, 'imge_pth', conf.SV_DIR_IMAGES, lc_nmbre_imgn, True) if arrayGuardarArchivo['status'] == 'error': return Utils.nice_json( {"error": arrayGuardarArchivo['retorno']}, 400) else: arrayValues['fto_usro'] = str(arrayGuardarArchivo["retorno"]) ''' Actualizo el registro con el nombre de la imagen ''' arrayValues['id'] = str(id_lgn) self.UsuarioActualizaRegistro(arrayValues, 'tblogins') return Utils.nice_json({"error": labels.SCCSS_RGSTRO_EXTSO}, 200) ''' Fin de la insercion de los datos ''' else: return Utils.nice_json({"error": errors.ERR_NO_ATRZCN}, 400)