From 5221ee0c5aaca5588e20683f397fec9d1d6e98c7 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@owncloud.com>
Date: Tue, 5 Feb 2013 14:58:35 +0100
Subject: [PATCH] offer change password only when the action is supported by
 the user backend

---
 lib/user.php                    | 18 ++++++++++++++++++
 settings/personal.php           |  1 +
 settings/templates/personal.php |  7 ++++++-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/lib/user.php b/lib/user.php
index 38259bceea..f953d22154 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -419,6 +419,24 @@ class OC_User {
 		}
 	}
 
+	/**
+	 * @brief Check whether user can change his password
+	 * @param $uid The username
+	 * @returns true/false
+	 *
+	 * Check whether a specified user can change his password
+	 */
+	public static function canUserChangePassword($uid) {
+		foreach(self::$_usedBackends as $backend) {
+			if($backend->implementsActions(OC_USER_BACKEND_SET_PASSWORD)) {
+				if($backend->userExists($uid)) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
 	/**
 	 * @brief Check if the password is correct
 	 * @param $uid The username
diff --git a/settings/personal.php b/settings/personal.php
index 4624bda839..a2e510a6d3 100644
--- a/settings/personal.php
+++ b/settings/personal.php
@@ -47,6 +47,7 @@ $tmpl->assign('total_space', OC_Helper::humanFileSize($storageInfo['total']));
 $tmpl->assign('usage_relative', $storageInfo['relative']);
 $tmpl->assign('email', $email);
 $tmpl->assign('languages', $languages);
+$tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
 
 $forms=OC_App::getForms('personal');
 $tmpl->assign('forms', array());
diff --git a/settings/templates/personal.php b/settings/templates/personal.php
index 0e1677bdea..b1cc671392 100644
--- a/settings/templates/personal.php
+++ b/settings/templates/personal.php
@@ -15,7 +15,9 @@
 	<a class="button" href="https://itunes.apple.com/us/app/owncloud/id543672169?mt=8" target="_blank"><?php echo $l->t('Download iOS Client');?></a>
 </fieldset>
 
-
+<?php
+if($_['passwordChangeSupported']) {
+?>
 <form id="passwordform">
 	<fieldset class="personalblock">
 		<legend><strong><?php echo $l->t('Password');?></strong></legend>
@@ -27,6 +29,9 @@
 		<input id="passwordbutton" type="submit" value="<?php echo $l->t('Change password');?>" />
 	</fieldset>
 </form>
+<?php
+}
+?>
 
 <form id="lostpassword">
 	<fieldset class="personalblock">
-- 
GitLab