|
844 | 844 |
|
845 | 845 | break; |
846 | 846 |
|
847 | | - // |
848 | | - // Save user data from UCP |
849 | | - // |
850 | | - case 'submit-user-data': |
851 | | - $postData = json_decode(file_get_contents('php://input'), true, 512, JSON_THROW_ON_ERROR); |
852 | | - |
853 | | - $csrfToken = Filter::filterVar($postData[Token::PMF_SESSION_NAME], FILTER_SANITIZE_SPECIAL_CHARS); |
854 | | - |
855 | | - if (!Token::getInstance()->verifyToken('ucp', $csrfToken)) { |
856 | | - $response->setStatusCode(Response::HTTP_UNAUTHORIZED); |
857 | | - $response->setData(['error' => Translation::get('ad_msg_noauth')]); |
858 | | - break; |
859 | | - } |
860 | | - |
861 | | - $userId = Filter::filterVar($postData['userid'], FILTER_VALIDATE_INT); |
862 | | - $userName = trim((string) Filter::filterVar($postData['name'], FILTER_SANITIZE_SPECIAL_CHARS)); |
863 | | - $email = Filter::filterVar($postData['email'], FILTER_VALIDATE_EMAIL); |
864 | | - $isVisible = Filter::filterVar($postData['is_visible'], FILTER_SANITIZE_SPECIAL_CHARS); |
865 | | - $password = trim((string) Filter::filterVar($postData['faqpassword'], FILTER_SANITIZE_SPECIAL_CHARS)); |
866 | | - $confirm = trim((string) Filter::filterVar($postData['faqpassword_confirm'], FILTER_SANITIZE_SPECIAL_CHARS)); |
867 | | - $twoFactorEnabled = Filter::filterVar($postData['twofactor_enabled'] ?? 'off', FILTER_SANITIZE_SPECIAL_CHARS); |
868 | | - $deleteSecret = Filter::filterVar($postData['newsecret'] ?? '', FILTER_SANITIZE_SPECIAL_CHARS); |
869 | | - |
870 | | - $user = CurrentUser::getFromSession($faqConfig); |
871 | | - |
872 | | - $isAzureAdUser = $user->getUserAuthSource() === 'azure'; |
873 | | - |
874 | | - $secret = $deleteSecret === 'on' ? '' : $user->getUserData('secret'); |
875 | | - |
876 | | - if ($userId !== $user->getUserId()) { |
877 | | - $response->setStatusCode(Response::HTTP_BAD_REQUEST); |
878 | | - $response->setData(['error' => 'User ID mismatch!']); |
879 | | - break; |
880 | | - } |
881 | | - |
882 | | - if (!$isAzureAdUser) { |
883 | | - if ($password !== $confirm) { |
884 | | - $response->setStatusCode(Response::HTTP_CONFLICT); |
885 | | - $response->setData(['error' => Translation::get('ad_user_error_passwordsDontMatch')]); |
886 | | - break; |
887 | | - } |
888 | | - |
889 | | - if (strlen($password) <= 7 || strlen($confirm) <= 7) { |
890 | | - $response->setStatusCode(Response::HTTP_CONFLICT); |
891 | | - $response->setData(['error' => Translation::get('ad_passwd_fail')]); |
892 | | - break; |
893 | | - } else { |
894 | | - $userData = [ |
895 | | - 'display_name' => $userName, |
896 | | - 'email' => $email, |
897 | | - 'is_visible' => $isVisible === 'on' ? 1 : 0, |
898 | | - 'twofactor_enabled' => $twoFactorEnabled === 'on' ? 1 : 0, |
899 | | - 'secret' => $secret |
900 | | - ]; |
901 | | - |
902 | | - $success = $user->setUserData($userData); |
903 | | - |
904 | | - foreach ($user->getAuthContainer() as $auth) { |
905 | | - if ($auth->setReadOnly()) { |
906 | | - continue; |
907 | | - } |
908 | | - |
909 | | - if (!$auth->update($user->getLogin(), $password)) { |
910 | | - $response->setStatusCode(Response::HTTP_BAD_REQUEST); |
911 | | - $response->setData(['error' => $auth->error()]); |
912 | | - $success = false; |
913 | | - } else { |
914 | | - $success = true; |
915 | | - } |
916 | | - } |
917 | | - } |
918 | | - } else { |
919 | | - $userData = [ |
920 | | - 'is_visible' => $isVisible === 'on' ? 1 : 0, |
921 | | - 'twofactor_enabled' => $twoFactorEnabled === 'on' ? 1 : 0, |
922 | | - 'secret' => $secret |
923 | | - ]; |
924 | | - |
925 | | - $success = $user->setUserData($userData); |
926 | | - } |
927 | | - |
928 | | - if ($success) { |
929 | | - $response->setStatusCode(Response::HTTP_OK); |
930 | | - $response->setData(['success' => Translation::get('ad_entry_savedsuc')]); |
931 | | - } else { |
932 | | - $response->setStatusCode(Response::HTTP_BAD_REQUEST); |
933 | | - $response->setData(['error' => Translation::get('ad_entry_savedfail')]); |
934 | | - } |
935 | | - |
936 | | - break; |
937 | | - |
938 | 847 | // |
939 | 848 | // Change password |
940 | 849 | // |
|
0 commit comments