Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. void vk::account::login()
  2. {
  3.     if (this->username != "" && this->password != "")
  4.     {
  5.         string fields = "grant_type=password&client_id=" + to_string(this->client_id) + "&client_secret=" + this->client_secret + "&username=" + this->username + "&password=" + this->password + "&scope=notify,friends,photos,audio,video,docs,notes,pages,status,offers,questions,wall,groups,messages,notifications,stats,ads,offline";
  6.         string nwresp = vk::net::GetNWPOSTResponse("https://oauth.vk.com/token", fields);
  7.         if (nwresp[0] == '{')
  8.         {
  9.             size_t pos = nwresp.find("access_token");
  10.             if (pos != string::npos)
  11.             {
  12.                 json::value val;
  13.                 parse(nwresp, val);
  14.                 this->a_t = val["access_token"].as<string>();
  15.             }
  16.             else throw string("vk::account::login error: Bad login.");
  17.         }
  18.         else throw string("vk::account::login error: No { symbol found; response not JSON object.");
  19.     }
  20.     else throw string("vk::account::login error: No login/password found.");
  21. }
  22.  
  23. void vk::account::login(string username, string password)
  24. {
  25.     if (username != "" && password != "")
  26.     {
  27.         string fields = "grant_type=password&client_id=" + to_string(this->client_id) + "&client_secret=" + this->client_secret + "&username=" + username + "&password=" + password + "&scope=notify,friends,photos,audio,video,docs,notes,pages,status,offers,questions,wall,groups,messages,notifications,stats,ads,offline";
  28.         string nwresp = vk::net::GetNWPOSTResponse("https://oauth.vk.com/token", fields);
  29.         if (nwresp[0] == '{')
  30.         {
  31.             size_t pos = nwresp.find("access_token");
  32.             if (pos != string::npos)
  33.             {
  34.                 json::value val;
  35.                 parse(nwresp, val);
  36.                 this->a_t = val["access_token"].as<string>();
  37.             }
  38.             else throw string("vk::account::login error: Bad login.");
  39.         }
  40.         else throw string("vk::account::login error: No { symbol found; response not JSON object.");
  41.     }
  42.     else throw string("vk::account::login error: No login/password found.");
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement