Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17171 Rev 17172
Línea 1975... Línea 1975...
1975
 
1975
 
1976
        return new JsonModel($data);
1976
        return new JsonModel($data);
Línea -... Línea 1977...
-
 
1977
    }
-
 
1978
 
-
 
1979
 
-
 
1980
    /**
-
 
1981
     * Handles the editing of user details including type, verification, block status, and user status.
-
 
1982
     *
-
 
1983
     * This action supports both GET and POST requests:
-
 
1984
     * - GET: Retrieves the current user details for a given user UUID.
-
 
1985
     * - POST: Updates the user details based on the provided data.
1977
    }
1986
     *
1978
 
1987
     * @return JsonModel
-
 
1988
     */
1979
 
1989
    public function editUserDetailsAction()
1980
    public function changeTypeAction()
1990
    {
Línea 1981... Línea 1991...
1981
    {
1991
        // Retrieve the current user and request objects
Línea -... Línea 1992...
-
 
1992
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1982
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1993
        $currentUser = $currentUserPlugin->getUser();
1983
        $currentUser = $currentUserPlugin->getUser();
1994
 
1984
 
1995
        $request = $this->getRequest();
1985
        $request = $this->getRequest();
1996
 
1986
 
1997
        // Handle GET request to fetch current user details
Línea 1994... Línea 2005...
1994
            }
2005
            }
Línea 1995... Línea 2006...
1995
 
2006
 
1996
            $userMapper = UserMapper::getInstance($this->adapter);
2007
            $userMapper = UserMapper::getInstance($this->adapter);
Línea 1997... Línea -...
1997
            $user = $userMapper->fetchOneByUuid($uuid);
-
 
1998
 
-
 
1999
 
2008
            $user = $userMapper->fetchOneByUuid($uuid);
2000
 
2009
 
2001
            if ($user) {
2010
            if ($user) {
2002
                return new JsonModel([
2011
                return new JsonModel([
2003
                    'success'   => true,
2012
                    'success'   => true,
-
 
2013
                    'data'      => [
-
 
2014
                        'usertype_id' => $user->usertype_id,
-
 
2015
                        'email_verified' => $user->email_verified,
2004
                    'data'      => [
2016
                        'blocked' => $user->blocked,
2005
                        'usertype_id' => $user->usertype_id,
2017
                        'status' => $user->status,
2006
                    ]
2018
                    ]
2007
                ]);
2019
                ]);
2008
            } else {
2020
            } else {
2009
                return new JsonModel([
2021
                return new JsonModel([
2010
                    'success'   => false,
2022
                    'success'   => false,
2011
                    'data'      => 'ERROR_USER_NOT_FOUND'
2023
                    'data'      => 'ERROR_USER_NOT_FOUND'
2012
                ]);
2024
                ]);
Línea -... Línea 2025...
-
 
2025
            }
2013
            }
2026
        }
2014
        }
-
 
2015
 
2027
 
2016
        if ($request->isPost()) {
2028
        // Handle POST request to update user details
2017
 
2029
        if ($request->isPost()) {
2018
            $uuid = $this->params()->fromRoute('id');
2030
            $uuid = $this->params()->fromRoute('id');
2019
            if (!$uuid) {
2031
            if (!$uuid) {
Línea 2031... Línea 2043...
2031
                    'success'   => false,
2043
                    'success'   => false,
2032
                    'data'      => 'ERROR_USER_NOT_FOUND'
2044
                    'data'      => 'ERROR_USER_NOT_FOUND'
2033
                ]);
2045
                ]);
2034
            }
2046
            }
Línea 2035... Línea -...
2035
 
-
 
-
 
2047
 
2036
 
2048
            // Validate and process form data
2037
            $dataPost = $request->getPost()->toArray();
2049
            $dataPost = $request->getPost()->toArray();
2038
            $form = new ChangeTypeForm();
2050
            $form = new ChangeTypeForm(); // Assuming this form can handle all fields
Línea 2039... Línea 2051...
2039
            $form->setData($dataPost);
2051
            $form->setData($dataPost);
2040
 
2052
 
Línea -... Línea 2053...
-
 
2053
            if ($form->isValid()) {
2041
            if ($form->isValid()) {
2054
                $dataPost = (array) $form->getData();
-
 
2055
 
2042
                $dataPost = (array) $form->getData();
2056
                // Update the user details in the database
2043
 
2057
                $user->usertype_id = $dataPost['usertype_id'];
Línea -... Línea 2058...
-
 
2058
                $user->email_verified = $dataPost['email_verified'];
-
 
2059
                $user->blocked = $dataPost['blocked'];
-
 
2060
                $user->status = $dataPost['status'];
Línea 2044... Línea 2061...
2044
                $result = $userMapper->updateUserTypeId($user, $dataPost['usertype_id']);
2061
 
2045
                if ($result) {
2062
                $result = $userMapper->update($user);
2046
                    $this->logger->info('Cambio del tipo de usuario realizado por realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2063
                if ($result) {
2047
 
-
 
2048
 
2064
                    $this->logger->info('User details updated', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2049
                    return new JsonModel([
2065
 
2050
                        'success'   => true,
2066
                    return new JsonModel([
Línea 2051... Línea 2067...
2051
                        'data'      => 'LABEL_USER_CHANGE_TYPE_HAS_BEEN_UPDATED'
2067
                        'success'   => true,
2052
 
2068
                        'data'      => 'LABEL_USER_DETAILS_UPDATED'
2053
                    ]);
2069
                    ]);
2054
                } else {
-
 
2055
                    $this->logger->err('Cambio del tipo de usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2070
                } else {
2056
 
2071
                    $this->logger->err('Error updating user details', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2057
                    return new JsonModel([
2072
 
-
 
2073
                    return new JsonModel([
2058
                        'success'   => true,
2074
                        'success'   => false,
Línea 2059... Línea 2075...
2059
                        'data'      => 'ERROR_THERE_WAS_AN_ERROR'
2075
                        'data'      => 'ERROR_THERE_WAS_AN_ERROR'
2060
 
2076
                    ]);
2061
                    ]);
2077
                }
Línea 2073... Línea 2089...
2073
                    'data'   => $messages
2089
                    'data'   => $messages
2074
                ]);
2090
                ]);
2075
            }
2091
            }
2076
        }
2092
        }
Línea 2077... Línea -...
2077
 
-
 
2078
 
-
 
-
 
2093
 
2079
 
2094
        // Return error for unsupported request methods
2080
        return new JsonModel([
2095
        return new JsonModel([
2081
            'success' => false,
2096
            'success' => false,
2082
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2097
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2083
        ]);
2098
        ]);