2121
2222namespace OCA \UserSQL \Backend ;
2323
24- use OC \User \Backend ;
2524use OCA \UserSQL \Action \EmailSync ;
2625use OCA \UserSQL \Action \IUserAction ;
2726use OCA \UserSQL \Action \QuotaSync ;
3635use OCP \IConfig ;
3736use OCP \IL10N ;
3837use OCP \ILogger ;
38+ use OCP \User \Backend \ABackend ;
39+ use OCP \User \Backend \ICheckPasswordBackend ;
40+ use OCP \User \Backend \ICountUsersBackend ;
41+ use OCP \User \Backend \IGetDisplayNameBackend ;
42+ use OCP \User \Backend \IGetHomeBackend ;
43+ use OCP \User \Backend \IProvideAvatarBackend ;
44+ use OCP \User \Backend \ISetDisplayNameBackend ;
45+ use OCP \User \Backend \ISetPasswordBackend ;
3946
4047/**
4148 * The SQL user backend manager.
4249 *
4350 * @author Marcin Łojewski <dev@mlojewski.me>
4451 */
45- final class UserBackend extends Backend
52+ final class UserBackend extends ABackend implements
53+ ICheckPasswordBackend,
54+ ICountUsersBackend,
55+ IGetDisplayNameBackend,
56+ IGetHomeBackend,
57+ IProvideAvatarBackend,
58+ ISetDisplayNameBackend,
59+ ISetPasswordBackend
4660{
4761 /**
4862 * @var string The application name.
@@ -237,7 +251,7 @@ private function getUser($uid)
237251 /**
238252 * @inheritdoc
239253 */
240- public function getDisplayName ($ uid )
254+ public function getDisplayName ($ uid ): string
241255 {
242256 $ this ->logger ->debug (
243257 "Entering getDisplayName( $ uid) " , ["app " => $ this ->appName ]
@@ -267,7 +281,7 @@ public function getDisplayName($uid)
267281 *
268282 * @return string|bool The user ID on success, false otherwise.
269283 */
270- public function checkPassword ($ uid , $ password )
284+ public function checkPassword (string $ uid , string $ password )
271285 {
272286 $ this ->logger ->debug (
273287 "Entering checkPassword( $ uid, *) " , ["app " => $ this ->appName ]
@@ -346,6 +360,10 @@ public function getDisplayNames($search = "", $limit = null, $offset = null)
346360 ["app " => $ this ->appName ]
347361 );
348362
363+ if (empty ($ this ->properties [DB ::USER_NAME_COLUMN ])) {
364+ return false ;
365+ }
366+
349367 $ users = $ this ->getUsers ($ search , $ limit , $ offset );
350368
351369 $ names = [];
@@ -419,12 +437,16 @@ function ($user) {
419437 *
420438 * @return bool TRUE if the password has been set, FALSE otherwise.
421439 */
422- public function setPassword ($ uid , $ password )
440+ public function setPassword (string $ uid , string $ password ): bool
423441 {
424442 $ this ->logger ->debug (
425443 "Entering setPassword( $ uid, *) " , ["app " => "user_sql " ]
426444 );
427445
446+ if (empty ($ this ->properties [Opt::PASSWORD_CHANGE ])) {
447+ return false ;
448+ }
449+
428450 $ passwordAlgorithm = $ this ->getPasswordAlgorithm ();
429451 if ($ passwordAlgorithm === false ) {
430452 return false ;
@@ -461,12 +483,16 @@ public function setPassword($uid, $password)
461483 /**
462484 * @inheritdoc
463485 */
464- public function getHome ($ uid )
486+ public function getHome (string $ uid )
465487 {
466488 $ this ->logger ->debug (
467489 "Entering getHome( $ uid) " , ["app " => $ this ->appName ]
468490 );
469491
492+ if (empty ($ this ->properties [Opt::HOME_MODE ])) {
493+ return false ;
494+ }
495+
470496 $ home = false ;
471497 switch ($ this ->properties [Opt::HOME_MODE ]) {
472498 case App::HOME_STATIC :
@@ -496,12 +522,16 @@ public function getHome($uid)
496522 *
497523 * @return bool TRUE if the user can change its avatar, FALSE otherwise.
498524 */
499- public function canChangeAvatar ($ uid )
525+ public function canChangeAvatar (string $ uid ): bool
500526 {
501527 $ this ->logger ->debug (
502528 "Entering canChangeAvatar( $ uid) " , ["app " => $ this ->appName ]
503529 );
504530
531+ if (empty ($ this ->properties [DB ::USER_AVATAR_COLUMN ])) {
532+ return false ;
533+ }
534+
505535 $ user = $ this ->userRepository ->findByUid ($ uid );
506536 if (!($ user instanceof User)) {
507537 return false ;
@@ -524,13 +554,17 @@ public function canChangeAvatar($uid)
524554 *
525555 * @return bool TRUE if the password has been set, FALSE otherwise.
526556 */
527- public function setDisplayName ($ uid , $ displayName )
557+ public function setDisplayName (string $ uid , string $ displayName ): bool
528558 {
529559 $ this ->logger ->debug (
530560 "Entering setDisplayName( $ uid, $ displayName) " ,
531561 ["app " => $ this ->appName ]
532562 );
533563
564+ if (empty ($ this ->properties [Opt::NAME_CHANGE ])) {
565+ return false ;
566+ }
567+
534568 $ user = $ this ->userRepository ->findByUid ($ uid );
535569 if (!($ user instanceof User)) {
536570 return false ;
@@ -550,28 +584,6 @@ public function setDisplayName($uid, $displayName)
550584 return false ;
551585 }
552586
553- /**
554- * @inheritdoc
555- */
556- public function getSupportedActions ()
557- {
558- $ actions = parent ::getSupportedActions ();
559-
560- $ actions &= empty ($ this ->properties [DB ::USER_NAME_COLUMN ])
561- ? ~Backend::GET_DISPLAYNAME : ~0 ;
562- $ actions &= empty ($ this ->properties [Opt::HOME_MODE ])
563- ? ~Backend::GET_HOME : ~0 ;
564- $ actions &= empty ($ this ->properties [DB ::USER_AVATAR_COLUMN ])
565- ? ~Backend::PROVIDE_AVATAR : ~0 ;
566- $ actions &= (!empty ($ this ->properties [DB ::USER_NAME_COLUMN ])
567- && $ this ->properties [Opt::NAME_CHANGE ]) ? ~0
568- : ~Backend::SET_DISPLAYNAME ;
569- $ actions &= $ this ->properties [Opt::PASSWORD_CHANGE ] ? ~0
570- : ~Backend::SET_PASSWORD ;
571-
572- return $ actions ;
573- }
574-
575587 /**
576588 * Check if this backend is correctly set and can be enabled.
577589 *
@@ -589,4 +601,20 @@ public function isConfigured()
589601 && !empty ($ this ->properties [DB ::USER_PASSWORD_COLUMN ])
590602 && !empty ($ this ->properties [Opt::CRYPTO_CLASS ]);
591603 }
604+
605+ /**
606+ * @inheritdoc
607+ */
608+ public function getBackendName ()
609+ {
610+ return "User SQL " ;
611+ }
612+
613+ /**
614+ * @inheritdoc
615+ */
616+ public function deleteUser ($ uid )
617+ {
618+ return false ;
619+ }
592620}
0 commit comments