updated to the new Pikotools api (new Space struct)

This commit is contained in:
2021-04-09 17:50:58 +02:00
parent 00b980e74b
commit 35e10ed469
52 changed files with 795 additions and 736 deletions

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2013-2018, Tomasz Sowa
* Copyright (c) 2013-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,7 +55,7 @@ Account::Account()
bool Account::ActivateAccount(User * puser, long code, bool use_ses_log)
{
std::wstring * user_code_str = puser->aenv.GetFirstValue(L"activation_code");
std::wstring * user_code_str = puser->aenv.get_wstr(L"activation_code");
if( user_code_str )
{
@@ -63,7 +63,7 @@ bool Account::ActivateAccount(User * puser, long code, bool use_ses_log)
{
if( db->ChangeUserStatus(puser->id, WINIX_ACCOUNT_READY) == WINIX_ERR_OK )
{
puser->aenv.Remove(L"activation_code");
puser->aenv.remove(L"activation_code");
db->ChangeUserAdminEnv(puser->id, puser->aenv);
puser->status = WINIX_ACCOUNT_READY;

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -229,7 +229,7 @@ bool AddUser::AddNewUser(const std::wstring & login,
if( user.status == WINIX_ACCOUNT_NOT_ACTIVATED )
{
code = std::rand();
user.aenv.Add(L"activation_code", code);
user.aenv.add(L"activation_code", code);
}
if( AddNewUser(user, pass) )

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2018, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -74,10 +74,10 @@ return true;
bool Env::Parse(const std::wstring & env_str)
{
space.Clear();
space.clear();
conf_parser.SetSpace(space);
return (conf_parser.ParseString(env_str) == PT::SpaceParser::ok);
return (conf_parser.ParseSpace(env_str) == PT::SpaceParser::ok);
}
@@ -102,10 +102,10 @@ bool Env::EditAdminEnv(long user_id, const std::wstring & env_str, bool use_ses_
}
else
{
log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend;
log << log2 << "Env: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend;
}
return false;
@@ -133,10 +133,10 @@ bool Env::EditEnv(long user_id, const std::wstring & env_str, bool use_ses_log)
}
else
{
log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend;
log << log2 << "Env: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend;
}
return false;

View File

@@ -62,10 +62,10 @@ bool Meta::HasAccess()
bool Meta::Parse(const std::wstring & meta_str)
{
space.Clear();
space.clear();
conf_parser.SetSpace(space);
return (conf_parser.ParseString(meta_str) == PT::SpaceParser::ok);
return (conf_parser.ParseSpace(meta_str) == PT::SpaceParser::ok);
}
@@ -91,10 +91,10 @@ bool Meta::EditAdminMeta(Item & item, const std::wstring & meta_str, bool use_se
}
else
{
log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend;
log << log2 << "Meta: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend;
}
return false;
@@ -122,10 +122,10 @@ bool Meta::EditMeta(Item & item, const std::wstring & meta_str, bool use_ses_log
}
else
{
log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend;
log << log2 << "Meta: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend;
}
return false;

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2011-2018, Tomasz Sowa
* Copyright (c) 2011-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -189,7 +189,7 @@ return result;
bool Passwd::ResetPassword(User * puser, long code, bool use_ses_log, bool only_check_access)
{
std::wstring * user_code_str = puser->aenv.GetFirstValue(L"password_change_code");
std::wstring * user_code_str = puser->aenv.get_wstr(L"password_change_code");
if( user_code_str )
{
@@ -229,7 +229,7 @@ bool Passwd::ResetPassword(const std::wstring & login, long code, bool use_ses_l
{
long t = static_cast<long>(cur->request->start_time);
if( puser->aenv.Long(L"password_change_time") + config->reset_password_code_expiration_time > t )
if( puser->aenv.to_long(L"password_change_time") + config->reset_password_code_expiration_time > t )
{
result = ResetPassword(puser, code, use_ses_log, only_check_access);
}

View File

@@ -59,8 +59,6 @@ Upload::Upload()
void Upload::Init()
{
json_serializer.TreatAsTable(L"files");
json_serializer.TreatAsNumeric(L"size");
}
@@ -146,9 +144,10 @@ void Upload::CreateThumb(Item & item)
void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
{
// we should add the file beforehand to get the proper item.id
cur->request->status = system->AddFile(item, 0, false);
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
bool status = system->AddFile(item, 0, false);
if( cur->request->status == WINIX_ERR_OK )
if( status )
{
if( system->CreateNewFile(item) )
{
@@ -160,6 +159,7 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
//cur->request->status = db->EditFileById(item, item.id);
if( item.update(item_model_data) )
{
cur->request->status = WINIX_ERR_OK;
plugin->Call(WINIX_FILE_ADDED, &item);
if( item.item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE )
@@ -174,10 +174,6 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
if( is_jquery_upload )
cur->request->item_tab.push_back(item);
}
else
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
}
else
{
@@ -246,6 +242,8 @@ void Upload::UploadMulti()
void Upload::UploadSingle()
{
cur->request->item.Clear(); // clearing and setting date
const std::wstring & new_subject = cur->request->PostVar(L"subject");
const std::wstring & new_url = cur->request->PostVar(L"url");
bool has_subject = !new_subject.empty();
@@ -308,29 +306,33 @@ void Upload::MakePost()
void Upload::CreateAnswer()
{
Request & req = *cur->request;
PT::Space & files = req.info.AddSpace(L"files"); // 'files' will be serialized to an array
PT::Space & files = req.info.add_empty_space(L"files");
for(size_t i=0 ; i<req.item_tab.size() ; ++i)
{
PT::Space & file = files.AddSpace(L"");
PT::Space & file = files.add_empty_space();
file.Add(L"name", req.item_tab[i].url);
file.Add(L"size", req.item_tab[i].item_content.file_size);
file.add(L"name", req.item_tab[i].url);
file.add(L"size", req.item_tab[i].item_content.file_size);
std::wstring & link = file.Add(L"url", L"");
std::wstring link;
system->CreateItemLink(req.item_tab[i], link);
file.add(L"url", link);
std::wstring & del_url = file.Add(L"deleteUrl", link);
del_url += L"/rm/jquery_upload";
std::wstring delete_url = link;
delete_url += L"/rm/jquery_upload";
file.add(L"deleteUrl", delete_url);
file.Add(L"deleteType", L"POST");
file.add(L"deleteType", L"POST");
if( req.item_tab[i].item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE )
{
std::wstring & thumb = file.Add(L"thumbnailUrl", link);
std::wstring thumb = link;
if( req.item_tab[i].item_content.file_has_thumb )
thumb += L"/-/thumb";
file.add(L"thumbnailUrl", thumb);
}
/*
@@ -341,10 +343,6 @@ void Upload::CreateAnswer()
cur->request->return_json = true;
cur->request->return_info_only = true;
cur->request->info_serializer = &json_serializer;
//cur->request->out_headers.Add(L"Content-Type", L"text/html");
}

View File

@@ -36,7 +36,7 @@
#define headerfile_winix_functions_upload
#include "functionbase.h"
#include "space/spacetojson.h"
namespace Winix
{
@@ -62,11 +62,6 @@ private:
//DbItemQuery query;
bool is_jquery_upload;
// this object is used in App at the end of a request
// for serializing Request::info to JSON
// this will make a problem if in the future we'll use multithread requests
PT::SpaceToJSON json_serializer;
void Init();
bool HasAccess(const Item & item);