Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17172 | Rev 17176 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17172 Rev 17174
Línea 1976... Línea 1976...
1976
        return new JsonModel($data);
1976
        return new JsonModel($data);
1977
    }
1977
    }
Línea 1978... Línea 1978...
1978
 
1978
 
1979
 
1979
 
1980
    /**
1980
    /**
1981
     * Handles the editing of user details including type, verification, block status, and user status.
1981
     * Handles the change of user type.
1982
     *
1982
     *
1983
     * This action supports both GET and POST requests:
1983
     * This action supports both GET and POST requests:
1984
     * - GET: Retrieves the current user details for a given user UUID.
1984
     * - GET: Retrieves the current user type for a given user UUID.
1985
     * - POST: Updates the user details based on the provided data.
1985
     * - POST: Updates the user type based on the provided data.
1986
     *
1986
     *
1987
     * @return JsonModel
1987
     * @return JsonModel
1988
     */
1988
     */
1989
    public function editUserDetailsAction()
1989
    public function changeTypeAction()
1990
    {
1990
    {
1991
        // Retrieve the current user and request objects
1991
        // Retrieve the current user and request objects
Línea 1992... Línea 1992...
1992
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1992
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 1993... Línea 1993...
1993
        $currentUser = $currentUserPlugin->getUser();
1993
        $currentUser = $currentUserPlugin->getUser();
1994
 
1994
 
1995
        $request = $this->getRequest();
1995
        $request = $this->getRequest();
1996
 
1996
 
1997
        // Handle GET request to fetch current user details
1997
        // Handle GET request to fetch current user type and additional fields
1998
        if ($request->isGet()) {
1998
        if ($request->isGet()) {
Línea 2010... Línea 2010...
2010
            if ($user) {
2010
            if ($user) {
2011
                return new JsonModel([
2011
                return new JsonModel([
2012
                    'success'   => true,
2012
                    'success'   => true,
2013
                    'data'      => [
2013
                    'data'      => [
2014
                        'usertype_id' => $user->usertype_id,
2014
                        'usertype_id' => $user->usertype_id,
2015
                        'email_verified' => $user->email_verified,
2015
                        'is_verified' => $user->is_verified,
2016
                        'blocked' => $user->blocked,
2016
                        'is_blocked' => $user->is_blocked,
2017
                        'status' => $user->status,
2017
                        'status' => $user->status,
2018
                    ]
2018
                    ]
2019
                ]);
2019
                ]);
2020
            } else {
2020
            } else {
2021
                return new JsonModel([
2021
                return new JsonModel([
Línea 2023... Línea 2023...
2023
                    'data'      => 'ERROR_USER_NOT_FOUND'
2023
                    'data'      => 'ERROR_USER_NOT_FOUND'
2024
                ]);
2024
                ]);
2025
            }
2025
            }
2026
        }
2026
        }
Línea 2027... Línea 2027...
2027
 
2027
 
2028
        // Handle POST request to update user details
2028
        // Handle POST request to update user type and additional fields
2029
        if ($request->isPost()) {
2029
        if ($request->isPost()) {
2030
            $uuid = $this->params()->fromRoute('id');
2030
            $uuid = $this->params()->fromRoute('id');
2031
            if (!$uuid) {
2031
            if (!$uuid) {
2032
                return new JsonModel([
2032
                return new JsonModel([
Línea 2045... Línea 2045...
2045
                ]);
2045
                ]);
2046
            }
2046
            }
Línea 2047... Línea 2047...
2047
 
2047
 
2048
            // Validate and process form data
2048
            // Validate and process form data
2049
            $dataPost = $request->getPost()->toArray();
2049
            $dataPost = $request->getPost()->toArray();
2050
            $form = new ChangeTypeForm(); // Assuming this form can handle all fields
2050
            $form = new ChangeTypeForm();
Línea 2051... Línea 2051...
2051
            $form->setData($dataPost);
2051
            $form->setData($dataPost);
2052
 
2052
 
Línea 2053... Línea 2053...
2053
            if ($form->isValid()) {
2053
            if ($form->isValid()) {
2054
                $dataPost = (array) $form->getData();
2054
                $dataPost = (array) $form->getData();
2055
 
2055
 
2056
                // Update the user details in the database
2056
                // Update the user type and additional fields in the database
2057
                $user->usertype_id = $dataPost['usertype_id'];
2057
                $result = $userMapper->updateUserTypeId($user, $dataPost['usertype_id']);
-
 
2058
                $user->is_verified = $dataPost['is_verified'];
Línea 2058... Línea -...
2058
                $user->email_verified = $dataPost['email_verified'];
-
 
2059
                $user->blocked = $dataPost['blocked'];
2059
                $user->is_blocked = $dataPost['is_blocked'];
2060
                $user->status = $dataPost['status'];
2060
                $user->status = $dataPost['status'];
Línea 2061... Línea 2061...
2061
 
2061
                $userMapper->save($user);
2062
                $result = $userMapper->update($user);
2062
 
2063
                if ($result) {
2063
                if ($result) {
2064
                    $this->logger->info('User details updated', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2064
                    $this->logger->info('Cambio del tipo de usuario y otros campos realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2065
 
2065
 
2066
                    return new JsonModel([
2066
                    return new JsonModel([
Línea 2067... Línea 2067...
2067
                        'success'   => true,
2067
                        'success'   => true,
2068
                        'data'      => 'LABEL_USER_DETAILS_UPDATED'
2068
                        'data'      => 'LABEL_USER_CHANGE_TYPE_HAS_BEEN_UPDATED'
2069
                    ]);
2069
                    ]);
2070
                } else {
2070
                } else {
2071
                    $this->logger->err('Error updating user details', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2071
                    $this->logger->err('Cambio del tipo de usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2072
 
2072
 
2073
                    return new JsonModel([
2073
                    return new JsonModel([