| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- $page_title = _("Submit ID");
- Core::addBreadcrumb("/account", _("Account"));
- Core::addBreadcrumb("/account/submit-id", $page_title);
- $submit = http::value("submit");
- if($submit) {
- $user = Core::$user;
- try {
- Core::validateCSRFToken($submit);
- $form_exception = new FormException;
- $id_document = (object) $_FILES["id_document"];
- $photo = (object) $_FILES["photo"];
- if($id_document->error != UPLOAD_ERR_OK) $form_exception->addError(HTTP::getUploadErrorString($id_document->error));
- if($photo->error != UPLOAD_ERR_OK) $form_exception->addError(HTTP::getUploadErrorString($photo->error));
- $size = @getimagesize($id_document->tmp_name);
- if(!$size) $form_exception->addError(_("The uploaded ID document is not an image."));
- list($width, $height, $type) = $size;
- if($type != IMAGETYPE_JPEG) $form_exception->addError(_("The uploaded ID document is not a JPEG."));
- $size = @getimagesize($photo->tmp_name);
- if(!$size) $form_exception->addError(_("The uploaded photo is not an image."));
- list($width, $height, $type) = $size;
- if($type != IMAGETYPE_JPEG) $form_exception->addError(_("The uploaded photo is not a JPEG."));
- if($form_exception->hasErrors()) throw $form_exception;
- $files = [$id_document, $photo];
- foreach($files as $index => $file) {
- if($index == 0) {
- $name = "ID document";
- $type = UserFile::TYPE_ID;
- }
- if($index == 1) {
- $name = "photo";
- $type = UserFile::TYPE_PHOTO;
- }
- $output_image = Image::normalise($file->tmp_name);
- $user_file = new UserFile;
- $user_file->user_id = $user->id;
- $user_file->type = $type;
- $user_file->dts_uploaded = Util::getDateTime();
- $success = $user_file->commit();
- if(!$success) throw new Exception(sprintf(_("Failed to save the %s. Please try again later."), $name));
- $output_path = $user->getDirectory() . "/" . $user_file->id . ".jpg";
- imagejpeg($output_image, $output_path, 60);
- imagedestroy($output_image);
- }
- $user->level = User::LEVEL_UNVERIFIED;
- $success = $user->commit();
- // TODO: Send out pending verification email
- Core::addAlert("success", _("ID submitted successfully."));
- HTTP::redirect("/account");
- }
- catch(FormException $e) {
- $e->generateAlerts();
- }
- catch(Exception $e) {
- Core::addAlert("danger", $e->getMessage());
- }
- }
- View::includeOnce("header", compact("page_title"));
- View::include("submit_id");
- View::includeOnce("footer");
- ?>
|