1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include "AccountManager.h"
24 #include "DatabaseMgr.h"
25 #include "EditorAccount.h"
26 #include "EditorNewAccount.h"
27 #include "FieldImpls.h"
32 EditorNewAccount::EditorNewAccount(UBSocket
* sock
) :
36 OnLine(Global::Get()->EmptyString
);
39 EditorNewAccount::~EditorNewAccount(void)
43 void EditorNewAccount::OnLine(const std::string
&line
)
45 if(!line
.compare("quit"))
47 m_sock
->Send("Allright, quitting!\n");
48 m_sock
->SetCloseAndDelete();
56 Assert(m_state
!= m_state
);
70 m_sock
->Send("Enter a name for your account please: \n");
74 if(mud::Managers::Get()->Account
->IllegalName(line
))
76 m_sock
->Sendf("You cannot use the name %s, please pick another name.\n", line
.c_str());
77 OnLine(Global::Get()->EmptyString
);
83 OnLine(Global::Get()->EmptyString
);
91 m_sock
->Sendf("Create an account named %s?\n", m_name
.c_str());
95 if(!line
.compare("n") || !line
.compare("no"))
97 m_sock
->Send("Let's try again then.\n");
99 OnLine(Global::Get()->EmptyString
);
103 if(line
.compare("y") && line
.compare("yes"))
105 OnLine(Global::Get()->EmptyString
);
106 m_sock
->Send("yes/no?\n");
111 OnLine(Global::Get()->EmptyString
);
113 } /* case M_NAMECONFIRM: */
119 m_sock
->Send("Please choose a password: \n");
125 OnLine(Global::Get()->EmptyString
);
127 } /* case M_PASSWORD: */
129 case M_PASSWORDCONFIRM
:
133 m_sock
->Send("Please confirm your password: \n");
137 if(m_password
.compare(line
))
139 m_sock
->Send("Passwords do not match, let's try again!\n");
140 m_state
= M_PASSWORD
;
141 OnLine(Global::Get()->EmptyString
);
145 m_sock
->Sendf("Your password is set.\n", line
.c_str());
146 m_sock
->Send("Please hit enter to continue.\n");
149 } /* case M_PASSWORDCONFIRM: */
155 m_sock
->Send("Please hit enter to continue.\n");
159 KeysPtr newaccountkeys
= mud::Managers::Get()->Account
->Add();
160 value_type id
= newaccountkeys
->first()->getIntegerValue();
163 m_sock
->Send("Could not create a new account.\n");
164 m_sock
->SetCloseAndDelete();
168 mud::AccountPtr Acc
= mud::Managers::Get()->Account
->GetByKey(id
);
169 Acc
->setName(m_name
);
170 Acc
->setPassword(m_password
);
173 m_sock
->Sendf("Account %s created, enjoy!\n", m_name
.c_str());
174 m_sock
->SetAccount(Acc
);
175 m_sock
->SetEditor(new EditorAccount(m_sock
), true);
179 } /* switch(state) */
183 void EditorNewAccount::OnEmptyLine()
185 OnLine(Global::Get()->EmptyString
);
189 bool EditorNewAccount::canReceiveChannel(mud::ChannelPtr channel
) const
191 if(!channel
->needLogin())
197 bool EditorNewAccount::supportPrefixes() const