2010-09-25 07:34:32 -05:00
//
// MGMAccountSetup . m
// VoiceMob
//
// Created by Mr . Gecko on 9 / 24 / 10.
2013-07-20 06:56:17 -05:00
// Copyright ( c ) 2011 Mr . Gecko ' s Media ( James Coleman ) . http : // mrgeckosmedia . com /
2010-09-25 07:34:32 -05:00
//
# import "MGMAccountSetup.h"
2010-09-30 12:27:22 -05:00
# import "MGMController.h"
2010-09-25 07:34:32 -05:00
# import "MGMSIPUser.h"
# import "MGMVMAddons.h"
2010-10-01 22:03:15 -05:00
# import < VoiceBase / VoiceBase . h >
2010-09-25 07:34:32 -05:00
# import < MGMUsers / MGMUsers . h >
NSString * const MGMRadioButton = @ "Radio" ;
NSString * const MGMRadioSelectedButton = @ "RadioSelected" ;
NSString * const MGMSGoBack = @ "Go Back" ;
NSString * const MGMSCancel = @ "Cancel" ;
NSString * const MGMSDisagree = @ "Disagree" ;
NSString * const MGMSContinue = @ "Continue" ;
NSString * const MGMSDone = @ "Done" ;
NSString * const MGMSAgree = @ "Agree" ;
NSString * const MGMSGoogleVoice = @ "Google Voice" ;
NSString * const MGMSGoogleContacts = @ "Google Contacts" ;
NSString * const MGMSSIP = @ "Session Initiation Protocol" ;
NSString * const MGMSAccountType = @ "MGMSAccountType" ;
NSString * const MGMS7Crediential = @ "Checking Login Credentials." ;
NSString * const MGMS7SIPWaiting = @ "Waiting for Registration Status." ;
NSString * const MGMSIPDefaultDomain = @ "proxy01.sipphone.com" ;
2013-07-20 06:56:17 -05:00
NSString * const MGMASKeyboardBounds = @ "UIKeyboardBoundsUserInfoKey" ;
2010-09-25 07:34:32 -05:00
@ implementation MGMAccountSetup
2010-09-30 12:27:22 -05:00
- ( id ) initWithController : ( MGMController * ) theController {
2013-07-20 06:56:17 -05:00
if ( ( self = [ super init ] ) ) {
2010-09-25 07:34:32 -05:00
if ( ! [ [ NSBundle mainBundle ] loadNibNamed : [ [ UIDevice currentDevice ] appendDeviceSuffixToString : @ "AccountSetup" ] owner : self options : nil ] ) {
NSLog ( @ "Unable to load Account Setup" ) ;
2010-09-30 12:27:22 -05:00
[ self release ] ;
self = nil ;
2010-09-25 07:34:32 -05:00
} else {
2010-09-30 12:27:22 -05:00
controller = theController ;
2010-09-25 07:34:32 -05:00
displaying = NO ;
needsDisplay = NO ;
goingBack = NO ;
2010-09-30 12:27:22 -05:00
[ self setSetupOnly : NO ] ;
accountType = 0 ;
2010-09-25 07:34:32 -05:00
accountsCreated = [ NSMutableArray new ] ;
S7ConnectionManager = [ [ MGMURLConnectionManager managerWithCookieStorage : nil ] retain ] ;
2013-07-20 06:56:17 -05:00
NSNotificationCenter * notifications = [ NSNotificationCenter defaultCenter ] ;
[ notifications addObserver : self selector : @ selector ( keyboardWillShow : ) name : UIKeyboardWillShowNotification object : nil ] ;
[ notifications addObserver : self selector : @ selector ( keyboardWillHide : ) name : UIKeyboardWillHideNotification object : nil ] ;
2010-09-25 07:34:32 -05:00
}
}
return self ;
}
- ( void ) dealloc {
2013-07-20 06:56:17 -05:00
# if releaseDebug
NSLog ( @ "%s Releasing" , __PRETTY _FUNCTION __ ) ;
# endif
[ [ NSNotificationCenter defaultCenter ] removeObserver : self ] ;
[ setupView release ] ;
[ view release ] ;
[ titleField release ] ;
[ backButton release ] ;
[ continueButton release ] ;
[ S1View release ] ;
[ S2View release ] ;
[ S2GVButton release ] ;
[ S2GCButton release ] ;
[ S2SIPButton release ] ;
[ S3View release ] ;
[ S3Browser release ] ;
[ S4View release ] ;
[ S4EmailField release ] ;
[ S4PasswordField release ] ;
[ S5View release ] ;
[ S5EmailField release ] ;
[ S5PasswordField release ] ;
[ S6View release ] ;
[ S6FullNameField release ] ;
[ S6DomainField release ] ;
[ S6RegistrarField release ] ;
[ S6UserNameField release ] ;
[ S6PasswordField release ] ;
[ S7View release ] ;
[ S7Progress release ] ;
[ S7StatusField release ] ;
[ S7CheckUser release ] ;
[ S7CheckInstance release ] ;
[ S7ConnectionManager release ] ;
2010-09-25 07:34:32 -05:00
# if MGMSIPENABLED
2013-07-20 06:56:17 -05:00
[ S7CheckSIPAccount release ] ;
[ S7SIPRegistrationTimeout invalidate ] ;
[ S7SIPRegistrationTimeout release ] ;
2010-09-25 07:34:32 -05:00
# endif
2013-07-20 06:56:17 -05:00
[ S8View release ] ;
[ S8MessageField release ] ;
[ S8Message release ] ;
[ S9View release ] ;
[ S9MessageField release ] ;
[ accountsCreated release ] ;
2010-09-25 07:34:32 -05:00
[ super dealloc ] ;
}
- ( UIView * ) view {
2010-09-30 12:27:22 -05:00
if ( lastView = = nil )
[ self displayStep ] ;
2010-09-25 07:34:32 -05:00
return setupView ;
}
- ( IBAction ) closeKeyboard : ( id ) sender {
}
2013-07-20 06:56:17 -05:00
- ( void ) keyboardWillShow : ( NSNotification * ) theNotification {
if ( step ! = 6 ) return ;
CGSize keyboardSize = CGSizeZero ;
if ( [ [ theNotification userInfo ] objectForKey : MGMASKeyboardBounds ] ! = nil )
keyboardSize = [ [ [ theNotification userInfo ] objectForKey : MGMASKeyboardBounds ] CGRectValue ] . size ;
else
keyboardSize = [ [ [ theNotification userInfo ] objectForKey : UIKeyboardFrameBeginUserInfoKey ] CGRectValue ] . size ;
CGRect setupRect = [ setupView frame ] ;
setupRect . origin . y = ( - keyboardSize . height ) + 44 ;
if ( ! CGRectEqualToRect ( [ setupView frame ] , setupRect ) ) {
[ UIView beginAnimations : nil context : nil ] ;
[ UIView setAnimationDuration : 0.3 ] ;
[ UIView setAnimationCurve : UIViewAnimationCurveEaseInOut ] ;
[ setupView setFrame : setupRect ] ;
[ UIView commitAnimations ] ;
}
}
- ( void ) keyboardWillHide : ( NSNotification * ) theNotification {
if ( step ! = 6 ) return ;
CGSize keyboardSize = CGSizeZero ;
if ( [ [ theNotification userInfo ] objectForKey : MGMASKeyboardBounds ] ! = nil )
keyboardSize = [ [ [ theNotification userInfo ] objectForKey : MGMASKeyboardBounds ] CGRectValue ] . size ;
else
keyboardSize = [ [ [ theNotification userInfo ] objectForKey : UIKeyboardFrameBeginUserInfoKey ] CGRectValue ] . size ;
CGRect setupRect = [ setupView frame ] ;
setupRect . origin . y = 0 ;
if ( ! CGRectEqualToRect ( [ setupView frame ] , setupRect ) ) {
[ UIView beginAnimations : nil context : nil ] ;
[ UIView setAnimationDuration : 0.3 ] ;
[ UIView setAnimationCurve : UIViewAnimationCurveEaseInOut ] ;
[ setupView setFrame : setupRect ] ;
[ UIView commitAnimations ] ;
}
}
2010-09-25 07:34:32 -05:00
2010-09-30 12:27:22 -05:00
- ( void ) setSetupOnly : ( BOOL ) isSetupOnly {
setupOnly = isSetupOnly ;
if ( setupOnly )
step = 2 ;
else
step = 1 ;
}
2010-09-25 07:34:32 -05:00
- ( void ) setStep : ( int ) theStep {
step = theStep ;
}
- ( void ) displayStep {
if ( displaying ) {
needsDisplay = YES ;
return ;
}
switch ( step ) {
case 1 :
nextView = S1View ;
[ titleField setText : @ "Welcome to VoiceMob" ] ;
[ backButton setTitle : MGMSGoBack ] ;
[ backButton setEnabled : NO ] ;
[ continueButton setTitle : MGMSContinue ] ;
[ continueButton setEnabled : YES ] ;
break ;
case 2 :
nextView = S2View ;
[ titleField setText : @ "Account Setup" ] ;
2010-09-30 12:27:22 -05:00
if ( setupOnly )
[ backButton setTitle : MGMSCancel ] ;
else
[ backButton setTitle : MGMSGoBack ] ;
2010-09-25 07:34:32 -05:00
[ backButton setEnabled : YES ] ;
[ continueButton setTitle : MGMSContinue ] ;
[ continueButton setEnabled : YES ] ;
break ;
case 3 :
nextView = S3View ;
[ titleField setText : @ "Google Voice Privacy Policy" ] ;
[ backButton setTitle : MGMSDisagree ] ;
[ backButton setEnabled : YES ] ;
[ continueButton setTitle : MGMSAgree ] ;
[ continueButton setEnabled : YES ] ;
[ S3Browser loadRequest : [ NSURLRequest requestWithURL : [ NSURL URLWithString : @ "http://www.google.com/googlevoice/legal-notices.html" ] ] ] ;
break ;
case 4 :
case 5 :
case 6 : {
if ( step = = 4 )
nextView = S4View ;
else if ( step = = 5 )
nextView = S5View ;
else if ( step = = 6 )
nextView = S6View ;
NSString * type = nil ;
if ( accountType = = 0 )
type = MGMSGoogleVoice ;
else if ( accountType = = 1 )
type = MGMSGoogleContacts ;
else if ( accountType = = 2 )
type = MGMSSIP ;
[ titleField setText : [ NSString stringWithFormat : @ "Set Up %@" , type ] ] ;
[ backButton setTitle : MGMSGoBack ] ;
[ backButton setEnabled : YES ] ;
[ continueButton setTitle : MGMSContinue ] ;
[ continueButton setEnabled : YES ] ;
break ;
}
case 7 :
nextView = S7View ;
[ titleField setText : @ "Checking Credentials" ] ;
[ backButton setTitle : MGMSGoBack ] ;
[ backButton setEnabled : NO ] ;
[ continueButton setTitle : MGMSContinue ] ;
[ continueButton setEnabled : NO ] ;
[ S7StatusField setText : MGMS7Crediential ] ;
if ( accountType = = 0 )
[ self S7CheckGoogleVoice ] ;
else if ( accountType = = 1 )
[ self S7CheckGoogleContacts ] ;
else if ( accountType = = 2 )
[ self S7CheckSIP ] ;
[ S7Progress startAnimating ] ;
break ;
case 8 : {
nextView = S8View ;
[ S7Progress stopAnimating ] ;
NSString * type = nil ;
if ( accountType = = 0 )
type = MGMSGoogleVoice ;
else if ( accountType = = 1 )
type = MGMSGoogleContacts ;
else if ( accountType = = 2 )
type = MGMSSIP ;
[ titleField setText : @ "Credentials Error" ] ;
[ backButton setTitle : MGMSGoBack ] ;
[ backButton setEnabled : YES ] ;
[ continueButton setTitle : MGMSContinue ] ;
[ continueButton setEnabled : NO ] ;
2013-07-20 06:56:17 -05:00
< < < < < < < HEAD
[ S8MessageField setText : [ NSString stringWithFormat : @ "Unable to set up your %@ account, the error we receviced was \" % @ \ " Please go back and correct the problem." , type , S8Message ] ] ;
[ S8Message release ] ;
S8Message = nil ;
=== === =
2012-09-05 16:24:46 -05:00
[ S8MessageField setText : [ NSString stringWithFormat : @ "Unable to set up your %@ account, the error we received was \" % @ \ " Please go back and correct the problem." , type , S8Message ] ] ;
2010-09-25 07:34:32 -05:00
if ( S8Message ! = nil ) {
[ S8Message release ] ;
S8Message = nil ;
}
2013-07-20 06:56:17 -05:00
> > > > > > > 13 b6d2ac024f36826fdb6cd6dcb05710e133e842
2010-09-25 07:34:32 -05:00
break ;
}
case 9 : {
nextView = S9View ;
[ titleField setText : @ "Setup Successful" ] ;
NSString * type = nil ;
if ( accountType = = 0 )
type = MGMSGoogleVoice ;
else if ( accountType = = 1 )
type = MGMSGoogleContacts ;
else if ( accountType = = 2 )
type = MGMSSIP ;
[ S7Progress stopAnimating ] ;
[ backButton setTitle : MGMSGoBack ] ;
[ backButton setEnabled : NO ] ;
[ continueButton setTitle : MGMSDone ] ;
[ continueButton setEnabled : YES ] ;
[ S9MessageField setText : [ NSString stringWithFormat : @ "You have sucessfully set up your %@ account. You may continue to the Application or add another account by pressing \" Add Another Account \ ". If you are confused about VoiceMob, please read the documentation which explains all you can do with it." , type ] ] ;
break ;
}
}
if ( lastView = = nil ) {
[ view addSubview : nextView ] ;
lastView = nextView ;
} else if ( lastView ! = nextView ) {
backEnabled = [ backButton isEnabled ] ;
[ backButton setEnabled : NO ] ;
continueEnabled = [ continueButton isEnabled ] ;
[ continueButton setEnabled : NO ] ;
displaying = YES ;
if ( goingBack ) {
2013-07-20 06:56:17 -05:00
CGRect outViewFrame = [ lastView frame ] ;
2010-09-25 07:34:32 -05:00
CGRect inViewFrame = [ nextView frame ] ;
2013-07-20 06:56:17 -05:00
inViewFrame . size = outViewFrame . size ;
2010-10-02 22:00:01 -05:00
inViewFrame . origin . x = - inViewFrame . size . width ;
2010-09-25 07:34:32 -05:00
[ nextView setFrame : inViewFrame ] ;
[ view addSubview : nextView ] ;
2010-09-30 12:27:22 -05:00
[ UIView beginAnimations : nil context : nil ] ;
2010-09-25 07:34:32 -05:00
[ UIView setAnimationDuration : 0.5 ] ;
[ UIView setAnimationCurve : UIViewAnimationCurveEaseInOut ] ;
[ UIView setAnimationDelegate : self ] ;
[ UIView setAnimationDidStopSelector : @ selector ( displayAnimationDidStop : finished : context : ) ] ;
2013-07-20 06:56:17 -05:00
[ nextView setFrame : outViewFrame ] ;
2010-10-02 22:00:01 -05:00
outViewFrame . origin . x = + outViewFrame . size . width ;
2010-09-25 07:34:32 -05:00
[ lastView setFrame : outViewFrame ] ;
[ UIView commitAnimations ] ;
} else {
2013-07-20 06:56:17 -05:00
CGRect outViewFrame = [ lastView frame ] ;
2010-09-25 07:34:32 -05:00
CGRect inViewFrame = [ nextView frame ] ;
2013-07-20 06:56:17 -05:00
inViewFrame . size = outViewFrame . size ;
2010-10-02 22:00:01 -05:00
inViewFrame . origin . x = + inViewFrame . size . width ;
2010-09-25 07:34:32 -05:00
[ nextView setFrame : inViewFrame ] ;
[ view addSubview : nextView ] ;
[ UIView beginAnimations : nil context : nil ] ;
[ UIView setAnimationDuration : 0.5 ] ;
[ UIView setAnimationCurve : UIViewAnimationCurveEaseInOut ] ;
[ UIView setAnimationDelegate : self ] ;
[ UIView setAnimationDidStopSelector : @ selector ( displayAnimationDidStop : finished : context : ) ] ;
2013-07-20 06:56:17 -05:00
[ nextView setFrame : outViewFrame ] ;
2010-10-02 22:00:01 -05:00
outViewFrame . origin . x = - outViewFrame . size . width ;
2010-09-25 07:34:32 -05:00
[ lastView setFrame : outViewFrame ] ;
[ UIView commitAnimations ] ;
}
}
}
- ( void ) displayAnimationDidStop : ( NSString * ) animationID finished : ( NSNumber * ) finished context : ( void * ) context {
[ backButton setEnabled : backEnabled ] ;
[ continueButton setEnabled : continueEnabled ] ;
[ lastView removeFromSuperview ] ;
lastView = nextView ;
nextView = nil ;
displaying = NO ;
if ( needsDisplay ) {
needsDisplay = NO ;
[ self displayStep ] ;
}
}
- ( IBAction ) back : ( id ) sender {
switch ( step ) {
case 2 :
2010-09-30 12:27:22 -05:00
if ( setupOnly ) {
[ accountsCreated makeObjectsPerformSelector : @ selector ( start ) ] ;
[ controller dismissAccountSetup : self ] ;
return ;
}
2010-09-25 07:34:32 -05:00
step - - ;
break ;
case 4 :
step = 3 ;
break ;
case 3 :
case 5 :
case 6 :
if ( accountType = = 0 )
[ self S4Reset ] ;
else if ( accountType = = 1 )
[ self S5Reset ] ;
else if ( accountType = = 2 )
[ self S6Reset ] ;
step = 2 ;
break ;
case 8 :
if ( accountType = = 0 )
step = 4 ;
else if ( accountType = = 1 )
step = 5 ;
else if ( accountType = = 2 )
step = 6 ;
break ;
default :
step - - ;
break ;
}
goingBack = YES ;
[ self displayStep ] ;
}
- ( IBAction ) continue : ( id ) sender {
switch ( step ) {
case 2 :
switch ( accountType ) {
case 1 :
step = 5 ;
break ;
case 2 : {
# if MGMSIPENABLED
step = 6 ;
# else
2013-07-20 06:56:17 -05:00
UIAlertView * alert = [ [ UIAlertView new ] autorelease ] ;
[ alert setTitle : @ "Unable to Add Account" ] ;
[ alert setMessage : @ "MGMSIP is not compiled with VoiceMob, you can not add a SIP account without first compiling with MGMSIP." ] ;
[ alert addButtonWithTitle : MGMOkButtonTitle ] ;
[ alert show ] ;
2010-09-25 07:34:32 -05:00
return ;
# endif
break ;
}
default :
step + + ;
break ;
}
break ;
case 4 :
case 5 :
case 6 : {
BOOL emptyFields = NO ;
if ( accountType = = 0 ) {
if ( [ [ S4EmailField text ] isEqual : @ "" ] || [ [ S4PasswordField text ] isEqual : @ "" ] )
emptyFields = YES ;
} else if ( accountType = = 1 ) {
if ( [ [ S5EmailField text ] isEqual : @ "" ] || [ [ S5PasswordField text ] isEqual : @ "" ] )
emptyFields = YES ;
} else if ( accountType = = 2 ) {
if ( [ [ S6UserNameField text ] isEqual : @ "" ] || [ [ S6PasswordField text ] isEqual : @ "" ] )
emptyFields = YES ;
}
if ( emptyFields ) {
2013-07-20 06:56:17 -05:00
UIAlertView * alert = [ [ UIAlertView new ] autorelease ] ;
[ alert setTitle : @ "Missing Information" ] ;
[ alert setMessage : @ "It appears as if you did not fill the required fields, please fill out the required fields and then continue." ] ;
[ alert addButtonWithTitle : MGMOkButtonTitle ] ;
[ alert show ] ;
2010-09-25 07:34:32 -05:00
return ;
}
step = 7 ;
break ;
}
case 9 :
[ accountsCreated makeObjectsPerformSelector : @ selector ( start ) ] ;
2010-09-30 12:27:22 -05:00
[ controller dismissAccountSetup : self ] ;
2010-09-25 07:34:32 -05:00
return ;
default :
step + + ;
break ;
}
goingBack = NO ;
[ self displayStep ] ;
}
// Step 2
- ( IBAction ) S2SelectType : ( id ) sender {
[ S2GVButton setImage : [ UIImage imageNamed : MGMRadioButton ] forState : UIControlStateNormal ] ;
[ S2GCButton setImage : [ UIImage imageNamed : MGMRadioButton ] forState : UIControlStateNormal ] ;
[ S2SIPButton setImage : [ UIImage imageNamed : MGMRadioButton ] forState : UIControlStateNormal ] ;
accountType = [ sender tag ] -1 ;
if ( accountType = = 0 )
[ S2GVButton setImage : [ UIImage imageNamed : MGMRadioSelectedButton ] forState : UIControlStateNormal ] ;
else if ( accountType = = 1 )
[ S2GCButton setImage : [ UIImage imageNamed : MGMRadioSelectedButton ] forState : UIControlStateNormal ] ;
else if ( accountType = = 2 )
[ S2SIPButton setImage : [ UIImage imageNamed : MGMRadioSelectedButton ] forState : UIControlStateNormal ] ;
}
// Step 4
- ( void ) S4Reset {
[ S4EmailField setText : @ "" ] ;
[ S4PasswordField setText : @ "" ] ;
}
// Step 5
- ( void ) S5Reset {
[ S5EmailField setText : @ "" ] ;
[ S5PasswordField setText : @ "" ] ;
}
// Step 6
- ( IBAction ) S6UserNameChanged : ( id ) sender {
[ S6FullNameField setPlaceholder : [ S6UserNameField text ] ] ;
}
- ( IBAction ) S6DomainChanged : ( id ) sender {
if ( [ [ S6DomainField text ] isEqual : @ "" ] )
[ S6RegistrarField setPlaceholder : MGMSIPDefaultDomain ] ;
else
[ S6RegistrarField setPlaceholder : [ S6DomainField text ] ] ;
}
- ( void ) S6Reset {
[ S6FullNameField setText : @ "" ] ;
[ S6FullNameField setPlaceholder : @ "UserName" ] ;
[ S6DomainField setText : @ "" ] ;
[ S6RegistrarField setText : @ "" ] ;
[ S6UserNameField setText : @ "" ] ;
[ S6PasswordField setText : @ "" ] ;
}
// Step 7
- ( void ) S7CheckGoogleVoice {
S7CheckUser = [ [ MGMUser createUserWithName : [ S4EmailField text ] password : [ S4PasswordField text ] ] retain ] ;
[ S7CheckUser setSetting : MGMSGoogleVoice forKey : MGMSAccountType ] ;
S7CheckInstance = [ [ MGMInstance instanceWithUser : S7CheckUser delegate : self isCheck : YES ] retain ] ;
}
- ( void ) loginError : ( NSError * ) theError {
2013-07-20 06:56:17 -05:00
[ S7VerificationView release ] ;
S7VerificationView = nil ;
[ S7VerificationField release ] ;
S7VerificationField = nil ;
[ S7CheckUser remove ] ;
[ S7CheckUser release ] ;
S7CheckUser = nil ;
[ S7CheckInstance release ] ;
S7CheckInstance = nil ;
2010-09-25 07:34:32 -05:00
NSLog ( @ "Login Failed %@" , theError ) ;
S8Message = [ [ theError localizedDescription ] copy ] ;
step = 8 ;
[ self displayStep ] ;
}
2013-07-20 06:56:17 -05:00
- ( void ) loginVerificationRequested {
[ S7VerificationView release ] ;
S7VerificationView = [ UIAlertView new ] ;
[ S7VerificationView setTitle : @ "Account Verification" ] ;
[ S7VerificationView setMessage : @ " " ] ;
[ S7VerificationView addButtonWithTitle : @ "Cancel" ] ;
[ S7VerificationView addButtonWithTitle : @ "Verify" ] ;
[ S7VerificationView setCancelButtonIndex : 1 ] ;
[ S7VerificationView setDelegate : self ] ;
[ S7VerificationField release ] ;
S7VerificationField = [ [ UITextField alloc ] initWithFrame : CGRectMake ( 12.0 , 45.0 , 260.0 , 25.0 ) ] ;
[ S7VerificationField setBorderStyle : UITextBorderStyleLine ] ;
[ S7VerificationField setBackgroundColor : [ UIColor whiteColor ] ] ;
[ S7VerificationField setKeyboardType : UIKeyboardTypeNumbersAndPunctuation ] ;
[ S7VerificationView addSubview : S7VerificationField ] ;
[ S7VerificationView show ] ;
[ S7VerificationField becomeFirstResponder ] ;
}
- ( void ) alertView : ( UIAlertView * ) theAlertView clickedButtonAtIndex : ( NSInteger ) theIndex {
if ( theAlertView = = S7VerificationView ) {
if ( theIndex = = 1 )
[ S7CheckInstance verifyWithCode : [ S7VerificationField text ] ] ;
else
[ S7CheckInstance cancelVerification ] ;
}
}
2010-09-25 07:34:32 -05:00
- ( void ) loginSuccessful {
2013-07-20 06:56:17 -05:00
[ S7VerificationView release ] ;
S7VerificationView = nil ;
[ S7VerificationField release ] ;
S7VerificationField = nil ;
2010-09-25 07:34:32 -05:00
if ( S7CheckUser ! = nil ) {
[ accountsCreated addObject : S7CheckUser ] ;
MGMUser * contactsUser = [ MGMUser createUserWithName : [ S4EmailField text ] password : [ S4PasswordField text ] ] ;
[ contactsUser setSetting : MGMSGoogleContacts forKey : MGMSAccountType ] ;
[ S7CheckUser setSetting : [ contactsUser settingForKey : MGMUserID ] forKey : MGMCGoogleContactsUser ] ;
[ S7CheckUser release ] ;
S7CheckUser = nil ;
}
2013-07-20 06:56:17 -05:00
[ S7CheckInstance release ] ;
S7CheckInstance = nil ;
2010-09-25 07:34:32 -05:00
[ self S4Reset ] ;
step = 9 ;
[ self displayStep ] ;
}
- ( void ) S7CheckGoogleContacts {
S7CheckUser = [ [ MGMUser createUserWithName : [ S5EmailField text ] password : [ S5PasswordField text ] ] retain ] ;
[ S7CheckUser setSetting : MGMSGoogleContacts forKey : MGMSAccountType ] ;
NSString * username = [ S7CheckUser settingForKey : MGMUserName ] ;
if ( ! [ username containsString : @ "@" ] )
username = [ username stringByAppendingString : @ "@gmail.com" ] ;
NSURLCredential * credentials = [ NSURLCredential credentialWithUser : username password : [ S7CheckUser password ] persistence : NSURLCredentialPersistenceForSession ] ;
[ S7ConnectionManager setCookieStorage : [ S7CheckUser cookieStorage ] ] ;
[ S7ConnectionManager setCredentials : credentials ] ;
2013-07-20 06:56:17 -05:00
[ S7ConnectionManager setUserAgent : MGMGCUseragent ] ;
2010-09-25 07:34:32 -05:00
NSMutableURLRequest * request = [ NSMutableURLRequest requestWithURL : [ NSURL URLWithString : MGMGCAuthenticationURL ] cachePolicy : NSURLRequestReloadIgnoringCacheData timeoutInterval : 15.0 ] ;
[ request setHTTPMethod : MGMPostMethod ] ;
[ request setValue : MGMURLForm forHTTPHeaderField : MGMContentType ] ;
[ request setHTTPBody : [ [ NSString stringWithFormat : MGMGCAuthenticationBody , [ username addPercentEscapes ] , [ [ S7CheckUser password ] addPercentEscapes ] ] dataUsingEncoding : NSUTF8StringEncoding ] ] ;
2013-07-20 06:56:17 -05:00
MGMURLBasicHandler * handler = [ MGMURLBasicHandler handlerWithRequest : request delegate : self ] ;
[ handler setFailWithError : @ selector ( authentication : didFailWithError : ) ] ;
[ handler setFinish : @ selector ( authenticationDidFinish : ) ] ;
[ S7ConnectionManager addHandler : handler ] ;
}
- ( void ) authentication : ( MGMURLBasicHandler * ) theHandler didFailWithError : ( NSError * ) theError {
[ S7CheckUser remove ] ;
[ S7CheckUser release ] ;
S7CheckUser = nil ;
[ S7ConnectionManager setCookieStorage : nil ] ;
2010-09-25 07:34:32 -05:00
NSLog ( @ "Login Failed %@" , theError ) ;
S8Message = [ [ theError localizedDescription ] copy ] ;
step = 8 ;
[ self displayStep ] ;
}
2013-07-20 06:56:17 -05:00
- ( void ) authenticationDidFinish : ( MGMURLBasicHandler * ) theHandler {
NSDictionary * info = [ MGMGoogleContacts dictionaryWithString : [ theHandler string ] ] ;
[ S7ConnectionManager setCookieStorage : nil ] ;
if ( [ info objectForKey : @ "Error" ] ! = nil ) {
[ S7CheckUser remove ] ;
2010-09-25 07:34:32 -05:00
[ S7CheckUser release ] ;
S7CheckUser = nil ;
2013-07-20 06:56:17 -05:00
S8Message = [ @ "Unable to login. Please check your Credentials." retain ] ;
step = 8 ;
[ self displayStep ] ;
return ;
2010-09-25 07:34:32 -05:00
}
2013-07-20 06:56:17 -05:00
[ S7CheckUser done ] ;
[ S7CheckUser release ] ;
S7CheckUser = nil ;
2010-09-25 07:34:32 -05:00
[ self S5Reset ] ;
step = 9 ;
[ self displayStep ] ;
}
- ( void ) S7CheckSIP {
# if MGMSIPENABLED
if ( ! [ [ MGMSIP sharedSIP ] isStarted ] ) [ [ MGMSIP sharedSIP ] start ] ;
S7CheckUser = [ [ MGMUser createUserWithName : [ S6UserNameField text ] password : [ S6PasswordField text ] ] retain ] ;
[ S7CheckUser setSetting : MGMSSIP forKey : MGMSAccountType ] ;
NSString * fullName = [ S6FullNameField text ] ;
if ( [ fullName isEqual : @ "" ] )
fullName = [ S6UserNameField text ] ;
[ S7CheckUser setSetting : fullName forKey : MGMSIPAccountFullName ] ;
[ S7CheckUser setSetting : [ S6UserNameField text ] forKey : MGMSIPAccountUserName ] ;
if ( [ [ S6UserNameField text ] isPhone ] )
[ S7CheckUser setSetting : [ [ S6UserNameField text ] areaCode ] forKey : MGMSIPUserAreaCode ] ;
if ( [ [ S6DomainField text ] isEqual : @ "" ] )
[ S7CheckUser setSetting : MGMSIPDefaultDomain forKey : MGMSIPAccountDomain ] ;
else
[ S7CheckUser setSetting : [ S6DomainField text ] forKey : MGMSIPAccountDomain ] ;
if ( ! [ [ S6RegistrarField text ] isEqual : @ "" ] )
[ S7CheckUser setSetting : [ S6RegistrarField text ] forKey : MGMSIPAccountRegistrar ] ;
S7CheckSIPAccount = [ [ MGMSIPAccount alloc ] initWithSettings : [ S7CheckUser settings ] ] ;
2013-07-20 06:56:17 -05:00
[ S7CheckUser registerSettings : [ S7CheckSIPAccount settings ] ] ;
2010-09-25 07:34:32 -05:00
[ S7CheckSIPAccount setDelegate : self ] ;
S7AccountRegistered = NO ;
NSLog ( @ "Logging in" ) ;
[ NSThread detachNewThreadSelector : @ selector ( login ) toTarget : S7CheckSIPAccount withObject : nil ] ;
# endif
}
- ( NSString * ) password {
return [ S7CheckUser password ] ;
}
- ( void ) registrationChanged {
2013-07-20 06:56:17 -05:00
[ self performSelector : @ selector ( S7RegistrationChanged ) withObject : nil afterDelay : 0.5 ] ;
}
- ( void ) S7RegistrationChanged {
2010-09-25 07:34:32 -05:00
# if MGMSIPENABLED
2013-07-20 06:56:17 -05:00
[ S7SIPRegistrationTimeout invalidate ] ;
[ S7SIPRegistrationTimeout release ] ;
S7SIPRegistrationTimeout = nil ;
if ( ! [ S7CheckSIPAccount isRegistered ] ) {
[ S7CheckSIPAccount setLastError : @ "Unable to Register with Server. Please check your credentials." ] ;
[ self loginErrored ] ;
return ;
2010-09-25 07:34:32 -05:00
}
2013-07-20 06:56:17 -05:00
[ S7CheckSIPAccount setDelegate : nil ] ;
[ S7CheckSIPAccount logout ] ;
[ S7CheckSIPAccount release ] ;
S7CheckSIPAccount = nil ;
2010-09-25 07:34:32 -05:00
if ( S7CheckUser ! = nil ) {
[ accountsCreated addObject : S7CheckUser ] ;
[ S7CheckUser release ] ;
S7CheckUser = nil ;
}
[ self S6Reset ] ;
S7AccountRegistered = YES ;
step = 9 ;
2013-07-20 06:56:17 -05:00
[ self displayStep ] ;
2010-09-25 07:34:32 -05:00
# endif
}
# if MGMSIPENABLED
- ( void ) S7SIPTimeout {
2013-07-20 06:56:17 -05:00
[ S7SIPRegistrationTimeout invalidate ] ;
[ S7SIPRegistrationTimeout release ] ;
S7SIPRegistrationTimeout = nil ;
2010-09-25 07:34:32 -05:00
[ S7CheckSIPAccount setLastError : @ "Registration Timeout." ] ;
[ self loginErrored ] ;
}
- ( void ) loggedIn {
[ S7StatusField setText : MGMS7SIPWaiting ] ;
[ self performSelectorOnMainThread : @ selector ( S7StartRegistrationTimeoutTimer ) withObject : nil waitUntilDone : NO ] ;
}
- ( void ) S7StartRegistrationTimeoutTimer {
if ( ! S7AccountRegistered )
S7SIPRegistrationTimeout = [ [ NSTimer scheduledTimerWithTimeInterval : 10.0 target : self selector : @ selector ( S7SIPTimeout ) userInfo : nil repeats : NO ] retain ] ;
}
- ( void ) loginErrored {
2013-07-20 06:56:17 -05:00
[ S7CheckUser remove ] ;
[ S7CheckUser release ] ;
S7CheckUser = nil ;
NSLog ( @ "Login Failed %@" , [ S7CheckSIPAccount lastError ] ) ;
S8Message = [ [ S7CheckSIPAccount lastError ] copy ] ;
[ S7CheckSIPAccount setDelegate : nil ] ;
[ S7CheckSIPAccount logout ] ;
[ S7CheckSIPAccount release ] ;
S7CheckSIPAccount = nil ;
2010-09-25 07:34:32 -05:00
step = 8 ;
[ self performSelectorOnMainThread : @ selector ( displayStep ) withObject : nil waitUntilDone : NO ] ;
}
# endif
// Step 9
- ( IBAction ) S9AddAnotherAccount : ( id ) sender {
goingBack = YES ;
2010-09-30 12:27:22 -05:00
[ self setSetupOnly : YES ] ;
2010-09-25 07:34:32 -05:00
[ self displayStep ] ;
}
2012-09-05 16:24:46 -05:00
@ end