Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
11| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_accion | char | 1 | |
| @p_user_id | int | 4 | |
| @p_login | varchar | 60 | |
| @p_estado_login | char | 1 | |
| @p_email | varchar | 500 | |
| @first_name | varchar | 50 | |
| @last_name | varchar | 50 | |
| @password | varchar | 20 | |
| @p_plataforma | varchar | 10 | |
| @p_country | varchar | 2 | |
| @p_iso_idioma | varchar | 3 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.users_backend
-- Parte 1: Carga el username, y estado del login.
@p_accion char(1), --A / M
@p_user_id int, -- id para el update
@p_login varchar(60), --username
@p_estado_login char(1), --Y / N
@p_email varchar(500),
@first_name varchar(50),
@last_name varchar(50),
@password varchar(20),
@p_plataforma varchar(10)=null,
@p_country varchar(2)='AR',
@p_iso_idioma varchar(3) = 'SPA'
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ok char(1)
DECLARE @p_rand int
DECLARE @p_rand_char varchar(120)
DECLARE @i int
DECLARE @codIdioma int = 29523
select @codIdioma = idioma from idiomas where upper(codigo_iso)=upper(@p_iso_idioma)
set @i = 0
if (@p_accion = 'A')
begin
if (select count(*) from users where username = @p_login) = 0
begin
set @ok = 'N'
--select @ok
WHILE (@ok = 'N')
BEGIN
set @i = @i + 1
set @p_rand = ROUND(((999999999 - 1) * RAND() + 1), 0)
set @p_rand_char = convert(varchar(120),newid())
if (select count(*) from users where user_id = @p_rand or cookie_id = @p_rand_char) = 0
begin
insert into users (user_id, cookie_id, username, active_user, email, user_created,first_name,last_name,password,preferences,country_code,idioma)
values (@p_rand, @p_rand_char, @p_login, @p_estado_login, @p_email, getdate(),@first_name,@last_name,@password,@p_plataforma,@p_country,@codIdioma)
set @ok = 'S'
--select @ok
insert into usuarios_roles (rol,user_id,idioma) values (30210,@p_rand,17491)
end
END
select '0' as error, 'Alta OK 1 ' as mensaje
end
else
begin
if (select count(*) from users where username = @p_login ) = 0
begin
if ((select password from users where user_id = @p_user_id) != @password)
begin
update users
set active_user = @p_estado_login,
email = @p_email,
first_name = @first_name,
last_name = @last_name,
password = @password,
preferences = @p_plataforma,
country_code = @p_country,
idioma = @codIdioma
where username = @p_login
select '0' as error, 'Alta OK 2' as mensaje
end
else
begin
update users
set active_user = @p_estado_login,
email = @p_email,
first_name = @first_name,
last_name = @last_name,
preferences = @p_plataforma,
country_code = @p_country,
idioma = @codIdioma
where username = @p_login
select '0' as error, 'Alta OK 2' as mensaje
end
end
else
begin
select '1' as error, 'Ese login ya está asignado a otro Cliente'
end
end
end
else
-- Modificacion
begin
update users
set active_user = @p_estado_login,
email = @p_email,
first_name = @first_name,
last_name = @last_name,
password = @password,
preferences = @p_plataforma,
idioma = @codIdioma
where user_id = @p_user_id
select '0' as error, 'Modificación OK' as mensaje
end
END
/*
select * from roles where rol = 30210
select * from usuarios_roles where user_id=5546717
insert into usuarios_roles (rol,user_id,idioma) values (30210,@user,17491
select distinct users.user_id, users.first_name, users.last_name, isnull(users.first_name,'') + ' ' + isnull(users.last_name,'') as usuario,
/*ROLES.nombre_rol,ROLES.activo,ROLES.country_code,*/ROLES.PLATAFORMA
from users
inner join usuarios_roles on users.user_id = usuarios_roles.user_id
inner join roles_tipo_informe on usuarios_roles.rol = roles_tipo_informe.rol
inner join idiomas on usuarios_roles.idioma = idiomas.idioma
inner join roles on roles_tipo_informe.rol = roles.rol
where --roles_tipo_informe.id_tipo_informe = @p_id_tipo_informe and
ROLES.plataforma = 'BLUE' AND ROLES.ACTIVO = 1 AND
idiomas.codigo_idioma = 'ES'
and roles.datamanager = 1
and users.active_user = 'Y'
order by isnull(users.first_name,'') + ' ' + isnull(users.last_name,'')
*/
GO
GO
CREATE OR ALTER PROCEDURE dbo.users_backend
-- Parte 1: Carga el username, y estado del login.
@p_accion char(1), --A / M
@p_user_id int, -- id para el update
@p_login varchar(60), --username
@p_estado_login char(1), --Y / N
@p_email varchar(500),
@first_name varchar(50),
@last_name varchar(50),
@password varchar(20),
@p_plataforma varchar(10)=null,
@p_country varchar(2)='AR',
@p_iso_idioma varchar(3) = 'SPA'
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ok char(1)
DECLARE @p_rand int
DECLARE @p_rand_char varchar(120)
DECLARE @i int
DECLARE @codIdioma int = 29523
select @codIdioma = idioma from idiomas where upper(codigo_iso)=upper(@p_iso_idioma)
set @i = 0
if (@p_accion = 'A')
begin
if (select count(*) from users where username = @p_login) = 0
begin
set @ok = 'N'
--select @ok
WHILE (@ok = 'N')
BEGIN
set @i = @i + 1
set @p_rand = ROUND(((999999999 - 1) * RAND() + 1), 0)
set @p_rand_char = convert(varchar(120),newid())
if (select count(*) from users where user_id = @p_rand or cookie_id = @p_rand_char) = 0
begin
insert into users (user_id, cookie_id, username, active_user, email, user_created,first_name,last_name,password,preferences,country_code,idioma)
values (@p_rand, @p_rand_char, @p_login, @p_estado_login, @p_email, getdate(),@first_name,@last_name,@password,@p_plataforma,@p_country,@codIdioma)
set @ok = 'S'
--select @ok
insert into usuarios_roles (rol,user_id,idioma) values (30210,@p_rand,17491)
end
END
select '0' as error, 'Alta OK 1 ' as mensaje
end
else
begin
if (select count(*) from users where username = @p_login ) = 0
begin
if ((select password from users where user_id = @p_user_id) != @password)
begin
update users
set active_user = @p_estado_login,
email = @p_email,
first_name = @first_name,
last_name = @last_name,
password = @password,
preferences = @p_plataforma,
country_code = @p_country,
idioma = @codIdioma
where username = @p_login
select '0' as error, 'Alta OK 2' as mensaje
end
else
begin
update users
set active_user = @p_estado_login,
email = @p_email,
first_name = @first_name,
last_name = @last_name,
preferences = @p_plataforma,
country_code = @p_country,
idioma = @codIdioma
where username = @p_login
select '0' as error, 'Alta OK 2' as mensaje
end
end
else
begin
select '1' as error, 'Ese login ya está asignado a otro Cliente'
end
end
end
else
-- Modificacion
begin
update users
set active_user = @p_estado_login,
email = @p_email,
first_name = @first_name,
last_name = @last_name,
password = @password,
preferences = @p_plataforma,
idioma = @codIdioma
where user_id = @p_user_id
select '0' as error, 'Modificación OK' as mensaje
end
END
/*
select * from roles where rol = 30210
select * from usuarios_roles where user_id=5546717
insert into usuarios_roles (rol,user_id,idioma) values (30210,@user,17491
select distinct users.user_id, users.first_name, users.last_name, isnull(users.first_name,'') + ' ' + isnull(users.last_name,'') as usuario,
/*ROLES.nombre_rol,ROLES.activo,ROLES.country_code,*/ROLES.PLATAFORMA
from users
inner join usuarios_roles on users.user_id = usuarios_roles.user_id
inner join roles_tipo_informe on usuarios_roles.rol = roles_tipo_informe.rol
inner join idiomas on usuarios_roles.idioma = idiomas.idioma
inner join roles on roles_tipo_informe.rol = roles.rol
where --roles_tipo_informe.id_tipo_informe = @p_id_tipo_informe and
ROLES.plataforma = 'BLUE' AND ROLES.ACTIVO = 1 AND
idiomas.codigo_idioma = 'ES'
and roles.datamanager = 1
and users.active_user = 'Y'
order by isnull(users.first_name,'') + ' ' + isnull(users.last_name,'')
*/
GO
Depends On
2Used By
No items found