Flo
4/25/2018 - 7:08 AM

Create User

Create a new user

declare
    p_login        varchar2(100) := 'testautomatisierung';
    p_password     varchar2(100) := 't3staut0mat1s13rung';
    p_first_name   varchar2(100) := 'testautomatisierung';
    p_last_name    varchar2(100) := 'testautomatisierung';
    p_client       number := 2;

    l_user         u_users.id%type;
    l_has_role     number := 0;
begin

    insert into aax2sw.u_users(login,
                               password,
                               first_name,
                               last_name,
                               deactivated,
                               usergroup,
                               level_current,
                               status,
                               user_name,
                               user_style,
                               client,
                               last_password_change,
                               language,
                               use_allowed_actions,
                               display_mode_call_flow,
                               ldap_exclude)
         values (p_login,
                 aax_zentral.get_password_hash(p_password),
                 p_first_name,
                 p_last_name,
                 0,
                 3,
                 0,
                 1,
                 p_first_name || ' ' || p_last_name,
                 'toll4europe',
                 p_client,
                 SYSDATE + 30000,
                 1,
                 0,
                 0,
                 1)
      returning id
           into l_user;

    update u_users
       set password = aax_zentral.get_password_hash(p_password)
     where login = p_login;

    update u_users
       set last_password_change = SYSDATE + 30000
     where login = p_login;

    select COUNT(*)
      into l_has_role
      from u_roles_2_user
     where userid = l_user
       and role = 127;

    if l_has_role = 0 then

        insert into u_roles_2_user(userid, role, status)
             values (l_user, 127, 1);

    end if;

end;