Skip to content

Commit

Permalink
Integrate "Add Account (advanced)" in WelcomeLogIn.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
lissine0 authored and tmolitor-stud-tu committed Oct 18, 2024
1 parent c5956ce commit 38cc560
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 63 deletions.
12 changes: 8 additions & 4 deletions Monal/Classes/DataLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ -(BOOL) updateAccounWithDictionary:(NSDictionary*) dictionary
NSString* query = @"UPDATE account SET server=?, other_port=?, username=?, resource=?, domain=?, enabled=?, directTLS=?, rosterName=?, statusMessage=?, needs_password_migration=? WHERE account_id=?;";
NSString* server = (NSString*)[dictionary objectForKey:kServer];
NSString* port = (NSString*)[dictionary objectForKey:kPort];
if ([port isEqual:@""])
port = nil;
NSArray* params = @[
server == nil ? @"" : server,
port == nil ? @"5222" : port,
nilDefault(server, @""),
nilDefault(port, @"5222"),
((NSString*)[dictionary objectForKey:kUsername]),
((NSString*)[dictionary objectForKey:kResource]),
((NSString*)[dictionary objectForKey:kDomain]),
Expand All @@ -272,9 +274,11 @@ -(NSNumber*) addAccountWithDictionary:(NSDictionary*) dictionary
NSString* query = @"INSERT INTO account (server, other_port, resource, domain, enabled, directTLS, username, rosterName, statusMessage, plain_activated) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
NSString* server = (NSString*) [dictionary objectForKey:kServer];
NSString* port = (NSString*)[dictionary objectForKey:kPort];
if ([port isEqual:@""])
port = nil;
NSArray* params = @[
server == nil ? @"" : server,
port == nil ? @"5222" : port,
nilDefault(server, @""),
nilDefault(port, @"5222"),
((NSString *)[dictionary objectForKey:kResource]),
((NSString *)[dictionary objectForKey:kDomain]),
[dictionary objectForKey:kEnabled] ,
Expand Down
9 changes: 5 additions & 4 deletions Monal/Classes/MLSettingsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,16 @@ -(void)tableView:(UITableView*) tableView didSelectRowAtIndexPath:(NSIndexPath*)
else
{
switch(indexPath.row - [self getAccountNum]) {
case QuickSettingsRow:
{
case QuickSettingsRow: {
UIViewController* loginView = [[SwiftuiInterface new] makeViewWithName:@"LogIn"];
[self showDetailViewController:loginView sender:self];
break;
}
case AdvancedSettingsRow:
[self performSegueWithIdentifier:@"editXMPP" sender:self];
case AdvancedSettingsRow: {
UIViewController* advancedLoginView = [[SwiftuiInterface new] makeViewWithName:@"AdvancedLogIn"];
[self showDetailViewController:advancedLoginView sender:self];
break;
}
default:
unreachable();
}
Expand Down
1 change: 1 addition & 0 deletions Monal/Classes/MLXMPPManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ NS_ASSUME_NONNULL_BEGIN
-(NSDate *) connectedTimeFor:(NSNumber*) accountID;

-(NSNumber* _Nullable) login:(NSString*) jid password:(NSString*) password;
-(NSNumber* _Nullable) login:(NSString*) jid password:(NSString*) password hardcodedServer:(NSString* _Nullable) hardcodedServer hardcodedPort:(NSString* _Nullable) hardcodedPort forceDirectTLS:(BOOL) directTLS allowPlainAuth:(BOOL) plainActivated;
-(void) removeAccountForAccountID:(NSNumber*) accountID;
-(void) addNewAccountToKeychainAndConnectWithPassword:(NSString*) password andAccountID:(NSNumber*) accountID;

Expand Down
37 changes: 26 additions & 11 deletions Monal/Classes/MLXMPPManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,26 @@ -(void) sendChatState:(BOOL) isTyping toContact:(MLContact*) contact
#pragma mark - login/register

-(NSNumber*) login:(NSString*) jid password:(NSString*) password
{
NSArray* elements = [jid componentsSeparatedByString:@"@"];
MLAssert([elements count] > 1, @"Got invalid jid", (@{@"jid": nilWrapper(jid), @"elements": elements}));
NSString* domain = ((NSString*)[elements objectAtIndex:1]).lowercaseString;

//we don't want to set kPlainActivated (not even according to our preload list) and default to plain_activated=false,
//because the error message will warn the user and direct them to the advanced account creation menu to activate PLAIN
//if they still want to connect to this server
//only exception: yax.im --> we don't want to suggest a server during account creation that has a scary warning
//when logging in using another device afterwards
//TODO: to be removed once yax.im and quicksy.im supports SASL2 and SSDP!!
//TODO: use preload list and allow PLAIN for all others once enough domains are on this list
//allow plain for all servers not on preload list, since prosody with SASL2 wasn't even released yet
BOOL defaultPlainActivated = YES;
BOOL plainActivated = ([domain isEqualToString:@"yax.im"] || [domain isEqualToString:@"quicksy.im"]) ? YES : defaultPlainActivated;

return [self login:jid password:password hardcodedServer:nil hardcodedPort:nil forceDirectTLS:NO allowPlainAuth:plainActivated];
}

-(NSNumber*) login:(NSString*) jid password:(NSString*) password hardcodedServer:(NSString*) hardcodedServer hardcodedPort:(NSString*) hardcodedPort forceDirectTLS:(BOOL) directTLS allowPlainAuth:(BOOL) plainActivated
{
//check if it is a JID
NSArray* elements = [jid componentsSeparatedByString:@"@"];
Expand All @@ -739,17 +759,12 @@ -(NSNumber*) login:(NSString*) jid password:(NSString*) password
[dic setObject:user forKey:kUsername];
[dic setObject:[HelperTools encodeRandomResource] forKey:kResource];
[dic setObject:@YES forKey:kEnabled];
[dic setObject:@NO forKey:kDirectTLS];
//we don't want to set kPlainActivated (not even according to our preload list) and default to plain_activated=false,
//because the error message will warn the user and direct them to the advanced account creation menu to activate PLAIN
//if they still want to connect to this server
//only exception: yax.im --> we don't want to suggest a server during account creation that has a scary warning
//when logging in using another device afterwards
//TODO: to be removed once yax.im and quicksy.im supports SASL2 and SSDP!!
//TODO: use preload list and allow PLAIN for all others once enough domains are on this list
//allow plain for all servers not on preload list, since prosody with SASL2 wasn't even released yet
NSNumber* defaultPlainActivated = @YES;
[dic setObject:([domain isEqualToString:@"yax.im"] || [domain isEqualToString:@"quicksy.im"] ? @YES : defaultPlainActivated) forKey:kPlainActivated];
if(hardcodedServer != nil)
[dic setObject:hardcodedServer forKey:kServer];
if(hardcodedPort != nil)
[dic setObject:hardcodedPort forKey:kPort];
[dic setObject:@(directTLS) forKey:kDirectTLS];
[dic setObject:@(plainActivated) forKey:kPlainActivated];

NSNumber* accountID = [[DataLayer sharedInstance] addAccountWithDictionary:dic];
if(accountID == nil)
Expand Down
2 changes: 2 additions & 0 deletions Monal/Classes/SwiftuiHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,8 @@ class SwiftuiInterface : NSObject {
host = UIHostingController(rootView:AnyView(AddTopLevelNavigation(withDelegate:delegate, to:WelcomeLogIn(delegate:delegate))))
case "LogIn":
host = UIHostingController(rootView:AnyView(UIKitWorkaround(WelcomeLogIn(delegate:delegate))))
case "AdvancedLogIn":
host = UIHostingController(rootView:AnyView(UIKitWorkaround(WelcomeLogIn(advancedMode: true, delegate: delegate))))
case "ChatPlaceholder":
host = UIHostingController(rootView:AnyView(ChatPlaceholder()))
case "GeneralSettings" :
Expand Down
Loading

0 comments on commit 38cc560

Please sign in to comment.