Present a dialog window with username and password when account authentication fails.

git-svn-id: http://voip.null.ro/svn/yate@4678 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2011-11-04 15:54:44 +00:00
parent 5b718f2810
commit 89a2e00cda
4 changed files with 414 additions and 31 deletions

View File

@ -493,6 +493,16 @@ static inline void dumpList(const NamedList& p, const char* text, Window* w = 0)
#endif
}
// Check reason and error for auth failure texts
static bool isNoAuth(const String& reason, const String& error)
{
static const String s_noAuth[] = {"noauth", "not-authorized", "invalid-authzid", ""};
for (int i = 0; s_noAuth[i]; i++)
if (reason == s_noAuth[i] || error == s_noAuth[i])
return true;
return false;
}
// Split user@domain
static inline void splitContact(const String& contact, String& user, String& domain)
{
@ -1289,13 +1299,61 @@ static Window* getAccPasswordWnd(const String& account, bool create)
text << "Enter password for account '" << account << "'";
p.addParam("inputpwd_text",text);
p.addParam("inputpwd_password","");
p.addParam("check::inputpwd_savepassword",String::boolText(false));
p.addParam("check:inputpwd_savepassword",String::boolText(false));
p.addParam("context","loginpassword:" + account);
Client::self()->setParams(&p,w);
Client::self()->setVisible(wname,true,true);
return w;
}
// Close an account's password window
static void closeAccPasswordWnd(const String& account)
{
Window* w = getAccPasswordWnd(account,false);
if (w)
Client::self()->closeWindow(w->toString());
}
// Retrieve an account's enter credentials window
// Create it if requested and not found.
static Window* getAccCredentialsWnd(const NamedList& account, bool create,
const String& text = String::empty())
{
if (!(Client::valid() && account))
return 0;
String wname(account + "EnterCredentials");
Window* w = Client::self()->getWindow(wname);
if (!create)
return w;
if (!w) {
Client::self()->createWindowSafe(YSTRING("inputacccred"),wname);
w = Client::self()->getWindow(wname);
if (!w) {
Debug(ClientDriver::self(),DebugNote,"Failed to build account credentials window!");
return 0;
}
}
NamedList p("");
p.addParam("inputacccred_text",text);
p.addParam("inputacccred_username",account.getValue(YSTRING("username")));
p.addParam("inputacccred_password",account.getValue(YSTRING("password")));
p.addParam("check:inputacccred_savepassword",
String(account.getBoolValue(YSTRING("savepassword"))));
p.addParam("context","logincredentials:" + account);
Client::self()->setParams(&p,w);
Client::self()->setVisible(wname,true,true);
return w;
}
// Close an account's enter credentials window
static void closeAccCredentialsWnd(const String& account)
{
NamedList tmp(account);
Window* w = getAccCredentialsWnd(tmp,false);
if (w)
Client::self()->closeWindow(w->toString());
}
// Build a chat history item parameter list
static NamedList* buildChatParams(const char* text, const char* sender,
unsigned int sec, bool delay = false, const char* delaysource = 0)
@ -1700,7 +1758,8 @@ static bool getAccount(Window* w, NamedList& p, ClientAccountList& accounts)
String host;
if (!getAccount(w,&proto,&user,&host))
return false;
p.assign(proto + ":" + user + "@" + host);
String id;
p.assign(DefaultLogic::buildAccountId(id,proto,user,host));
p.addParam("enabled",String::boolText(true));
// Account flags
p.addParam("protocol",proto);
@ -4565,20 +4624,10 @@ bool DefaultLogic::action(Window* wnd, const String& name, NamedList* params)
return true;
if (name == YSTRING("textchanged"))
return handleTextChanged(params,wnd);
if (name.startsWith("loginpassword:")) {
String account = name.substr(14);
ClientAccount* acc = account ? m_accounts->findAccount(account) : 0;
if (!acc)
return false;
saveParam(acc->m_params,YSTRING("inputpwd_"),YSTRING("password"),wnd);
saveCheckParam(acc->m_params,YSTRING("inputpwd_"),YSTRING("savepassword"),wnd);
acc->save(true,acc->params().getBoolValue(YSTRING("savepassword")));
if (acc->startup()) {
setAccountStatus(m_accounts,acc,0,0,false);
return true;
}
return ::loginAccount(this,acc->params(),true,false);
}
// Input password/credentials
bool inputPwd = name.startsWith("loginpassword:");
if (inputPwd || name.startsWith("logincredentials:"))
return handleAccCredInput(wnd,name.substr(inputPwd ? 14 : 17),inputPwd);
if (name == s_actionShowCallsList) {
if (Client::valid()) {
Client::self()->ringer(true,false);
@ -5263,9 +5312,8 @@ bool DefaultLogic::delAccount(const String& account, Window* wnd)
Engine::enqueue(userLogin(acc,false));
// Delete from memory and UI. Save the accounts file
removeAccNotifications(acc);
Window* w = getAccPasswordWnd(account,false);
if (w)
Client::self()->closeWindow(w->toString());
closeAccPasswordWnd(account);
closeAccCredentialsWnd(account);
clearAccountContacts(*acc);
updateChatRoomsContactList(false,acc);
Client::self()->delTableRow(s_account,account);
@ -5877,7 +5925,8 @@ bool DefaultLogic::handleUserNotify(Message& msg, bool& stopLogic)
if (!account)
return false;
bool reg = msg.getBoolValue(YSTRING("registered"));
const char* reason = msg.getValue(YSTRING("reason"));
const String& reasonStr = msg[YSTRING("reason")];
const char* reason = reasonStr;
// Notify wizards
s_mucWizard->handleUserNotify(account,reg,reason);
bool save = s_accWizard->handleUserNotify(account,reg,reason);
@ -5897,6 +5946,8 @@ bool DefaultLogic::handleUserNotify(Message& msg, bool& stopLogic)
if (reg) {
// Remove account failure notification if still there
removeNotifArea(YSTRING("loginfail"),account);
closeAccPasswordWnd(account);
closeAccCredentialsWnd(account);
// Clear account register option
NamedString* opt = acc->m_params.getParam(YSTRING("options"));
if (opt) {
@ -5936,16 +5987,29 @@ bool DefaultLogic::handleUserNotify(Message& msg, bool& stopLogic)
bool reConn = acc->params().getBoolValue(YSTRING("internal.reconnect"));
// Show login failure message if not requested by the user
if (!(noFail || reConn)) {
NamedList rows("");
NamedList* upd = buildNotifArea(rows,"loginfail",account,String::empty(),"Login failure");
String text;
text << "Failed to connect account '" << account << "'";
text.append(reason,"\r\nReason: ");
upd->addParam("text",text);
// Enable/disable account edit
const char* ok = String::boolText(!Client::self()->getVisible(s_wndAccount));
upd->addParam("active:messages_acc_edit",ok);
showNotificationArea(true,Client::self()->getWindow(s_wndMain),&rows);
const String& error = msg[YSTRING("error")];
bool noAuth = isNoAuth(reasonStr,error);
String text(noAuth ? "Login failed for account '" : "Failed to connect account '");
text << account << "'";
if (reasonStr || error) {
text << "\r\nReason: ";
if (reasonStr) {
text << reasonStr;
if (error && reasonStr != error)
text << " (" << error << ")";
}
else
text << error;
}
if (!(noAuth && getAccCredentialsWnd(acc->params(),true,text))) {
NamedList rows("");
NamedList* upd = buildNotifArea(rows,"loginfail",account,String::empty(),"Login failure");
upd->addParam("text",text);
// Enable/disable account edit
const char* ok = String::boolText(!Client::self()->getVisible(s_wndAccount));
upd->addParam("active:messages_acc_edit",ok);
showNotificationArea(true,Client::self()->getWindow(s_wndMain),&rows);
}
}
if (msg.getBoolValue(YSTRING("autorestart")))
stat = ClientResource::Connecting;
@ -7833,7 +7897,7 @@ bool DefaultLogic::updateAccount(const NamedList& account, bool save,
const String& user = account[YSTRING("username")];
const char* host = account.getValue(YSTRING("domain"),account.getValue(YSTRING("server")));
if (proto && user && host)
id.assign(proto + ":" + user + "@" + host);
buildAccountId(id,proto,user,host);
else {
updAccDelOld(old,this);
Debug(ClientDriver::self(),DebugNote,
@ -8977,6 +9041,47 @@ bool DefaultLogic::storeContact(ClientContact* c)
return true;
}
// Handle ok from account password/credentials input window
bool DefaultLogic::handleAccCredInput(Window* wnd, const String& name, bool inputPwd)
{
ClientAccount* acc = name ? m_accounts->findAccount(name) : 0;
if (!acc)
return false;
String prefix = inputPwd ? "inputpwd_" : "inputacccred_";
String pwd;
Client::self()->getText(prefix + "password",pwd,false,wnd);
if (!pwd)
return showError(wnd,"Account password is mandatory");
// Check username changes
if (!inputPwd) {
String user;
Client::self()->getText(prefix + "username",user,false,wnd);
if (!user)
return showError(wnd,"Account username is mandatory");
if (user != acc->params()[YSTRING("username")]) {
String newId;
buildAccountId(newId,acc->protocol(),user,
acc->params().getValue("domain",acc->params().getValue("server")));
if (m_accounts->findAccount(newId))
return showAccDupError(wnd);
NamedList account(acc->params());
account.assign(newId);
account.setParam("username",user);
account.setParam("password",pwd);
saveCheckParam(account,prefix,YSTRING("savepassword"),wnd);
return updateAccount(account,true,name);
}
}
acc->m_params.setParam("password",pwd);
saveCheckParam(acc->m_params,prefix,YSTRING("savepassword"),wnd);
acc->save(true,acc->params().getBoolValue(YSTRING("savepassword")));
if (acc->startup()) {
setAccountStatus(m_accounts,acc,0,0,false);
return true;
}
return ::loginAccount(this,acc->params(),true,false);
}
/**
* DurationUpdate

View File

@ -0,0 +1,257 @@
<ui version="4.0" >
<class>inputacccred</class>
<widget class="QWidget" name="inputacccred" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>200</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>400</width>
<height>200</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>400</width>
<height>200</height>
</size>
</property>
<property name="windowTitle" >
<string>Enter account credentials</string>
</property>
<property name="windowIcon" >
<iconset>user.png</iconset>
</property>
<property name="styleSheet" >
<string>QWidget {font-size: 11px; color: black;}
QLabel {background: none;}
QTextEdit { background: transparent; }
QLineEdit {
background: none;
border: 1px solid #97acbc;
border-radius: 2px;
}
</string>
</property>
<property name="_yate_windowflags" stdset="0" >
<string>title,sysmenu,close</string>
</property>
<property name="_yate_destroyonclose" stdset="0" >
<bool>true</bool>
</property>
<property name="_yate_destroyonhide" stdset="0" >
<bool>true</bool>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>2</number>
</property>
<property name="leftMargin" >
<number>6</number>
</property>
<property name="topMargin" >
<number>10</number>
</property>
<property name="rightMargin" >
<number>6</number>
</property>
<property name="bottomMargin" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="inputacccred_text" >
<property name="sizePolicy" >
<sizepolicy vsizetype="MinimumExpanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>6</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Username:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="inputacccred_username" >
<property name="minimumSize" >
<size>
<width>0</width>
<height>22</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Password:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="inputacccred_password" >
<property name="minimumSize" >
<size>
<width>0</width>
<height>22</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>22</height>
</size>
</property>
<property name="echoMode" >
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="inputacccred_savepassword" >
<property name="minimumSize" >
<size>
<width>0</width>
<height>16</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>16</height>
</size>
</property>
<property name="text" >
<string>Save password</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="ok" >
<property name="text" >
<string>Retry</string>
</property>
<property name="icon" >
<iconset>ok.png</iconset>
</property>
<property name="shortcut" >
<string>Return</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_hide" >
<property name="text" >
<string>Cancel</string>
</property>
<property name="icon" >
<iconset>close.png</iconset>
</property>
<property name="shortcut" >
<string>Esc</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -54,6 +54,11 @@ enabled=false
save=false
description=inputpwd.ui
[inputacccred]
enabled=false
save=false
description=inputacccred.ui
[account]
enabled=true
description=account.ui

View File

@ -3058,6 +3058,20 @@ public:
*/
virtual void engineStart(Message& msg);
/**
* Build an account id from protocol, username, host
* @param id Destination string
* @param proto Account protocol
* @param user Account username
* @param host Account host
* @return Destination string address
*/
static inline String& buildAccountId(String& id, const String& proto,
const String& user, const String& host) {
id = proto + ":" + user + "@" + host;
return id;
}
protected:
/**
* Method called by the client when idle.
@ -3247,6 +3261,8 @@ private:
bool handleNotificationAreaAction(const String& action, Window* wnd);
// Save a contact to config. Save chat rooms if the contact is a chat room
bool storeContact(ClientContact* c);
// Handle ok from account password/credentials input window
bool handleAccCredInput(Window* wnd, const String& name, bool inputPwd);
ClientAccountList* m_accounts; // Accounts list (always valid)
};