Commit 4c48c19f authored by armin's avatar armin
Browse files

Merge branch 'loginProblemsAfterRegistration' into 'master'

Login problems after registration

See merge request !108
parents 9c0c0416 66adc01c
#include "rocketchatgetusernamesuggestion.h"
RocketChatGetUsernameSuggestion::RocketChatGetUsernameSuggestion( const DdpCallback &pSuccess )
{
setSuccess( pSuccess );
QJsonArray params;
buildRequest( QStringLiteral( "getUsernameSuggestion" ), params );
}
#ifndef ROCKETCHATGETUSERNAMESUGGESTION_H
#define ROCKETCHATGETUSERNAMESUGGESTION_H
#include "ddpmethodrequest.h"
class RocketChatGetUsernameSuggestion : public DDPMethodRequest
{
public:
RocketChatGetUsernameSuggestion( const DdpCallback &pSuccess );
};
#endif // ROCKETCHATGETUSERNAMESUGGESTION_H
#include "rocketchatsetusername.h"
RocketChatSetUsername::RocketChatSetUsername( const QString &pUsername, const DdpCallback &pSuccess )
{
setSuccess( pSuccess );
QJsonArray params;
params.append( pUsername );
buildRequest( QStringLiteral( "setUsername" ), params );
}
#ifndef ROCKETCHATSETUSERNAME_H
#define ROCKETCHATSETUSERNAME_H
#include "ddpmethodrequest.h"
class RocketChatSetUsername : public DDPMethodRequest
{
public:
RocketChatSetUsername( const QString &pUsername, const DdpCallback &pSuccess );
};
#endif // ROCKETCHATSETUSERNAME_H
......@@ -100,6 +100,8 @@ SOURCES += api/meteorddp.cpp \
ddpRequests/rocketchatgetroomidbynameorid.cpp \
ddpRequests/rocketchatspotlightrequest.cpp \
repos/entities/rocketchatreplymessage.cpp \
ddpRequests/rocketchatgetusernamesuggestion.cpp \
ddpRequests/rocketchatsetusername.cpp
ddpRequests/rocketchatcreatepublicgrouprequest.cpp \
ddpRequests/rocketchatchangeuserpresencestatus.cpp \
ddpRequests/rocketchatsubscribeuserdata.cpp \
......@@ -206,6 +208,8 @@ HEADERS += \
ddpRequests/rocketchatspotlightrequest.h \
api/messagelistener.h \
repos/entities/rocketchatreplymessage.h \
ddpRequests/rocketchatgetusernamesuggestion.h \
ddpRequests/rocketchatsetusername.h
ddpRequests/rocketchatcreatepublicgrouprequest.h \
ddpRequests/rocketchatchangeuserpresencestatus.h \
ddpRequests/rocketchatchangeuserpresencedefaultstatus.h \
......
......@@ -747,15 +747,31 @@ void RocketChatServerData::loginWithToken( const QString &pUsername, const QStri
if ( !pToken.isEmpty() ) {
auto self = this;
RestRequestCallback meCallBackSuccess = [ self ]( QNetworkReply *, QJsonObject data, RestApi * ) {
QString username;
if ( data.contains( QStringLiteral( "username" ) ) ) {
self->mUsername = data[QStringLiteral( "username" )].toString();
self->mStorage->setUserName( self->mUsername );
username = data[QStringLiteral( "username" )].toString();
} else if ( data.contains( "name" ) ) {
QString name = data["name"].toString().toLower();
QStringList nameParts = name.split( " " );
username = nameParts.join( "." );
}
if ( username.length() ) {
self->mUsername = username;
self->mStorage->transaction();
self->mStorage->setUserData( self->mUsername, "" );
self->mStorage->setToken( self->mResumeToken, self->mTokenExpire );
self->mStorage->setUserId( self->mUserId );
self->mStorage->commit();
self->onResume();
self->onDDPAuthenticated();
} else {
qWarning() << "no valid user information, check message from server";
}
};
auto request = QSharedPointer<DDPLoginRequest>::create( pToken );
......@@ -827,15 +843,31 @@ void RocketChatServerData::loginWtihSamlToken( const QString &pToken )
if ( !pToken.isEmpty() ) {
qDebug() << pToken;
RestRequestCallback meCallBackSuccess = [ = ]( QNetworkReply *, QJsonObject data, RestApi * ) {
auto self = this;
RestRequestCallback meCallBackSuccess = [ self ]( QNetworkReply *, QJsonObject data, RestApi * ) {
QString username;
if ( data.contains( QStringLiteral( "username" ) ) ) {
mUsername = data[QStringLiteral( "username" )].toString();
mStorage->setUserName( mUsername );
onResume();
this->onDDPAuthenticated();
username = data[QStringLiteral( "username" )].toString();
} else if ( data.contains( "name" ) ) {
QString name = data["name"].toString().toLower();
QStringList nameParts = name.split( " " );
username = nameParts.join( "." );
}
if ( username.length() ) {
self->mUsername = username;
self->mStorage->transaction();
self->mStorage->setUserData( self->mUsername, "" );
self->mStorage->setToken( self->mResumeToken, self->mTokenExpire );
self->mStorage->setUserId( self->mUserId );
self->mStorage->commit();
self->onResume();
self->onDDPAuthenticated();
} else {
qWarning() << "no valid user information, check message from server";
}
};
auto request = QSharedPointer<ddpSamlLoginRequest>::create( pToken );
......@@ -865,9 +897,7 @@ void RocketChatServerData::loginWtihSamlToken( const QString &pToken )
RestApiRequest meRequest
= RestApiRequest( new restMeRequest( meCallBackSuccess ) );
mRestApi->sendRequest( meRequest );
self->sendApiRequest( meRequest, true );
}
}
......@@ -895,8 +925,37 @@ void RocketChatServerData::loginWithOpenIDToken( const QString &pToken, const QS
auto self = this;
RestRequestCallback meCallBackSuccess = [ self ]( QNetworkReply *, QJsonObject data, RestApi * ) {
QString username;
if ( data.contains( QStringLiteral( "username" ) ) ) {
self->mUsername = data[QStringLiteral( "username" )].toString();
username = data[QStringLiteral( "username" )].toString();
} else {
DdpCallback nameSuggestionSucces = [ = ]( QJsonObject pResponse, MeteorDDP * ) {
if ( pResponse.contains( "result" ) ) {
QString username = pResponse["result"].toString();
DdpCallback setUsernameSuccess = [ = ]( QJsonObject pResponse, MeteorDDP * ) {
if ( pResponse.contains( "result" ) ) {
QString username = pResponse["result"].toString();
self->mUsername = username;
self->mStorage->transaction();
self->mStorage->setUserData( self->mUsername, "" );
self->mStorage->setToken( self->mResumeToken, self->mTokenExpire );
self->mStorage->setUserId( self->mUserId );
self->mStorage->commit();
self->onResume();
self->onDDPAuthenticated();
}
};
QSharedPointer<RocketChatSetUsername> setUsernameRequest( new RocketChatSetUsername( username, setUsernameSuccess ) );
self->sendDdprequest( setUsernameRequest, true );
}
};
QSharedPointer<RocketChatGetUsernameSuggestion> nameSuggestionRequest( new RocketChatGetUsernameSuggestion( nameSuggestionSucces ) );
self->sendDdprequest( nameSuggestionRequest, true );
}
if ( username.length() ) {
self->mUsername = username;
self->mStorage->transaction();
self->mStorage->setUserData( self->mUsername, "" );
self->mStorage->setToken( self->mResumeToken, self->mTokenExpire );
......@@ -904,8 +963,9 @@ void RocketChatServerData::loginWithOpenIDToken( const QString &pToken, const QS
self->mStorage->askForcommit();
self->onResume();
self->onDDPAuthenticated();
} else {
qWarning() << "no valid user information, check message from server";
}
};
auto request = QSharedPointer<DDPOpenIDLoginRequest>::create( pToken, pSecret );
......@@ -936,7 +996,7 @@ void RocketChatServerData::loginWithOpenIDToken( const QString &pToken, const QS
RestApiRequest meRequest
= RestApiRequest( new restMeRequest( meCallBackSuccess ) );
self->mRestApi->sendRequest( meRequest );
self->sendApiRequest( meRequest, true );
}
}
......
......@@ -67,6 +67,8 @@
#include "ddpRequests/rocketchatunblockuserrequest.h"
#include "ddpRequests/rocketchatsubscriberoomschanged.h"
#include "ddpRequests/rocketchatmessagesearchrequest.h"
#include "ddpRequests/rocketchatgetusernamesuggestion.h"
#include "ddpRequests/rocketchatsetusername.h"
#include "restRequests/restrequest.h"
#include "restRequests/restlogoutrequest.h"
#include "restRequests/getserverinforequest.h"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment