示例#1
0
void AccountNotificationService::notifyConnectionError(const Account &account, const QString &errorServer, const QString &errorMessage)
{
	if (account.property(QStringLiteral("notify:ignore-connection-errors"), false).toBool())
		return;

	auto lastConnectionError = account.property(QStringLiteral("notify:last-connection-error"), QDateTime{}).toDateTime();
	if (lastConnectionError.isValid() && lastConnectionError.addSecs(60) > QDateTime::currentDateTime())
		return;

	account.addProperty(QStringLiteral("notify:last-connection-error"), QDateTime::currentDateTime(), CustomProperties::NonStorable);

	auto data = QVariantMap{};
	data.insert(QStringLiteral("account"), qVariantFromValue(account));
	data.insert(QStringLiteral("error-server"), errorServer);
	data.insert(QStringLiteral("error-message"), errorMessage);

	auto notification = Notification{};
	notification.type = m_connectionErrorEvent.name();
	notification.title = tr("Connection error");
	notification.text = normalizeHtml(plainToHtml(tr("Connection error on account: %1 (%2)").arg(account.id(), account.accountIdentity().name())));
	notification.data = std::move(data);
	notification.details = normalizeHtml(plainToHtml(errorDetails(errorServer, errorMessage)));
	notification.callbacks.append(QStringLiteral("connection-ignore-errors"));

	m_notificationService->notify(notification);
}
示例#2
0
void Period::changePart(int s)
{
	if(!type) { addSecs(s*secs()); return; }
	uint np = type->parts.size();
	if(np)
	{
		uint p = (part + np + s)%np;
		if(part == 0 && s < 0) add(t1, type->base, -1);
		if(part == np - 1 && s > 0) add(t1, type->base, 1);
		part = p;
		QDateTime dt = set(from(), type->base, type->parts[part]);
		setFrom(dt); setTo(dt);
		p = (part + 1)%np;
                if(part == np - 1) add(t2, type->base, 1);
		setTo(set(to(), type->base, type->parts[p]));
	}
	else
	{
		setFrom(set(from(), type->base));
		add(t1, type->base, s);
		t2 = t1;
		add(t2, type->base, 1);
	}
}
AuthenticationResultPtr OAuth2Response::parseTokenResponse(TokenResponsePtr tokenResponse, CallStatePtr/* callState*/)
{
    Logger::info(Tag(), "parseTokenResponse");
    AuthenticationResultPtr result = nullptr;

    if (!tokenResponse->accessToken.empty())
    {
        auto curTimeUts = QDateTime::currentDateTimeUtc();
        Logger::info(Tag(), "curTimeUTC: %; expiresIn: %", curTimeUts.toString("HH:mm:ss MM.dd.yy").toStdString(), tokenResponse->expiresIn);

        auto expiresUtc = curTimeUts.addSecs(tokenResponse->expiresIn);
        DateTimeOffset expiresOn = expiresUtc.toTime_t();

        Logger::info(Tag(), "tonken expiresOn: % (%)", expiresUtc.toString("HH:mm:ss MM.dd.yy").toStdString(), expiresOn);

        result = std::make_shared<AuthenticationResult>(tokenResponse->tokenType, tokenResponse->accessToken, tokenResponse->refreshToken, expiresOn);
        // This is only needed for AcquireTokenByAuthorizationCode in which parameter resource is optional and we need
        // to get it from the STS response.
        result->resource(tokenResponse->resource);
        result->isMultipleResourceRefreshToken(!tokenResponse->refreshToken.empty() && !tokenResponse->resource.empty());

        IdTokenPtr idToken = OAuth2Response::parseIdToken(tokenResponse->idToken);
        if (idToken != nullptr)
        {
            String tenantId = idToken->tenantId;
            String uniqueId;
            String displayableId;

            if (!idToken->objectId.empty())
            {
                uniqueId = idToken->objectId;
            }
            else if (!idToken->subject.empty())
            {
                uniqueId = idToken->subject;
            }

            if (!idToken->UPN.empty())
            {
                displayableId = idToken->UPN;
            }
            else if (!idToken->email.empty())
            {
                displayableId = idToken->email;
            }

            String givenName = idToken->givenName;
            String familyName = idToken->familyName;
            String identityProvider = idToken->identityProvider.empty() ? idToken->issuer : idToken->identityProvider;
            DateTimeOffset passwordExpiresOn = 0;
            if (idToken->passwordExpiration > 0)
            {
                passwordExpiresOn = QDateTime::currentDateTimeUtc().addSecs(idToken->passwordExpiration).toTime_t();
            }

            String changePasswordUri;
            if (!idToken->passwordChangeUrl.empty())
            {
                changePasswordUri = idToken->passwordChangeUrl;
            }

            auto userInfo = std::make_shared<UserInfo>();
            userInfo->uniqueId(uniqueId);
            userInfo->displayableId(displayableId);
            userInfo->givenName(givenName);
            userInfo->familyName(familyName);
            userInfo->identityProvider(identityProvider);
            userInfo->passwordExpiresOn(passwordExpiresOn);
            userInfo->passwordChangeUrl(changePasswordUri);

            result->updateTenantAndUserInfo(tenantId, tokenResponse->idToken, userInfo );
        }
    }
    else if (!tokenResponse->error.empty())
    {
        Logger::error(Tag(), "error: %, description: %", tokenResponse->error, tokenResponse->errorDescription);
        throw RmsauthException(tokenResponse->error, tokenResponse->errorDescription);
    }
    else
    {
        throw RmsauthException(Constants::rmsauthError().Unknown);
    }

    return result;
}
示例#4
0
文件: Time.cpp 项目: chipjacks/Runlog
Time::Time(unsigned int hours, unsigned int mins, unsigned int secs) {
	addHours(hours);
	addMins(mins);
	addSecs(secs);
}
示例#5
0
文件: Time.cpp 项目: chipjacks/Runlog
void Time::addMins(unsigned int mins) {
	addSecs(mins*60);
}
QVariant ScheduleModel::data(const QModelIndex &index, int role) const
{
    QVariant res;

    if(index.row() != rowCount()-1)
    {
        auto dtCome = m_times[index.row()].first;
        auto dtLeave = m_times[index.row()].second;

        if(!(dtCome == dtLeave && dtCome.time() == QTime(0,0)))
        {
            //measurement error fix
            dtCome = dtCome.addSecs(-5*60);
            dtLeave = dtLeave.addSecs(5*60);
        }

        auto diffSecs = dtCome.secsTo(dtLeave);
        QTime diffTime = QTime(0,0).addSecs(diffSecs);
        QTime needToWork;
        auto holidayData = m_holidays.find(dtCome.date());
        if(holidayData != m_holidays.end())
        {
            if(holidayData.value() == HOLIDAY)
                needToWork = QTime(0,0);
            else if(holidayData.value() == SHORT_DAY)
                needToWork = QTime(7,30);
            else
                needToWork = QTime(8,30);
        }
        else
        {
            if(dtCome.date().dayOfWeek() == 6 || dtCome.date().dayOfWeek() == 7)
                needToWork = QTime(0,0);
            else
                needToWork = QTime(8,30);
        }

        QString resultString;
        if(index.column() == COL_RESULT)
        {
            //SKIP -> current day, no result yet
            if(dtCome.date() == QDateTime::currentDateTime().date())
                return res;
        }


        if(role == Qt::DisplayRole)
        {
            switch(index.column())
            {
            case COL_COME:
                if(dtCome.isValid())
                    res = dtCome.toString();
                break;
            case COL_LEAVE:
                if(dtLeave.isValid())
                    res = dtLeave.toString();
                break;
            case COL_DIFF:
                if(dtCome.isValid() && dtLeave.isValid())
                {
                    res = diffTime.toString();
                }
                break;
            case COL_RESULT:

                if(diffTime < needToWork)
                {
                    diffTime = QTime(0,0).addSecs(QTime(0,0).secsTo(needToWork) - QTime(0,0).secsTo(diffTime));
                    resultString += "-";
                }
                else if(diffTime > needToWork)
                {
                    diffTime = QTime(0,0).addSecs(QTime(0,0).secsTo(diffTime) - QTime(0,0).secsTo(needToWork));
                }
                else
                    diffTime = QTime(0,0);
                res = resultString + diffTime.toString();
            }
        }
        else
        if(index.column() == COL_DIFF && role == ROLE_DIFF)
        {            
            res = diffSecs;
        }
        else
        if(index.column() == COL_RESULT && role == ROLE_RESULT)
        {            
            auto resSecs = QTime(0,0).secsTo(needToWork) - diffSecs;
            res = resSecs;
        }
        else
        if((index.column() == COL_COME || index.column() == COL_LEAVE) && role == ROLE_DATETIME)
        {
            if(index.column() == COL_COME)
                res = dtCome.toTime_t();
            else
                res = dtLeave.toTime_t();
        }
    }
    else
    {
        if(role == Qt::DisplayRole)
        {
            unsigned int sum = 0, temp = 0;
            int result = 0, tempResult = 0;
            bool ok = false;
            switch(index.column())
            {
            //Last row
            case COL_LEAVE:
                res = tr("Sum:");
                break;
            case COL_DIFF:
            {
                for(auto i = 0; i < rowCount() - 1; ++i)
                {
                    temp = data(this->index(i, COL_DIFF), ROLE_DIFF).toUInt(&ok);
                    if(ok)
                        sum += temp;
                }                
                res = secondsToString(sum);
                break;
            }
            case COL_RESULT:
                for(auto i = 0; i < rowCount() - 1; ++i)
                {
                    tempResult = data(this->index(i, COL_RESULT), ROLE_RESULT).toInt(&ok);
                    if(ok)
                        result += tempResult;
                }
                //if result < 0 it's overwork
                result *= -1;

                res = secondsToString(result);
                break;

            }
        }
    }
//    else
//        res = QAbstractItemModel::data(index, role);
    return res;
}