User-submit is now working!

This commit is contained in:
tobast 2011-12-25 00:48:23 +01:00
parent 90e1f8e672
commit 03b7e93c4b
6 changed files with 40 additions and 10 deletions

View File

@ -37,17 +37,23 @@ using namespace std;
ConfigRead::ConfigRead(string filepath)
{
ifstream infile(filepath.c_str());
ifstream infile(filepath.c_str(), ios_base::in);
if(!infile)
throw -1;
string filecontent=unxor(infile);
unsigned findpos;
user=filecontent;
user.erase(user.begin()+user.find("\n"), user.end());
findpos=user.find("\n");
if(findpos!=string::npos)
user.erase(user.begin()+findpos, user.end());
pass=filecontent;
pass.erase(pass.begin(), pass.begin()+pass.find("\n"));
pass.erase(pass.begin()+pass.find("\n"), pass.end()); // erases everything on lines after.
findpos=pass.find("\n");
if(findpos!=string::npos)
pass.erase(pass.begin(), pass.begin()+findpos+1);
infile.close();
}

View File

@ -8,7 +8,10 @@ CXXLIBS=-lcurl
TARGET=pastebincl
OBJS=CurlPost.o func.o main.o ParameterRead.o ConfigRead.o
all: $(TARGET)
all: $(TARGET) makeuser
makeuser:
./pastebincl --usergen < userinput &> /dev/null
$(TARGET): $(OBJS)
$(CXX) $(CXXLIBS) $^ $(CXXFLAGS) -o $@

1
data.h
View File

@ -48,6 +48,7 @@
#define DEFAULT_OPTION "paste"
#define PASTEBIN_SUBMIT_URL "http://pastebin.com/api/api_post.php"
#define PASTEBIN_USERCODE_URL "http://pastebin.com/api/api_login.php"
#define DEFAULT_CONFIGPATH ".pastebinclrc"

View File

@ -81,7 +81,7 @@ bool checkParameterRead(ParameterRead& pr, unsigned& flags)
if(pr.isSet("p") || pr.isSet("private"))
flags+=P_PRIVATE;
if(pr.isSet("g") || pr.isSet("guest"))
flags+=P_PRIVATE;
flags+=P_GUEST;
}
catch(const int& e) {
return false;
@ -135,7 +135,7 @@ bool userGen()
std::cout << std::endl;
return ConfigRead::writeConf(user, pass);
return ConfigRead::writeConf(user, pass, getConfigPath());
}
CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr, std::string pasteContent)
@ -191,8 +191,25 @@ CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr, std::stri
std::string getUserCode()
{
//TODO!!!
return "";
ConfigRead cr(getConfigPath());
CurlPost* request=new CurlPost(PASTEBIN_USERCODE_URL);
request->setPostData("api_dev_key", DEVELOPPER_CODE);
request->setPostData("api_user_name", cr.getUser());
request->setPostData("api_user_password", cr.getPass());
std::string result=request->execute();
delete request;
if(result.find("Bad API request") != std::string::npos) // FAIL!
{
std::cerr << result << std::endl;
throw -1;
}
return result;
}
std::string getPasteContent()
@ -230,6 +247,7 @@ inline std::string getConfigPath()
#if defined(UNIX)
outpath=getpwuid(getuid())->pw_dir;
outpath+="/";
#elif defined(WINDOwS)
outpath="C:/Documents and Settings/";

3
func.h
View File

@ -34,8 +34,9 @@
#ifndef DEF_FUNCTION
#define DEF_FUNCTION
#include "ParameterRead.h"
#include <iostream>
#include <string>
#include "ParameterRead.h"
#include "CurlPost.h"
#include "data.h"
#include "ConfigRead.h"

View File

@ -88,6 +88,7 @@ int main(int argc, char** argv)
}
CurlPost::clean();
}
}
catch(...) {