Slack: get_oauth2_url now stores uin/password in the state data and use them when registering the user - this makes the registration easier from web interface side
This commit is contained in:
parent
384d4bfcd0
commit
2e508b97c3
3 changed files with 33 additions and 23 deletions
|
@ -427,9 +427,9 @@ void SlackSession::handleMessageReceived(const std::string &channel, const std::
|
|||
msg += "```.spectrum2 register <3rdPartyNetworkAccount> <3rdPartyPassword> <#SlackChannel>``` Registers 3rd-party account for transportation.";
|
||||
m_rtm->sendMessage(m_ownerChannel, msg);
|
||||
}
|
||||
else {
|
||||
m_rtm->sendMessage(m_ownerChannel, "Unknown command. Use `.spectrum2 help` for help.");
|
||||
}
|
||||
// else {
|
||||
// m_rtm->sendMessage(m_ownerChannel, "Unknown command. Use `.spectrum2 help` for help.");
|
||||
// }
|
||||
}
|
||||
|
||||
void SlackSession::handleDisconnected() {
|
||||
|
|
|
@ -144,14 +144,24 @@ std::string SlackUserRegistration::handleOAuth2Code(const std::string &code, con
|
|||
return "The token you have provided is invalid";
|
||||
}
|
||||
|
||||
std::string slackChannel;
|
||||
std::string uin;
|
||||
std::string password;
|
||||
if (data.size() == 4) {
|
||||
slackChannel = data[1];
|
||||
uin = data[2];
|
||||
password = data[3];
|
||||
}
|
||||
|
||||
UserInfo user;
|
||||
user.uin = "";
|
||||
user.password = "";
|
||||
user.id = 0;
|
||||
m_storageBackend->getUser(domain, user);
|
||||
|
||||
value = user.jid;
|
||||
user.jid = domain;
|
||||
user.uin = uin;
|
||||
user.password = password;
|
||||
user.language = "en";
|
||||
user.encoding = "";
|
||||
user.vip = 0;
|
||||
|
@ -160,8 +170,8 @@ std::string SlackUserRegistration::handleOAuth2Code(const std::string &code, con
|
|||
|
||||
m_storageBackend->getUser(user.jid, user);
|
||||
|
||||
if (!value.empty()) {
|
||||
m_storageBackend->getUserSetting(user.id, "slack_channel", type, value);
|
||||
if (!slackChannel.empty()) {
|
||||
m_storageBackend->getUserSetting(user.id, "slack_channel", type, slackChannel);
|
||||
}
|
||||
|
||||
value = token;
|
||||
|
|
|
@ -197,27 +197,27 @@ void APIServer::serve_instances_register(Server *server, Server::session *sessio
|
|||
send_ack(conn, true, "Insufficient data.");
|
||||
}
|
||||
else {
|
||||
std::string response = server->send_command(instance, "register " + jid + " " + uin + " " + password);
|
||||
// Check if the frontend wants to use OAuth2 (Slack for example).
|
||||
std::string response = server->send_command(instance, "get_oauth2_url " + jid + " " + uin + " " + password);
|
||||
if (!response.empty()) {
|
||||
std::string value = jid;
|
||||
int type = (int) TYPE_STRING;
|
||||
m_storage->updateUserSetting(info.id, instance, value);
|
||||
Document json;
|
||||
json.SetObject();
|
||||
json.AddMember("error", false, json.GetAllocator());
|
||||
json.AddMember("oauth2_url", response.c_str(), json.GetAllocator());
|
||||
send_json(conn, json);
|
||||
}
|
||||
else {
|
||||
send_ack(conn, true, response);
|
||||
return;
|
||||
response = server->send_command(instance, "register " + jid + " " + uin + " " + password);
|
||||
if (!response.empty()) {
|
||||
std::string value = jid;
|
||||
int type = (int) TYPE_STRING;
|
||||
m_storage->updateUserSetting(info.id, instance, value);
|
||||
}
|
||||
else {
|
||||
send_ack(conn, true, response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Document json;
|
||||
json.SetObject();
|
||||
json.AddMember("error", false, json.GetAllocator());
|
||||
|
||||
response = server->send_command(instance, "get_oauth2_url " + jid);
|
||||
if (!response.empty()) {
|
||||
json.AddMember("oauth2_url", response.c_str(), json.GetAllocator());
|
||||
}
|
||||
|
||||
send_json(conn, json);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue