USP_DATAFORMTEMPLATE_ADD_AUTHUSERLINKSESSION

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT
@CURRENTAPPUSERID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN
@SESSIONTOKEN uniqueidentifier IN

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_AUTHUSERLINKSESSION
(
  @ID uniqueidentifier output,
  @CURRENTAPPUSERID uniqueidentifier,
  @CHANGEAGENTID uniqueidentifier = null,
  @SESSIONTOKEN uniqueidentifier
)
as

set nocount on;

begin try

  if @ID is null or @ID = '00000000-0000-0000-0000-000000000000'
  begin
    raiserror('BBERR_MISSINGRECORDID', 13, 1);
  end
  if @ID <> @CURRENTAPPUSERID
  begin
    raiserror('BBERR_UNAUTHORIZEDAPPUSER', 13, 1);
  end

  if exists(
    select 1
    from dbo.APPUSERTHIRDPARTYAUTH
    where ID = @ID
      and INVITATIONSTATUSCODE = 3 --Active (the user has been linked to 3rd party auth)

  )
  begin
    raiserror('BBERR_AUTHUSERLINK_INVITATIONACTIVE', 13, 1);
  end

  exec dbo.USP_APPUSERTHIRDPARTYAUTH_UPDATEINVITATIONSTATUS
    @ID=@ID,
    @INVITATIONID=@SESSIONTOKEN, -- Overloading "invitation" with the token to match with after authenticating.

    @INVITATIONSTATUSCODE=1; --Invitation Sent


end try

begin catch
  exec dbo.USP_RAISE_ERROR;
  return 1;
end catch

return 0;