public function confirmationEmailAction() { $token = $this->getParameters('token'); $max_days = $this->max_days_token; $status = 2; if (preg_match('/^[a-zA-Z0-9]+$/', $token)) { $ModelUser = $this->getDB()->model($this->model); $User = $ModelUser->fetch(array('token_email' => $token)); if ($User) { $diff = \Kodazzi\Tools\Date::diff($User->token_email_created, $this->getTimestamp(), 'd'); // Si es mayor o igual a uno o es menor que cero dias dice que ha expirado. if ($diff >= $max_days || $diff < 0) { // Error 3: Token ha expirado o no es valido $status = 3; } else { if ((int) $User->email_confirm === 1) { // Error 4: El email ya fue confirmado $status = 4; } else { $quantity = $ModelUser->update(array('email_confirm' => 1, 'token_email' => null, 'token_email_created' => null), array('id' => $User->id, 'token_email' => $User->token_email)); if ($quantity) { $status = 1; $this->sendEmailVerified($User); } } } } else { // Error 2: Token no valido. $status = 2; } } return $this->render('Dinnovos\\Users:Registration:confirmation_email', array('status' => $status, 'max_days' => $max_days)); }
public function modifyPasswordAction() { $token = $this->getRequest()->get('token'); $max_hours = 1; $status = 1; $post = $this->getPOST(); $errors = array(); $User = null; if (preg_match('/^[a-zA-Z0-9]+$/', $token)) { $ModelUser = $this->getDB()->model($this->model); $User = $ModelUser->fetch(array('token_forgotten' => $token, 'status' => 1)); if ($User) { $diff = \Kodazzi\Tools\Date::diff($User->token_forgotten_created, $this->getTimestamp(), 'h'); // SI es mayor o igual a uno o es mejor que cero dias dice que ha expirado. if ($diff >= $max_hours || $diff < 0) { // Error 2: Token ha expirado. $status = 2; } } else { // Error 2: Token no valido. $status = 5; } } if ($status === 1 && count($post) && array_key_exists('modify', $post) && array_key_exists('password', $post['modify']) && array_key_exists('confirmation_password', $post['modify'])) { $password = $post['modify']['password']; $confirmation_password = $post['modify']['confirmation_password']; if ($password != '' && $confirmation_password != '') { if ($password != $confirmation_password) { $errors['password'] = '******'; $errors['confirmation_password'] = '******'; } else { if (!\Kodazzi\Tools\RegularExpression::isValidPassword($password)) { $errors['password'] = '******'; } } } else { if ($password == '') { $errors['password'] = '******'; } if ($confirmation_password == '') { $errors['confirmation_password'] = '******'; } } if (count($errors) == 0) { $result = $ModelUser->update(array('password' => $this->getSession()->encript($password), 'token_forgotten' => null, 'token_forgotten_created' => null), array('id' => $User->id, 'status' => 1)); if ((int) $result == 1) { // Status 5: Clave modificada correctamente. $status = 4; } } } return $this->render('Dinnovos\\Amazonas:Admin/Session:modify_password', array('status' => $status, 'max_hours' => $max_hours, 'errors' => $errors)); }
protected function isValidEmail($User) { if ($User) { if ((int) $User->email_confirm === 1) { return true; } if ((int) $User->email_confirm === 0) { if ($this->start_after_registration) { $diff = \Kodazzi\Tools\Date::diff($User->created, $this->getTimestamp(), 'd'); if ($diff > 0 && $diff < $this->max_days_unconfirme_email) { return true; } } } } return false; }