Explicitly create a new user as an executive step. This is done as part of the response to submission of a user registration form. In the form submission exec blocks, an <addUser> tag gives rise to an execAddUser instance, which in turn results in a call to this function. The <addUser> tag should not be used in any other context. Likewise, adding new users should not be attempted by a series of execCommit directives. NOTE: This function ONLY adds the new user to the standard subscriber repository

Return TypeFunction nameArguments
hzEcodehdsExec::Adduser(hzChain&,hzHttpEvent*,)

Declared in file: hzDissemino.h
Defined in file : hdsExec.cpp

Function Logic:

0:START 1:unknown 2:items 3:unknown 4:Return hzerr(E_NOINIT,Subscriber Class not initialized) 5:unknown 6:Return hzerr(E_NOINIT,Subscriber Repos not initialized) 7:userclass username password emaStr 8:unknown 9:Return hzerr(E_NOINIT,No user class specified) 10:unknown 11:Return hzerr(E_NOINIT,No user name specified) 12:unknown 13:Return hzerr(E_NOINIT,No user password specified) 14:unknown 15:Return hzerr(E_NOINIT,No user email specified) 16:pUserClass 17:unknown 18:Return hzerr(E_NOTFOUND,No user class: Class %s not known as a class\n,*userclass) 19:pUserRepos 20:unknown 21:Return hzerr(E_NOTFOUND,No user repository for class %s\n,*userclass) 22:items items rc 23:unknown 24:Return hzwarn(rc,Error during conversion of username %s,*username) 25:username rc 26:unknown 27:Return hzwarn(rc,Error during lookup of user %s,*username) 28:unknown 29:Return hzwarn(E_DUPLICATE,User %s already exists,*username) 30:pLog items items rc 31:unknown 32:Return hzwarn(rc,Error during conversion of password %s,*ema) 33:ema items items rc 34:unknown 35:Return hzwarn(rc,Error during conversion of password %s,*password) 36:items items m_pApp atom items items 37:Return E_OK

Function body:

