Logo Search packages:      
Sourcecode: sbnc version File versions  Download package

RESULT< CUser * > CCore::CreateUser ( const char *  Username,
const char *  Password 
)

CreateUser

Creates a new user. If the specified username is already in use that user's password will be re-set instead.

Parameters:
Username name of the new account
Password the new user's password

Definition at line 1085 of file Core.cpp.

References CVector< Type >::GetLength(), GetUser(), IsValidUsername(), CUser::LoadEvent(), Log(), m_Modules, m_Users, CUser::SetPassword(), and UpdateUserConfig().

Referenced by CClientConnection::ProcessBncCommand().

                                                                            {
      CUser *User;
      RESULT<bool> Result;

      User = GetUser(Username);

      if (User != NULL) {
            if (Password != NULL) {
                  User->SetPassword(Password);
            }

            RETURN(CUser *, User);
      }

      if (!IsValidUsername(Username)) {
            THROW(CUser *, Generic_Unknown, "The username you specified is not valid.");
      }

      safe_box_t UsersBox, UserBox = NULL;

      UsersBox = safe_get_box(NULL, "Users");

      if (UsersBox != NULL) {
            UserBox = safe_put_box(UsersBox, Username);
      }

      User = new CUser(Username, UserBox);

      Result = m_Users.Add(Username, User);

      if (IsError(Result)) {
            delete User;

            THROWRESULT(CUser *, Result);
      }

      if (Password != NULL) {
            User->SetPassword(Password);
      }

      Log("New user created: %s", Username);

      UpdateUserConfig();

      for (unsigned int i = 0; i < m_Modules.GetLength(); i++) {
            m_Modules[i]->UserCreate(Username);
      }

      User->LoadEvent();

      RETURN(CUser *, User);
}


Generated by  Doxygen 1.6.0   Back to index