Skip to content

Commit

Permalink
Add fix for full domain user names
Browse files Browse the repository at this point in the history
  • Loading branch information
onurkepenek committed Jan 3, 2022
1 parent ac41562 commit ba72b89
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/dialog_webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Dialog_webview::Dialog_webview(QWidget *parent) :
QString tmpurl = checkPasswordResetWebPage();

if(!tmpurl.isEmpty() && !tmpurl.isNull()){
ui->widget1->load(QUrl(tmpurl,QUrl::ParsingMode::TolerantMode));
//ui->widget1->load(QUrl(tmpurl,QUrl::ParsingMode::TolerantMode));
ui->widget1->setUrl(QUrl(tmpurl,QUrl::ParsingMode::TolerantMode));
//ui->widget1->setFocus();
qInfo() << "Opening webpage " + tmpurl + " now";
}else{
Expand Down
75 changes: 64 additions & 11 deletions src/loginform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ void LoginForm::initialize()
ui->userInput->completer()->setCompletionMode(QCompleter::InlineCompletion);
}

QString user = Cache().getLastUser();
QString tmp = Cache().getLastUser();
QString user = getShortUsername(tmp);

if (user.isEmpty() || user.isNull()) {
user = m_Greeter.selectUserHint();
ui->pushButton_right->hide();
currentSessionStr = m_Greeter.defaultSessionHint();
}else{
currentSessionStr = Cache().getLastSession(user);
currentSessionStr = Cache().getLastSession(getShortUsername(user));
}


Expand Down Expand Up @@ -377,9 +378,9 @@ void LoginForm::authenticationComplete()

needPasswordChange = 0;

addUsertoCache(lastuser);
Cache().setLastUser(lastuser);
Cache().setLastSession(lastuser, currentSessionStr);
addUsertoCache(getShortUsername(lastuser));
Cache().setLastUser(getShortUsername(lastuser));
Cache().setLastSession(getShortUsername(lastuser), currentSessionStr);
Cache().sync();

qWarning() << "Start session : " << currentSessionStr;
Expand Down Expand Up @@ -559,11 +560,13 @@ void LoginForm::initializeUserList(){

total_user_count = 0;
animationprogress = false;
QString tmp;



for(int i = 0; i < Settings().cachedusercount(); i++){
userList[i] = Cache().getLastUserfromIndex(i);
tmp = Cache().getLastUserfromIndex(i);
userList[i] = getShortUsername(tmp);

if(!userList[i].isNull() && !userList[i].isEmpty() && userList[i].length() > 1)
total_user_count++;
Expand All @@ -584,7 +587,7 @@ void LoginForm::initializeUserList(){
qInfo() << (QString::number(total_user_count) + " users found for last users cache");


currentSessionStr = Cache().getLastSession( userList[0]);
currentSessionStr = Cache().getLastSession( getShortUsername(userList[0]));
qInfo() << "currentSessionStr: " << currentSessionStr;

total_user_count++;
Expand Down Expand Up @@ -661,7 +664,6 @@ void LoginForm::addUsertoCache(QString user_name){
if(userList[0].isNull() || userList[0].isEmpty() || userList[0].length() < 2){
userList[i].clear();
}

if(userList[i].compare(user_name) == 0)
userList[i].clear();

Expand Down Expand Up @@ -720,7 +722,7 @@ void LoginForm::addUsertoCache(QString user_name){

for(i = 0; i < Settings().cachedusercount(); i++){
if(!userList[i].isNull() && !userList[i].isEmpty() && userList[i].length() > 2)
Cache().setLastUsertoIndex(userList[i], i);
Cache().setLastUsertoIndex(getShortUsername(userList[i]), i);
else
Cache().setLastUsertoIndex("", i);

Expand Down Expand Up @@ -1294,7 +1296,7 @@ void LoginForm::LoginTimerFinished(){
qInfo() << "Login start for " + userid;

qInfo() << "User name is sending";
m_Greeter.authenticate(userid.trimmed());
m_Greeter.authenticate(fixUserName(userid));
// addUsertoCache(userid.trimmed());//todo delete
//Cache().setLastUser(userid.trimmed());//todo delete

Expand Down Expand Up @@ -1612,7 +1614,7 @@ void LoginForm::passwordResetTimerFinished(){
userx = toolButtons[(lastuserindex+ 1) % 3]->text();
}

m_Greeter.authenticate(userx);
m_Greeter.authenticate(fixUserName(userx));
resetTimerState = 2;
break;

Expand Down Expand Up @@ -2560,3 +2562,54 @@ void LoginForm::on_userInput_textEdited(const QString &arg1)
emit resetHideTimer();
justshowed = false;
}



QString LoginForm::fixUserName(QString &username){

QString newname, tmpname;
int offset;
QString realm = getUserRealm(username);

offset = username.indexOf(realm.toLower());

if(offset < 0)
offset = username.indexOf(realm.toUpper());

if(offset > 1){
tmpname = username.mid(0, offset - 1);
}else{
tmpname = username;
}

if(realm.length() > 2){
newname = tmpname.trimmed() + "@" + realm;
}else {
newname = tmpname;
}

return newname;
}

QString LoginForm::getShortUsername(QString &username){

QString newname, tmpname;
int offset;
QString realm = getUserRealm(username);

offset = username.indexOf(realm.toLower());

if(offset < 0)
offset = username.indexOf(realm.toUpper());

if(offset > 1){
tmpname = username.mid(0, offset - 1);
}else{
tmpname = username;
}


return tmpname;

}

2 changes: 2 additions & 0 deletions src/loginform.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ private slots:
QString getUserRealm(QString username);
void debugBox(QString mes);
QString translateResetPwdMessage(QString message);
QString fixUserName(QString &username);
QString getShortUsername(QString &username);

Ui::LoginForm *ui;

Expand Down

0 comments on commit ba72b89

Please sign in to comment.