Skip to content

Commit

Permalink
Add a /Myth/ChangePassword service to the backend.
Browse files Browse the repository at this point in the history
Since we now have basic authentication working for the backend
webserver, add a service which we can use to change that password.
Setup page code will be in my next commit.

NOTE: This does modify the binary API version, so make clean, etc..
  • Loading branch information
cpinkham committed Mar 26, 2011
1 parent effc903 commit 3b2fbdd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
#define MYTH_BINARY_VERSION "0.25.20110324-1"
#define MYTH_BINARY_VERSION "0.25.20110326-1"

/** \brief Increment this whenever the MythTV network protocol changes.
*
Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythservicecontracts/services/mythServices.h
Expand Up @@ -54,6 +54,7 @@ class SERVICE_PUBLIC MythServices : public Service //, public QScriptable ???
Q_CLASSINFO( "PutSetting_Method", "POST" )
Q_CLASSINFO( "AddStorageGroupDir_Method", "POST" )
Q_CLASSINFO( "RemoveStorageGroupDir_Method", "POST" )
Q_CLASSINFO( "ChangePassword_Method", "POST" )

public:

Expand Down Expand Up @@ -94,6 +95,9 @@ class SERVICE_PUBLIC MythServices : public Service //, public QScriptable ???
const QString &Key,
const QString &Value ) = 0;

virtual bool ChangePassword ( const QString &UserName,
const QString &OldPassword,
const QString &NewPassword ) = 0;
};

#endif
Expand Down
45 changes: 45 additions & 0 deletions mythtv/programs/mythbackend/services/myth.cpp
Expand Up @@ -469,3 +469,48 @@ bool Myth::PutSetting( const QString &sHostName,
throw ( QString( "Key Required" ));
}

/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

bool Myth::ChangePassword( const QString &sUserName,
const QString &sOldPassword,
const QString &sNewPassword )
{
bool bResult = false;

if (sUserName.isEmpty())
{
throw ( QString( "UserName not supplied when trying to change "
"password." ) );
}

if (sOldPassword.isEmpty())
{
throw ( QString( "Old Password not supplied when trying to change "
"password for '%1'." ).arg(sUserName) );
}

if (sNewPassword.isEmpty())
{
throw ( QString( "New Password not supplied when trying to change "
"password for '%1'." ).arg(sUserName) );
}

if (sOldPassword !=
gCoreContext->GetSetting( "HTTP/Protected/Password", ""))
{
throw ( QString( "Incorrect Old Password supplied when trying to "
"change password for '%1'." ).arg(sUserName) );
}

if (gCoreContext->SaveSettingOnHost( "HTTP/Protected/Password", sNewPassword,
QString() ) )
{
gCoreContext->ClearSettingsCache();
bResult = true;
}

return bResult;
}

4 changes: 4 additions & 0 deletions mythtv/programs/mythbackend/services/myth.h
Expand Up @@ -60,6 +60,10 @@ class Myth : public MythServices
bool PutSetting ( const QString &HostName,
const QString &Key,
const QString &Value );

bool ChangePassword ( const QString &UserName,
const QString &OldPassword,
const QString &NewPassword );
};

// --------------------------------------------------------------------------
Expand Down

0 comments on commit 3b2fbdd

Please sign in to comment.