Skip to content

Commit

Permalink
Fix #1004 - We can now use url parameters to set user, pass and service
Browse files Browse the repository at this point in the history
If /?user= is set then it will append the username and try to guess the
service
If /?pass= is set then it will append the given password
If /?service= is set it will set the service directly (no more guessing
fron username).

If at least /?user=&pass= are set, this will auto fill and auto log the
give user.

Note: URL params needs to be urlencoded (like
index.html?user=admin%40archipelproject.org&pass=admin)
  • Loading branch information
CyrilPeponnet committed Feb 25, 2015
1 parent 6ac8869 commit 12c04e8
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions ArchipelClient/Controllers/TNConnectionController.j
Expand Up @@ -33,6 +33,20 @@
@class CPLocalizedString
@class TNDatasourceRoster

function _get_query_parameter_with_name(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);

return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var user = _get_query_parameter_with_name("user"),
pass = _get_query_parameter_with_name("pass"),
service = _get_query_parameter_with_name("service");

TNConnectionControllerCurrentUserVCardRetreived = @"TNConnectionControllerCurrentUserVCardRetreived";
TNConnectionControllerConnectionStarted = @"TNConnectionControllerConnectionStarted";

Expand Down Expand Up @@ -79,6 +93,19 @@ var TNConnectionControllerForceResource,
*/
- (void)awakeFromCib
{

if (user)
{
[fieldJID setStringValue:user]
if (!service)
[fieldService setStringValue:TNArchipelServiceTemplate.replace("@DOMAIN@",user.split("@")[1])]
else
[fieldService setStringValue:service]
}

if (pass)
[fieldPassword setStringValue:pass]

[mainWindow setShowsResizeIndicator:NO];
[mainWindow setDefaultButton:buttonConnect];

Expand Down Expand Up @@ -153,7 +180,8 @@ var TNConnectionControllerForceResource,
{
var lastPassword = [[CPUserDefaults standardUserDefaults] objectForKey:@"TNArchipelXMPPPassword"];

[fieldPassword setStringValue:lastPassword || @""];
if ([fieldPassword stringValue] == @"")
[fieldPassword setStringValue:lastPassword];
}

- (void)_prepareService
Expand All @@ -174,7 +202,8 @@ var TNConnectionControllerForceResource,

var lastService = [[CPUserDefaults standardUserDefaults] objectForKey:@"TNArchipelXMPPService"];

[fieldService setStringValue:lastService || @""];
if ([fieldService stringValue] == @"")
[fieldService setStringValue:lastService];
}

- (void)_saveCredentials
Expand Down

0 comments on commit 12c04e8

Please sign in to comment.