Support for password not stored locally.

This commit is contained in:
Klaas Freitag 2012-04-12 14:06:59 +02:00
parent 3fede657b9
commit b8434a8d56
6 changed files with 64 additions and 12 deletions

View file

@ -28,6 +28,9 @@
namespace Mirall {
QString MirallConfigFile::_passwd = QString();
bool MirallConfigFile::_askedUser = false;
MirallConfigFile::MirallConfigFile()
{
}
@ -108,12 +111,14 @@ bool MirallConfigFile::connectionExists( const QString& conn )
void MirallConfigFile::writeOwncloudConfig( const QString& connection,
const QString& url,
const QString& user,
const QString& passwd )
const QString& url,
const QString& user,
const QString& passwd,
bool skipPwd )
{
const QString file = configFile();
qDebug() << "*** writing mirall config to " << file;
QString pwd( passwd );
QSettings settings( file, QSettings::IniFormat);
QString cloudsUrl( url );
@ -124,8 +129,11 @@ void MirallConfigFile::writeOwncloudConfig( const QString& connection,
settings.beginGroup( connection );
settings.setValue("url", cloudsUrl );
settings.setValue("user", user );
settings.setValue("password", passwd );
if( skipPwd ) {
pwd = QString();
}
settings.setValue("password", pwd );
settings.setValue("nostoredpassword", QVariant(skipPwd) );
settings.sync();
// check the perms, only read-write for the owner.
@ -194,7 +202,25 @@ QString MirallConfigFile::ownCloudPasswd( const QString& connection ) const
QSettings settings( configFile(), QSettings::IniFormat );
settings.beginGroup( con );
QString pwd = settings.value( "password" ).toString();
QString pwd;
bool boolfalse( false );
bool skipPwd = settings.value( "nostoredpassword", QVariant(boolfalse) ).toBool();
if( skipPwd ) {
if( ! _askedUser ) {
bool ok;
QString text = QInputDialog::getText(0, QObject::tr("ownCloud Password Required"),
QObject::tr("Please enter your ownCloud password:"), QLineEdit::Password,
QString(), &ok);
if( ok && !text.isEmpty() ) { // empty password is not allowed on ownCloud
_passwd = text;
_askedUser = true;
}
}
pwd = _passwd;
} else {
pwd = settings.value( "password" ).toString();
}
return pwd;
}

View file

@ -35,7 +35,7 @@ public:
void writeOwncloudConfig( const QString& connection,
const QString& url,
const QString& user,
const QString& passwd );
const QString& passwd, bool skipPwd );
void removeConnection( const QString& connection = QString() );
@ -48,6 +48,10 @@ public:
bool ownCloudSkipUpdateCheck( const QString& connection = QString() ) const;
QByteArray basicAuthHeader() const;
private:
static QString _passwd;
static bool _askedUser;
};
}

View file

@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>587</width>
<width>576</width>
<height>374</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
@ -77,7 +77,7 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="2" column="0">
<layout class="QGridLayout" name="gridLayout">
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@ -115,6 +115,13 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="cbPwdNoLocalStore">
<property name="text">
<string>Do not store password on local machine.</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">

View file

@ -97,7 +97,8 @@ void OwncloudSetupWizard::testOwnCloudConnect()
cfgFile.writeOwncloudConfig( QString::fromLocal8Bit("ownCloud"),
_ocWizard->field("OCUrl").toString(),
_ocWizard->field("OCUser").toString(),
_ocWizard->field("OCPasswd").toString() );
_ocWizard->field("OCPasswd").toString(),
!(_ocWizard->field("cbPwdNoLocalStore").toBool()) );
// now start ownCloudInfo to check the connection.
if( _ocInfo->isConfigured() ) {

View file

@ -92,8 +92,11 @@ OwncloudCredentialsPage::OwncloudCredentialsPage()
_ui.setupUi(this);
registerField( "OCUser", _ui.OCUserEdit );
registerField( "OCPasswd", _ui.OCPasswdEdit );
registerField( "PwdNoLocalStore", _ui.cbPwdNoLocalStore );
connect( _ui.OCPasswdEdit, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
connect( _ui.cbPwdNoLocalStore, SIGNAL(stateChanged(int)), this, SLOT(slotPwdStoreChanged(int)));
}
OwncloudCredentialsPage::~OwncloudCredentialsPage()
@ -101,9 +104,18 @@ OwncloudCredentialsPage::~OwncloudCredentialsPage()
}
void OwncloudCredentialsPage::slotPwdStoreChanged( int state )
{
_ui.OCPasswdEdit->setEnabled( state == Qt::Unchecked );
emit completeChanged();
}
bool OwncloudCredentialsPage::isComplete() const
{
return !(_ui.OCPasswdEdit->text().isEmpty() );
if( _ui.cbPwdNoLocalStore->checkState() == Qt::Checked ) {
return !(_ui.OCUserEdit->text().isEmpty());
}
return !(_ui.OCUserEdit->text().isEmpty() || _ui.OCPasswdEdit->text().isEmpty() );
}
void OwncloudCredentialsPage::initializePage()

View file

@ -115,6 +115,8 @@ public:
virtual void initializePage();
virtual int nextId() const;
protected slots:
void slotPwdStoreChanged( int );
private:
Ui_OwncloudCredentialsPage _ui;