예제 #1
0
AuthResult ExternalAuth::auth(const AuthRequest &data)
{
  if (!Ch::server()->feed(FEED_NAME_SERVER)->data().value(SERVER_FEED_AUTH_KEY).toStringList().contains(AUTH_METHOD_OAUTH))
    return AuthResult(Notice::NotImplemented, data.id);

  if (SimpleID::typeOf(data.cookie) != SimpleID::CookieId)
    return AuthResult(Notice::BadRequest, data.id);

  new ExternalAuthTask(data, m_core->packetsEvent()->address.toString(), m_core);
  return AuthResult(AuthResult::Pending);
}
예제 #2
0
/*!
 * Отклонение авторизации пользователя.
 */
void ExternalAuthTask::setError(int errorCode)
{
  m_reply->deleteLater();
  Core::i()->reject(m_data, AuthResult(errorCode, m_data.id), m_socket);
  m_timer->stop();
  deleteLater();
}
예제 #3
0
/*!
 * Авторизация пользователя, если пользователь не существует, будет создан новый.
 */
AuthResult ExternalAuthTask::auth(const QVariantMap &data)
{
  QByteArray id = SimpleID::decode(data.value(LS("id")).toByteArray());
  if (SimpleID::typeOf(id) != SimpleID::UserId)
    return AuthResult(Notice::Forbidden, m_data.id);

  AuthResult result = AnonymousAuth::isCollision(id, m_data.nick, m_data.id, Storage::value(STORAGE_NICK_OVERRIDE).toBool());
  if (result.action == AuthResult::Reject) {
    if (result.status == Notice::NickAlreadyUse)
      m_cache[m_data.id + m_data.cookie] = data;

    return result;
  }

  ChatChannel channel = Ch::channel(id, SimpleID::UserId);
  bool created = false;

  if (!channel) {
    channel = ChatChannel(new ServerChannel(id, m_data.nick));
    created = true;

    channel->setAccount();
    channel->account()->provider = data.value(LS("provider")).toString();
    channel->account()->groups += LS("registered");
    channel->account()->setDate(DateTime::utc());

    channel->setName(m_data.nick);
    channel->gender().setRaw(m_data.gender);
    channel->user()->set(User(data.value(LS("user")).toMap()));
  }

  if (channel->status().value() == Status::Offline) {
    channel->setDate();
    channel->status().set(m_data.status);
  }

  if (!channel->isValid())
    return AuthResult(Notice::BadRequest, m_data.id);

  Core::add(channel);
  Ch::userChannel(channel, m_data, m_host, created, m_socket);

  LOG_INFO("N3010", "Core/ExternalAuth", channel->name() << "@" << m_host + "/" + ChatId(channel->id()).toString() << ", " << m_data.host)
  m_cache.remove(m_data.id + m_data.cookie);
  return AuthResult(id, m_data.id);
}
예제 #4
0
AuthResult DiscoveryAuth::auth(const AuthRequest &data)
{
  const QStringList methods = Ch::server()->feed(FEED_NAME_SERVER)->data().value(SERVER_FEED_AUTH_KEY).toStringList();

  if (methods.contains(AUTH_METHOD_ANONYMOUS) && !methods.contains(AUTH_METHOD_OAUTH))
    return AnonymousAuth::auth(data);

  return AuthResult(Notice::Found, data.id);
}