hzEcode hdsExec::Adduser (hzChain& errorReport)hzHttpEvent* pE, 
{
   //  Explicitly create a new user as an executive step.
   //  
   //  This is done as part of the response to submission of a user registration form. In the form submission exec blocks, an <addUser> tag gives rise to an execAddUser instance,
   //  which in turn results in a call to this function. The <addUser> tag should not be used in any other context. Likewise, adding new users should not be attempted by a series
   //  of execCommit directives.
   //  
   //  NOTE: This function ONLY adds the new user to the standard subscriber repository
   //  In the common case where the webapp has only one type of user, 
   //  .will insert information for a new user into both the specified user repository and the inbult subscriber repository. The sequence is as follows:-
   //  
   //  1) The proposed username must be unique across all users in all user classes. The username must not already exist in the subscriber class.
   //  2) The address of the subsriber entry is established in order to be inserted in the user class
   //  3) The user info that belongs in the user class repository is added
   //  4) The user info that belongs in the subscriber repository is added
   //  
   //  If this action fails on the grounds of poor setup, this is a fatal error.
   //  If this action fails on the grounds of insufficient user information, this is a config error as it should not be possible to enter an incomplete user
   //  registration form.
   //  If this action fails on the grounds of username already in existance, send the error page.
   //  
   //  
   //  Arguments: 1) error The error report chain
   //     2) pE  The HTTP event pointer
   //  
   //  Returns
   //  
   //  Note: Errors are exclusively reported to the 
   _hzfunc("hdsExec::Adduser") ;
   hzList  <hzPair>::Iter  pi ;    //  member name/value pairs for user-class object
   //  const hdbClass*  pSubsClass ; // User class
   const hdbClass*     pUserClass ;    //  User class
   hdbObject           objSubscriber ;     //  Subscriber object
   hdbObject           userObj ;       //  User class object
   hzAtom              atom ;          //  Atom for loading objects
   hzChain             err ;           //  Error report
   hzLogger*           pLog ;          //  Thread logger
                                       //  hdbObjRepos*  pSubsRepos ; // User class repository
   hdbObjRepos*        pUserRepos ;    //  User class repository
   hzPair              pair ;          //  Member name/value pair for user-class object
   hzEmaddr            ema ;           //  Email address
   hzString            userclass ;     //  Name of user class
   hzString            username ;      //  Extracted/converted username
   hzString            password ;      //  Extracted/converted password
   hzString            emaStr ;        //  Email address
   hzString            S ;             //  Value string
   uint32_t            subsObjId ;     //  New user object id in subscriber cache
                                       //  uint32_t   userObjId ;  // New user object id in user-class cache
   hzEcode             rc = E_OK ;     //  Return code
   /*
   **  ** Check basics
   **      */
   if (!m_pApp)
       hzexit(E_NOINIT, "No Application") ;
   if (!m_pApp->m_ADP.m_pClassSubscriber)  return hzerr(E_NOINIT, "Subscriber Class not initialized") ;
   if (!m_pApp->m_ADP.m_pReposSubscriber)  return hzerr(E_NOINIT, "Subscriber Repos not initialized") ;
   userclass   = m_pApp->m_ExecParams[m_FstParam] ;
   username    = m_pApp->m_ExecParams[m_FstParam+1];
   password    = m_pApp->m_ExecParams[m_FstParam+2];
   emaStr      = m_pApp->m_ExecParams[m_FstParam+3];
   if (!userclass) return hzerr(E_NOINIT, "No user class specified") ;
   if (!username)  return hzerr(E_NOINIT, "No user name specified") ;
   if (!password)  return hzerr(E_NOINIT, "No user password specified") ;
   if (!emaStr)    return hzerr(E_NOINIT, "No user email specified") ;
   pUserClass = m_pApp->m_ADP.GetPureClass(userclass) ;
   if (!pUserClass)
       return hzerr(E_NOTFOUND, "No user class: Class %s not known as a class\n", *userclass) ;
   pUserRepos = m_pApp->m_ADP.GetObjRepos(userclass) ;
   if (!pUserRepos)
       return hzerr(E_NOTFOUND, "No user repository for class %s\n", *userclass) ;
   objSubscriber.Init(m_pApp->m_ADP.m_pClassSubscriber) ;
   userObj.Init(pUserClass) ;
   /*
   **  ** Set up SUBSCRIBER object
   **      */
   //  Step 1: Establish username
   rc = m_pApp->PcEntConv(atom, username, pE) ;
   if (rc != E_OK)
       return hzwarn(rc, "Error during conversion of username %s", *username) ;
   username = atom.Str() ;
   //  Check it does not already exist
   //  pMbr = pSubsClass->GetMember("username") ;
   rc = m_pApp->m_ADP.m_pReposSubscriber->Exists(subsObjId, m_pApp->m_ADP.m_pMbr_Subscriber_username, atom) ;
   if (rc != E_OK)
       return hzwarn(rc, "Error during lookup of user %s", *username) ;
   if (subsObjId)
       return hzwarn(E_DUPLICATE, "User %s already exists", *username) ;
   pLog = GetThreadLogger() ;
   //  Set the username in the subscriber object
   objSubscriber.SetMbrValue(m_pApp->m_ADP.m_pMbr_Subscriber_username, username) ;
   pLog->Log("Set subscriber username to %s\n", *username) ;
   //  Step 2: Establish email address
   rc = m_pApp->PcEntConv(atom, emaStr, pE) ;
   if (rc != E_OK)
       return hzwarn(rc, "Error during conversion of password %s", *ema) ;
   ema = atom.Str() ;
   objSubscriber.SetMbrValue(m_pApp->m_ADP.m_pMbr_Subscriber_email, ema) ;
   pLog->Log("Set subscriber email %s to %s\n", *ema, *atom.Str()) ;
   //  Step 3: Establish password
   rc = m_pApp->PcEntConv(atom, password, pE) ;
   if (rc != E_OK)
       return hzwarn(rc, "Error during conversion of password %s", *password) ;
   objSubscriber.SetMbrValue(m_pApp->m_ADP.m_pMbr_Subscriber_userpass, atom.Str()) ;
   pLog->Log("Set subscriber password %s to %s\n", *password, *atom.Str()) ;
   //  Step 4: Set userUID. This is always the current population of susbsriber cache
   atom = m_pApp->m_ADP.m_pReposSubscriber->Count() + 1;
   objSubscriber.SetValue(m_pApp->m_ADP.m_pMbr_Subscriber_UID, atom) ;
   pLog->Log("subscriber UID = %s\n", *atom.Str()) ;
   return E_OK ;
}