public function recoveryAction() { $model = new PageModel(); $msg = false; if (isPost()) { $post = allPost(); if (isset($post['email'])) { if ($model->userExist($post['email'])) { $hash = randomHash(); if ($model->createRecoveryCode($post['email'], $hash)) { $message = "Dear,<br/>You requested to recovery Your password at <a href=\"" . SITE_URL . "\">" . SITE_NAME . "</a>.<br/>" . "Please visit page by following link:<br/>" . "<a href=\"" . SITE_URL . "/page/passwordReset/" . $hash . "\">" . SITE_URL . "/page/passwordReset/" . $hash . "</a><br/>" . "Link will be accessible for 24 hours." . "<br/><br/>" . "Thanks for using our service,<br/>" . "Best regards,<br/>Administration."; $headers = "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=utf-8\r\n"; if (mail($post['email'], "Password Recovery", $message, $headers)) { $msg = "You will receive email at the <" . $post['email'] . "> with link to page, where You could change your password. Thanks for using our service"; } else { $msg = "Sorry, but we can't send email now. Please try later."; } } else { $msg = "Sorry, but error occured when system creates recovery email. Maybe You already sent request to recover password. Please check your email or try again later."; } } else { $msg = "Sorry, but user with provided email not registered in this system. Please try again."; } } } $model->deleteOldRecovery(); $this->view->msg = $msg; $this->view->title = Lang::translate("RECOVERY_FORGOT_PASSWORD"); }
/** * Generate a CSRF token for this request, but only generate it once in case there are * multiple forms on the one page. * * @return string */ function csrfToken() { static $token; if (!$token) { $_SESSION['CSRF_TOKEN'] = $token = randomHash(); } return $token; }
public function regcodeAction() { if (empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { error404(); } $model = new ProfileModel(); $data['uid'] = Request::getParam('user')->id; $data['code'] = md5(Request::getParam('user')->nickname . '_' . randomHash()); $data['time'] = time(); $idCode = $model->insert('reg_code', $data); if ($idCode) { $response['error'] = 0; $response['target_h']['#reg_code'] = SITE_URL . 'reg_' . $data['code']; } else { $response['error'] = 'Error'; } echo json_encode($response); exit; }
/** * Function LoadImage * @param array $file ex. $_FILES['name'] * @param string $path ex. 'app/public/' * @param null $name ex. 'name' * @param string $format ex. 'jpg' * @param array $allowedFormats ex. array('jpg' => true, 'gif' => false) * @param int $size - max file size * @param int $resize ex. 0 - no resize(сжать), 1 - обрезать не изменяя размеров, 2 - обрезать симетрически уменьшив * @param int $minHeight * @param int $minWidth * @param int $maxHeight * @param int $maxWidth * @return mixed */ public static function LoadImage($file, $path, $name = null, $format = 'jpg', $allowedFormats = array(), $size = 0, $resize = 0, $minHeight = 0, $minWidth = 0, $maxHeight = 0, $maxWidth = 0) { $data = array('error' => 0); $data['format'] = mb_strtolower(mb_substr($file['name'], mb_strrpos($file['name'], '.') + 1)); $data['new_format'] = $format; $data['path'] = _SYSDIR_ . trim($path, '/') . '/'; $data['tmp_name'] = $file['tmp_name']; $data['size'] = $file['size']; $data['type'] = $file['type']; $data['name'] = $file['name']; // Recursive mkdir remkdir($path); if (!$name) { $data['new_name'] = randomHash(); } else { $data['new_name'] = $name; } if (!is_array($allowedFormats) or empty($allowedFormats)) { $allowedFormats = self::$allowedImageFormats; } if ($allowedFormats[$data['format']] !== true) { $data['error'] = 1; $data['error_msg'] = 'Incorrect file format'; return $data; } if (intval($size) > 0 && $data['size'] > $size) { $data['error'] = 2; $data['error_msg'] = 'File size is too large'; return $data; } if ($data['format'] == 'jpg') { $imageCreateFrom = 'ImageCreateFromJpeg'; } else { $imageCreateFrom = 'ImageCreateFrom' . $data['format']; } if ($data['new_format'] == 'jpg') { $imagePrint = 'imageJpeg'; } else { $imagePrint = 'image' . $data['new_format']; } // Create resource image $img = $imageCreateFrom($file['tmp_name']); $data['height'] = imagesy($img); $data['width'] = imagesx($img); // Min resizing if ($minHeight == 0 && $minWidth == 0) { $data['new_height'] = $data['height']; $data['new_width'] = $data['width']; } else { if ($minHeight != 0 && $minWidth == 0) { $data['new_height'] = $minHeight; $hw = round($data['width'] / $data['height'], 6); $data['new_width'] = round($hw * $minHeight, 0); } else { if ($minHeight == 0 && $minWidth != 0) { $data['new_width'] = $minWidth; $hw = round($data['height'] / $data['width'], 6); $data['new_height'] = round($hw * $minWidth, 0); } else { if ($minHeight != 0 && $minWidth != 0) { $data['new_height'] = $minHeight; $data['new_width'] = $minWidth; } } } } // Max resizing if ($maxHeight != 0 && $maxWidth == 0 && $maxHeight < $data['height']) { $data['new_height'] = $maxHeight; $hw = round($data['width'] / $data['height'], 6); $data['new_width'] = round($hw * $maxHeight, 0); } else { if ($maxHeight == 0 && $maxWidth != 0 && $maxWidth < $data['width']) { $data['new_width'] = $maxWidth; $hw = round($data['height'] / $data['width'], 6); $data['new_height'] = round($hw * $maxWidth, 0); } else { if ($maxHeight != 0 && $maxWidth != 0 && ($maxHeight < $data['height'] or $maxWidth < $data['width'])) { if ($data['height'] > $data['width']) { $data['new_height'] = $maxHeight; $hw = round($data['width'] / $data['height'], 6); $data['new_width'] = round($hw * $maxHeight, 0); } elseif ($data['height'] < $data['width']) { $data['new_width'] = $maxWidth; $hw = round($data['height'] / $data['width'], 6); $data['new_height'] = round($hw * $maxWidth, 0); } } } } if ($resize == 1) { $data['height'] = $data['new_height']; $data['width'] = $data['new_width']; } if ($resize == 2) { if ($data['new_width'] > $data['new_height']) { $hw = round($data['new_height'] / $data['new_width'], 6); $data['height'] = round($hw * $data['width'], 0); } elseif ($data['new_width'] < $data['new_height']) { $hw = round($data['new_width'] / $data['new_height'], 6); $data['width'] = round($hw * $data['height'], 0); } else { if ($data['width'] > $data['height']) { $data['width'] = $data['height']; } else { $data['height'] = $data['width']; } } } $screen = imageCreateTrueColor($data['new_width'], $data['new_height']); if ($data['format'] == 'png') { imagealphablending($screen, false); // Disable pairing colors imagesavealpha($screen, true); // Including the preservation of the alpha channel } imageCopyResampled($screen, $img, 0, 0, 0, 0, $data['new_width'], $data['new_height'], $data['width'], $data['height']); $imagePrint($screen, $data['path'] . $data['new_name'] . '.' . $data['new_format']); imageDestroy($img); return $data; }