Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 385 Rev 605
Línea 910... Línea 910...
910
    public function resetPasswordAction()
910
    public function resetPasswordAction()
911
    {
911
    {
912
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
912
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
913
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
913
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
Línea 914... Línea -...
914
 
-
 
915
 
914
 
Línea 916... Línea 915...
916
        $code =  Functions::sanitizeFilterString($this->params()->fromRoute('code', ''));
915
        $code =  Functions::sanitizeFilterString($this->params()->fromRoute('code', ''));
917
 
916
 
-
 
917
        $userMapper = UserMapper::getInstance($this->adapter);
918
        $userMapper = UserMapper::getInstance($this->adapter);
918
        $user = $userMapper->fetchOneByPasswordResetKeyAndNetworkId($code, $currentNetwork->id);
919
        $user = $userMapper->fetchOneByPasswordResetKeyAndNetworkId($code, $currentNetwork->id);
919
 
Línea 920... Línea 920...
920
        if (!$user) {
920
        if (!$user) {
921
            $this->logger->err('Restablecer contraseña - Error código no existe', ['ip' => Functions::getUserIP()]);
921
            $this->logger->err('Restablecer contraseña - Error código no existe', ['ip' => Functions::getUserIP()]);
922
 
922
 
923
            return new JsonModel([
923
            return new JsonModel([
Línea 924... Línea 924...
924
                'success'   => false,
924
                'success'   => false,
Línea 925... Línea -...
925
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_IS_INVALID'
-
 
926
            ]);
-
 
927
 
925
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_IS_INVALID'
928
        }
926
            ]);
-
 
927
 
929
 
928
        }
930
 
929
 
931
 
-
 
932
        $password_generated_on = strtotime($user->password_generated_on);
930
        $password_generated_on = strtotime($user->password_generated_on);
933
        $expiry_time = $password_generated_on + $this->config['leaderslinked.security.reset_password_expired'];
931
        $expiry_time = $password_generated_on + $this->config['leaderslinked.security.reset_password_expired'];
934
        if (time() > $expiry_time) {
932
 
935
            $this->logger->err('Restablecer contraseña - Error código expirado', ['ip' => Functions::getUserIP()]);
933
        if (time() > $expiry_time) {
936
 
934
            $this->logger->err('Restablecer contraseña - Error código expirado', ['ip' => Functions::getUserIP()]);
Línea 937... Línea 935...
937
            return new JsonModel([
935
            return new JsonModel([
-
 
936
                'success'   => false,
938
                'success'   => false,
937
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_HAS_EXPIRED'
939
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_HAS_EXPIRED'
938
            ]);
-
 
939
        }
940
            ]);
940
 
941
        }
941
        $request = $this->getRequest();
942
 
942
 
943
        $request = $this->getRequest();
943
        if ($request->isPost()) {
944
        if ($request->isPost()) {
944
            $dataPost = $request->getPost()->toArray();
945
            $dataPost = $request->getPost()->toArray();
-
 
946
            if (empty($_SESSION['aes'])) {
-
 
947
                return new JsonModel([
945
 
Línea 948... Línea 946...
948
                    'success'   => false,
946
            if (empty($_SESSION['aes'])) {
949
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
947
                return new JsonModel([
950
                ]);
948
                    'success'   => false,
-
 
949
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
951
                
950
                ]);   
952
                
951
            }
953
            }
952
 
Línea 954... Línea -...
954
 
-
 
955
            if (!empty($dataPost['password'])) {
-
 
956
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
953
            if (!empty($dataPost['password'])) {
957
            }
954
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
Línea 958... Línea 955...
958
            if (!empty($dataPost['confirmation'])) {
955
            }
959
                $dataPost['confirmation'] = CryptoJsAes::decrypt($dataPost['confirmation'], $_SESSION['aes']);
956
 
960
            }
957
            if (!empty($dataPost['confirmation'])) {
Línea 961... Línea -...
961
 
-
 
962
 
958
                $dataPost['confirmation'] = CryptoJsAes::decrypt($dataPost['confirmation'], $_SESSION['aes']);
963
 
959
            }
Línea 964... Línea 960...
964
            $form = new ResetPasswordForm($this->config);
960
 
965
            $form->setData($dataPost);
961
            $form = new ResetPasswordForm($this->config);
Línea 1074... Línea 1070...
1074
    public function forgotPasswordAction()
1070
    public function forgotPasswordAction()
1075
    {
1071
    {
1076
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1072
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1077
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1073
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
Línea -... Línea 1074...
-
 
1074
 
-
 
1075
        $request = $this->getRequest();
-
 
1076
 
-
 
1077
        if ($request->isGet()) {
-
 
1078
            if (empty($_SESSION['aes'])) {
-
 
1079
                $_SESSION['aes'] = Functions::generatePassword(16);
Línea -... Línea 1080...
-
 
1080
            }
-
 
1081
 
-
 
1082
            $site_key = $this->config['leaderslinked.runmode.sandbox'] 
-
 
1083
            ? $this->config['leaderslinked.google_captcha.sandbox_site_key'] 
-
 
1084
            : $this->config['leaderslinked.google_captcha.production_site_key'];
-
 
1085
 
-
 
1086
            return new JsonModel([
-
 
1087
                'site_key'  => $site_key,
-
 
1088
                'aes'       => $_SESSION['aes'],
-
 
1089
                'defaultNetwork' => $currentNetwork->default,
Línea 1078... Línea -...
1078
 
-
 
1079
 
1090
            ]);
1080
 
1091
        }
-
 
1092
 
1081
        $request = $this->getRequest();
1093
        if ($request->isPost()) {
1082
        if ($request->isPost()) {
1094
            $dataPost = $request->getPost()->toArray();
1083
            $dataPost = $request->getPost()->toArray();
1095
 
1084
            if (empty($_SESSION['aes'])) {
1096
            if (empty($_SESSION['aes'])) {
1085
                return new JsonModel([
1097
                return new JsonModel([
Línea 1093... Línea 1105...
1093
            }
1105
            }
Línea 1094... Línea 1106...
1094
 
1106
 
1095
            $form = new ForgotPasswordForm($this->config);
1107
            $form = new ForgotPasswordForm($this->config);
Línea 1096... Línea 1108...
1096
            $form->setData($dataPost);
1108
            $form->setData($dataPost);
1097
 
-
 
1098
            if ($form->isValid()) {
-
 
1099
                $dataPost = (array) $form->getData();
-
 
1100
                $email      = $dataPost['email'];
-
 
1101
 
-
 
1102
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
1103
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
-
 
1104
                if (!$user) {
-
 
1105
                    $this->logger->err('Olvidó contraseña ' . $email . '- Email no existe ', ['ip' => Functions::getUserIP()]);
-
 
1106
 
-
 
1107
                    return new JsonModel([
-
 
1108
                        'success' => false,
-
 
1109
                        'data' =>  'ERROR_EMAIL_IS_NOT_REGISTERED'
-
 
1110
                    ]);
-
 
1111
                } else {
-
 
1112
                    if ($user->status == User::STATUS_INACTIVE) {
-
 
1113
                        return new JsonModel([
-
 
1114
                            'success' => false,
-
 
1115
                            'data' =>  'ERROR_USER_IS_INACTIVE'
-
 
1116
                        ]);
-
 
1117
                    } else if ($user->email_verified == User::EMAIL_VERIFIED_NO) {
-
 
1118
                        $this->logger->err('Olvidó contraseña - Email no verificado ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
1119
 
-
 
1120
                        return new JsonModel([
-
 
1121
                            'success' => false,
-
 
1122
                            'data' => 'ERROR_EMAIL_HAS_NOT_BEEN_VERIFIED'
-
 
1123
                        ]);
-
 
1124
                    } else {
-
 
1125
                        $password_reset_key = md5($user->email . time());
-
 
1126
                        $userMapper->updatePasswordResetKey((int) $user->id, $password_reset_key);
-
 
1127
 
-
 
1128
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
-
 
1129
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RESET_PASSWORD, $currentNetwork->id);
-
 
1130
                        if ($emailTemplate) {
-
 
1131
                            $arrayCont = [
-
 
1132
                                'firstname'             => $user->first_name,
-
 
1133
                                'lastname'              => $user->last_name,
-
 
1134
                                'other_user_firstname'  => '',
-
 
1135
                                'other_user_lastname'   => '',
-
 
1136
                                'company_name'          => '',
-
 
1137
                                'group_name'            => '',
-
 
1138
                                'content'               => '',
-
 
1139
                                'code'                  => '',
-
 
1140
                                'link'                  => $this->url()->fromRoute('reset-password', ['code' => $password_reset_key], ['force_canonical' => true])
-
 
1141
                            ];
-
 
1142
 
-
 
1143
                            $email = new QueueEmail($this->adapter);
-
 
1144
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
-
 
1145
                        }
-
 
1146
 
-
 
1147
                        $this->logger->info('Olvidó contraseña - Se envio link de recuperación ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
1148
 
-
 
1149
                        return new JsonModel([
-
 
1150
                            'success' => true,
-
 
1151
                            'data' => 'LABEL_RECOVERY_LINK_WAS_SENT_TO_YOUR_EMAIL'
-
 
1152
                        ]);
-
 
1153
                    }
-
 
1154
                }
-
 
1155
            } else {
-
 
1156
 
1109
 
Línea 1157... Línea -...
1157
 
-
 
1158
                $form_messages =  $form->getMessages('captcha');
-
 
1159
 
1110
            if (!$form->isValid()){
1160
 
1111
                $form_messages =  $form->getMessages('captcha');
1161
 
1112
 
1162
                if (!empty($form_messages)) {
1113
                if (!empty($form_messages)) {
1163
                    return new JsonModel([
1114
                    return new JsonModel([
Línea 1175... Línea 1126...
1175
                return new JsonModel([
1126
                return new JsonModel([
1176
                    'success'   => false,
1127
                    'success'   => false,
1177
                    'data'      => $messages
1128
                    'data'      => $messages
1178
                ]);
1129
                ]);
1179
            }
1130
            }
1180
        } else  if ($request->isGet()) {
-
 
Línea -... Línea 1131...
-
 
1131
 
-
 
1132
            $dataPost = (array) $form->getData();
-
 
1133
            $email      = $dataPost['email'];
-
 
1134
 
-
 
1135
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
1136
            $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
1181
 
1137
 
-
 
1138
            if (!$user) {
-
 
1139
                $this->logger->err('Olvidó contraseña ' . $email . '- Email no existe ', ['ip' => Functions::getUserIP()]);
-
 
1140
                return new JsonModel([
1182
            if (empty($_SESSION['aes'])) {
1141
                    'success' => false,
-
 
1142
                    'data' =>  'ERROR_EMAIL_IS_NOT_REGISTERED'
1183
                $_SESSION['aes'] = Functions::generatePassword(16);
1143
                ]);
Línea -... Línea 1144...
-
 
1144
            }
-
 
1145
 
-
 
1146
            
-
 
1147
            if ($user->status == User::STATUS_INACTIVE) {
-
 
1148
                return new JsonModel([
-
 
1149
                    'success' => false,
-
 
1150
                    'data' =>  'ERROR_USER_IS_INACTIVE'
-
 
1151
                ]);
1184
            }
1152
            } 
-
 
1153
            
-
 
1154
            if ($user->email_verified == User::EMAIL_VERIFIED_NO) {
-
 
1155
                $this->logger->err('Olvidó contraseña - Email no verificado ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
1156
                return new JsonModel([
-
 
1157
                    'success' => false,
-
 
1158
                    'data' => 'ERROR_EMAIL_HAS_NOT_BEEN_VERIFIED'
-
 
1159
                ]);
-
 
1160
            } 
1185
 
1161
            
-
 
1162
            $password_reset_key = md5($user->email . time());
-
 
1163
            $userMapper->updatePasswordResetKey((int) $user->id, $password_reset_key);
-
 
1164
 
-
 
1165
            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
-
 
1166
            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RESET_PASSWORD, $currentNetwork->id);
-
 
1167
 
-
 
1168
            if (!$emailTemplate) {
-
 
1169
                $this->logger->err('Olvidó contraseña - Email template no existe ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
1170
                return new JsonModel([
1186
            if ($this->config['leaderslinked.runmode.sandbox']) {
1171
                    'success' => false,
-
 
1172
                    'data' => 'ERROR_EMAIL_TEMPLATE_NOT_FOUND'
-
 
1173
                ]);
-
 
1174
            }
-
 
1175
 
-
 
1176
            $arrayCont = [
-
 
1177
                'firstname'             => $user->first_name,
-
 
1178
                'lastname'              => $user->last_name,
-
 
1179
                'other_user_firstname'  => '',
-
 
1180
                'other_user_lastname'   => '',
-
 
1181
                'company_name'          => '',
-
 
1182
                'group_name'            => '',
1187
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
1183
                'content'               => '',
-
 
1184
                'code'                  => '',
-
 
1185
                'link'                  => $this->url()->fromRoute('reset-password', ['code' => $password_reset_key], ['force_canonical' => true])
-
 
1186
            ];
-
 
1187
 
-
 
1188
            $email = new QueueEmail($this->adapter);
-
 
1189
            
-
 
1190
            if (!$email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name))) {
-
 
1191
                $this->logger->err('Olvidó contraseña - Error al enviar email ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
1192
                return new JsonModel([
-
 
1193
                    'success' => false,
1188
            } else {
1194
                    'data' => 'ERROR_EMAIL_NOT_SENT'
Línea -... Línea 1195...
-
 
1195
                ]);
-
 
1196
            }
1189
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
1197
 
1190
            }
1198
            $this->logger->info('Olvidó contraseña - Se envio link de recuperación ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1191
 
1199
 
1192
            return new JsonModel([
-
 
1193
                'site_key'  => $site_key,
1200
            return new JsonModel([
1194
                'aes'       => $_SESSION['aes'],
1201
                'success' => true,
Línea 1195... Línea 1202...
1195
                'defaultNetwork' => $currentNetwork->default,
1202
                'data' => 'LABEL_RECOVERY_LINK_WAS_SENT_TO_YOUR_EMAIL'
1196
            ]);
1203
            ]);