@ -1,9 +1,5 @@
/ /
/ /
/ / CodeVerificationViewController . m
/ / Copyright ( c ) 2017 Open Whisper Systems . All rights reserved .
/ / Signal
/ /
/ / Created by Dylan Bourgeois on 13 / 11 / 14.
/ / Copyright ( c ) 2014 Open Whisper Systems . All rights reserved .
/ /
/ /
#import "CodeVerificationViewController . h "
#import "CodeVerificationViewController . h "
@ -21,12 +17,28 @@ NS_ASSUME_NONNULL_BEGIN
NSString * const kCompletedRegistrationSegue = @ "CompletedRegistration ";
NSString * const kCompletedRegistrationSegue = @ "CompletedRegistration ";
@ interface CodeVerificationViewController ( )
@ interface CodeVerificationViewController ( ) < UITextFieldDelegate >
@ property ( nonatomic , readonly ) AccountManager * accountManager ;
/ / Where the user enters the verification code they wish to document
@ property ( nonatomic ) UITextField * challengeTextField ;
@ property ( nonatomic ) UILabel * phoneNumberLabel ;
@ property ( nonatomic , strong , readonly ) AccountManager * accountManager ;
/ / / / User action buttons
@ property ( nonatomic ) UIButton * challengeButton ;
@ property ( nonatomic ) UIButton * sendCodeViaSMSAgainButton ;
@ property ( nonatomic ) UIButton * sendCodeViaVoiceButton ;
@ property ( nonatomic ) UIActivityIndicatorView * submitCodeSpinner ;
@ property ( nonatomic ) UIActivityIndicatorView * requestCodeAgainSpinner ;
@ property ( nonatomic ) UIActivityIndicatorView * requestCallSpinner ;
@ end
@ end
#pragma mark -
@ implementation CodeVerificationViewController
@ implementation CodeVerificationViewController
- ( nullable instancetype ) initWithCoder : ( NSCoder * ) aDecoder
- ( nullable instancetype ) initWithCoder : ( NSCoder * ) aDecoder
@ -55,30 +67,165 @@ NSString *const kCompletedRegistrationSegue = @"CompletedRegistration";
- ( void ) viewDidLoad {
- ( void ) viewDidLoad {
[ super viewDidLoad ] ;
[ super viewDidLoad ] ;
[ self createViews ] ;
[ self initializeKeyboardHandlers ] ;
[ self initializeKeyboardHandlers ] ;
_headerLabel . text = NSLocalizedString ( @ "VERIFICATION_HEADER ", @ "Navigation title in the registration flow - during the sms code verification process . ") ;
}
- ( void ) createViews {
self . view . backgroundColor = [ UIColor whiteColor ] ;
self . view . opaque = YES ;
/ / TODO : Move this to UIColor + OWS ?
UIColor * signalBlueColor = [ UIColor colorWithRed : 0.1135657504
green : 0.4787300229
blue : 0.89595204589999999
alpha : 1. ] ;
UIView * header = [ UIView new ] ;
header . backgroundColor = signalBlueColor ;
[ self . view addSubview : header ] ;
[ header autoPinWidthToSuperview ] ;
[ header autoPinEdgeToSuperviewEdge : ALEdgeTop ] ;
[ header autoSetDimension : ALDimensionHeight toSize : ScaleFromIPhone5To7Plus ( 60 , 60 ) ] ;
UILabel * titleLabel = [ UILabel new ] ;
titleLabel . textColor = [ UIColor whiteColor ] ;
titleLabel . text = NSLocalizedString ( @ "VERIFICATION_HEADER ", @ "Navigation title in the registration flow - during the sms code verification process . ") ;
titleLabel . font = [ UIFont ows_mediumFontWithSize : 20. f ] ;
[ header addSubview : titleLabel ] ;
[ titleLabel autoPinToTopLayoutGuideOfViewController : self withInset : 0 ] ;
[ titleLabel autoPinEdgeToSuperviewEdge : ALEdgeBottom ] ;
[ titleLabel autoHCenterInSuperview ] ;
UIButton * backButton = [ UIButton buttonWithType : UIButtonTypeCustom ] ;
[ backButton setTitle : NSLocalizedString ( @ "VERIFICATION_BACK_BUTTON ", @ "button text for back button on verification view ")
forState : UIControlStateNormal ] ;
[ backButton setTitleColor : [ UIColor whiteColor ]
forState : UIControlStateNormal ] ;
backButton . titleLabel . font = [ UIFont ows_mediumFontWithSize : 14. f ] ;
[ header addSubview : backButton ] ;
[ backButton autoPinEdgeToSuperviewEdge : ALEdgeLeft withInset : ScaleFromIPhone5To7Plus ( 10 , 10 ) ] ;
[ backButton autoAlignAxis : ALAxisHorizontal toSameAxisOfView : titleLabel ] ;
[ backButton addTarget : self action : @ selector ( backButtonPressed : ) forControlEvents : UIControlEventTouchUpInside ] ;
_phoneNumberLabel = [ UILabel new ] ;
_phoneNumberLabel . textColor = [ UIColor ows_darkGrayColor ] ;
_phoneNumberLabel . font = [ UIFont ows_regularFontWithSize : 20. f ] ;
[ self . view addSubview : _phoneNumberLabel ] ;
[ _phoneNumberLabel autoHCenterInSuperview ] ;
[ _phoneNumberLabel autoPinEdge : ALEdgeTop toEdge : ALEdgeBottom ofView : header
withOffset : ScaleFromIPhone5To7Plus ( 25 , 100 ) ] ;
_challengeTextField = [ UITextField new ] ;
_challengeTextField . textColor = [ UIColor blackColor ] ;
_challengeTextField . placeholder = NSLocalizedString ( @ "VERIFICATION_CHALLENGE_DEFAULT_TEXT ",
_challengeTextField . placeholder = NSLocalizedString ( @ "VERIFICATION_CHALLENGE_DEFAULT_TEXT ",
@ "Text field placeholder for SMS verification code during registration ") ;
@ "Text field placeholder for SMS verification code during registration ") ;
_challengeTextField . font = [ UIFont ows_lightFontWithSize : 21. f ] ;
_challengeTextField . textAlignment = NSTextAlignmentCenter ;
_challengeTextField . delegate = self ;
_challengeTextField . delegate = self ;
[ self . view addSubview : _challengeTextField ] ;
[ _challengeTextField autoPinWidthToSuperviewWithMargin : ScaleFromIPhone5To7Plus ( 36 , 36 ) ] ;
[ _challengeTextField autoPinEdge : ALEdgeTop toEdge : ALEdgeBottom ofView : _phoneNumberLabel
withOffset : ScaleFromIPhone5To7Plus ( 25 , 25 ) ] ;
UIView * underscoreView = [ UIView new ] ;
underscoreView . backgroundColor = [ UIColor colorWithWhite : 0.5 alpha : 1. f ] ;
[ self . view addSubview : underscoreView ] ;
[ underscoreView autoPinEdge : ALEdgeTop toEdge : ALEdgeBottom ofView : _challengeTextField
withOffset : ScaleFromIPhone5To7Plus ( 3 , 3 ) ] ;
[ underscoreView autoPinWidthToSuperviewWithMargin : ScaleFromIPhone5To7Plus ( 36 , 36 ) ] ;
[ underscoreView autoSetDimension : ALDimensionHeight toSize : 1. f ] ;
_challengeButton = [ UIButton buttonWithType : UIButtonTypeCustom ] ;
_challengeButton . backgroundColor = signalBlueColor ;
[ _challengeButton setTitle : NSLocalizedString ( @ "VERIFICATION_CHALLENGE_SUBMIT_CODE ", @ "button text during registration to submit your SMS verification code ")
[ _challengeButton setTitle : NSLocalizedString ( @ "VERIFICATION_CHALLENGE_SUBMIT_CODE ", @ "button text during registration to submit your SMS verification code ")
forState : UIControlStateNormal ] ;
forState : UIControlStateNormal ] ;
[ _challengeButton setTitleColor : [ UIColor whiteColor ]
forState : UIControlStateNormal ] ;
_challengeButton . titleLabel . font = [ UIFont ows_mediumFontWithSize : 14. f ] ;
[ _challengeButton addTarget : self
action : @ selector ( verifyChallengeAction : )
forControlEvents : UIControlEventTouchUpInside ] ;
[ self . view addSubview : _challengeButton ] ;
[ _challengeButton autoPinEdge : ALEdgeTop toEdge : ALEdgeBottom ofView : underscoreView
withOffset : ScaleFromIPhone5To7Plus ( 15 , 15 ) ] ;
[ _challengeButton autoPinWidthToSuperviewWithMargin : ScaleFromIPhone5To7Plus ( 36 , 36 ) ] ;
[ _challengeButton autoSetDimension : ALDimensionHeight toSize : 47. f ] ;
_submitCodeSpinner = [ [ UIActivityIndicatorView alloc ] initWithActivityIndicatorStyle : UIActivityIndicatorViewStyleWhite ] ;
[ _challengeButton addSubview : _submitCodeSpinner ] ;
[ _submitCodeSpinner autoSetDimension : ALDimensionWidth toSize : ScaleFromIPhone5To7Plus ( 20 , 20 ) ] ;
[ _submitCodeSpinner autoSetDimension : ALDimensionHeight toSize : ScaleFromIPhone5To7Plus ( 20 , 20 ) ] ;
[ _submitCodeSpinner autoVCenterInSuperview ] ;
[ _submitCodeSpinner autoPinEdgeToSuperviewEdge : ALEdgeRight withInset : ScaleFromIPhone5To7Plus ( 15 , 15 ) ] ;
_sendCodeViaSMSAgainButton = [ UIButton buttonWithType : UIButtonTypeCustom ] ;
_sendCodeViaSMSAgainButton . backgroundColor = [ UIColor whiteColor ] ;
[ _sendCodeViaSMSAgainButton setTitle : NSLocalizedString ( @ "VERIFICATION_CHALLENGE_SUBMIT_AGAIN ", @ "button text during registration to request another SMS code be sent ")
[ _sendCodeViaSMSAgainButton setTitle : NSLocalizedString ( @ "VERIFICATION_CHALLENGE_SUBMIT_AGAIN ", @ "button text during registration to request another SMS code be sent ")
forState : UIControlStateNormal ] ;
forState : UIControlStateNormal ] ;
[ _sendCodeViaVoiceButton
[ _sendCodeViaSMSAgainButton setTitleColor : signalBlueColor
setTitle : [ @ " " stringByAppendingString : NSLocalizedString ( @ "VERIFICATION_CHALLENGE_SEND_VIAVOICE ", @ "button text during registration to request phone number verification be done via phone call ") ]
forState : UIControlStateNormal ] ;
forState : UIControlStateNormal ] ;
[ _changeNumberButton
_sendCodeViaSMSAgainButton . titleLabel . font = [ UIFont ows_mediumFontWithSize : 14. f ] ;
setTitle : [ @ " " stringByAppendingString : NSLocalizedString ( @ "VERIFICATION_CHALLENGE_CHANGE_NUMBER ", @ "button text during registration to make corrections to your submitted phone number ") ]
[ _sendCodeViaSMSAgainButton addTarget : self
action : @ selector ( sendCodeViaSMSAction : )
forControlEvents : UIControlEventTouchUpInside ] ;
[ self . view addSubview : _sendCodeViaSMSAgainButton ] ;
[ _sendCodeViaSMSAgainButton autoPinEdge : ALEdgeTop toEdge : ALEdgeBottom ofView : _challengeButton
withOffset : ScaleFromIPhone5To7Plus ( 10 , 10 ) ] ;
[ _sendCodeViaSMSAgainButton autoPinWidthToSuperviewWithMargin : ScaleFromIPhone5To7Plus ( 36 , 36 ) ] ;
[ _sendCodeViaSMSAgainButton autoSetDimension : ALDimensionHeight toSize : 35 ] ;
_requestCodeAgainSpinner = [ [ UIActivityIndicatorView alloc ] initWithActivityIndicatorStyle : UIActivityIndicatorViewStyleGray ] ;
[ _sendCodeViaSMSAgainButton addSubview : _requestCodeAgainSpinner ] ;
[ _requestCodeAgainSpinner autoSetDimension : ALDimensionWidth toSize : ScaleFromIPhone5To7Plus ( 20 , 20 ) ] ;
[ _requestCodeAgainSpinner autoSetDimension : ALDimensionHeight toSize : ScaleFromIPhone5To7Plus ( 20 , 20 ) ] ;
[ _requestCodeAgainSpinner autoVCenterInSuperview ] ;
[ _requestCodeAgainSpinner autoPinEdgeToSuperviewEdge : ALEdgeRight withInset : ScaleFromIPhone5To7Plus ( 15 , 15 ) ] ;
_sendCodeViaVoiceButton = [ UIButton buttonWithType : UIButtonTypeCustom ] ;
_sendCodeViaVoiceButton . backgroundColor = [ UIColor whiteColor ] ;
[ _sendCodeViaVoiceButton setTitle : NSLocalizedString ( @ "VERIFICATION_CHALLENGE_SEND_VIA_VOICE ",
@ "button text during registration to request phone number verification be done via phone call ")
forState : UIControlStateNormal ] ;
forState : UIControlStateNormal ] ;
[ _sendCodeViaVoiceButton setTitleColor : signalBlueColor
forState : UIControlStateNormal ] ;
_sendCodeViaVoiceButton . titleLabel . font = [ UIFont ows_mediumFontWithSize : 14. f ] ;
[ _sendCodeViaVoiceButton addTarget : self
action : @ selector ( sendCodeViaVoiceAction : )
forControlEvents : UIControlEventTouchUpInside ] ;
[ self . view addSubview : _sendCodeViaVoiceButton ] ;
[ _sendCodeViaVoiceButton autoPinEdge : ALEdgeTop toEdge : ALEdgeBottom ofView : _sendCodeViaSMSAgainButton
withOffset : ScaleFromIPhone5To7Plus ( 0 , 0 ) ] ;
[ _sendCodeViaVoiceButton autoPinWidthToSuperviewWithMargin : ScaleFromIPhone5To7Plus ( 36 , 36 ) ] ;
[ _sendCodeViaVoiceButton autoSetDimension : ALDimensionHeight toSize : 35 ] ;
_requestCallSpinner = [ [ UIActivityIndicatorView alloc ] initWithActivityIndicatorStyle : UIActivityIndicatorViewStyleGray ] ;
[ _sendCodeViaVoiceButton addSubview : _requestCallSpinner ] ;
[ _requestCallSpinner autoSetDimension : ALDimensionWidth toSize : ScaleFromIPhone5To7Plus ( 20 , 20 ) ] ;
[ _requestCallSpinner autoSetDimension : ALDimensionHeight toSize : ScaleFromIPhone5To7Plus ( 20 , 20 ) ] ;
[ _requestCallSpinner autoVCenterInSuperview ] ;
[ _requestCallSpinner autoPinEdgeToSuperviewEdge : ALEdgeRight withInset : ScaleFromIPhone5To7Plus ( 15 , 15 ) ] ;
}
- ( void ) updatePhoneNumberLabel {
NSString * phoneNumber = [ PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber : [ TSAccountManager localNumber ] ] ;
_phoneNumberLabel . text = [ NSString stringWithFormat : NSLocalizedString ( @ "VERIFICATION_PHONE_NUMBER_FORMAT ",
@ "Label indicating the phone number currently being verified . ") ,
phoneNumber ] ;
}
}
- ( void ) viewWillAppear : ( BOOL ) animated {
- ( void ) viewWillAppear : ( BOOL ) animated {
[ super viewWillAppear : animated ] ;
[ super viewWillAppear : animated ] ;
[ self enableServerActions : YES ] ;
[ self enableServerActions : YES ] ;
[ _phoneNumberEntered setText :
[ self updatePhoneNumberLabel ] ;
[ PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber : [ TSAccountManager localNumber ] ] ] ;
}
[ self adjustScreenSizes ] ;
- ( void ) viewDidAppear : ( BOOL ) animated {
[ super viewDidAppear : animated ] ;
[ _challengeTextField becomeFirstResponder ] ;
}
}
- ( void ) startActivityIndicator
- ( void ) startActivityIndicator
@ -94,7 +241,7 @@ NSString *const kCompletedRegistrationSegue = @"CompletedRegistration";
[ self . submitCodeSpinner stopAnimating ] ;
[ self . submitCodeSpinner stopAnimating ] ;
}
}
- ( IBAction ) verifyChallengeAction : ( id ) sender
- ( void ) verifyChallengeAction : ( nullable id ) sender
{
{
[ self startActivityIndicator ] ;
[ self startActivityIndicator ] ;
[ self . accountManager registerWithVerificationCode : [ self validationCodeFromTextField ] ]
[ self . accountManager registerWithVerificationCode : [ self validationCodeFromTextField ] ]
@ -123,7 +270,9 @@ NSString *const kCompletedRegistrationSegue = @"CompletedRegistration";
preferredStyle : UIAlertControllerStyleAlert ] ;
preferredStyle : UIAlertControllerStyleAlert ] ;
UIAlertAction * dismissAction = [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "DISMISS_BUTTON_TEXT ", nil )
UIAlertAction * dismissAction = [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "DISMISS_BUTTON_TEXT ", nil )
style : UIAlertActionStyleDefault
style : UIAlertActionStyleDefault
handler : nil ] ;
handler : ^( UIAlertAction * action ) {
[ _challengeTextField becomeFirstResponder ] ;
} ] ;
[ alertController addAction : dismissAction ] ;
[ alertController addAction : dismissAction ] ;
[ self presentViewController : alertController animated : YES completion : nil ] ;
[ self presentViewController : alertController animated : YES completion : nil ] ;
@ -158,7 +307,8 @@ NSString *const kCompletedRegistrationSegue = @"CompletedRegistration";
}
}
#pragma mark - Send codes again
#pragma mark - Send codes again
- ( IBAction ) sendCodeSMSAction : ( id ) sender {
- ( void ) sendCodeViaSMSAction : ( id ) sender {
[ self enableServerActions : NO ] ;
[ self enableServerActions : NO ] ;
[ _requestCodeAgainSpinner startAnimating ] ;
[ _requestCodeAgainSpinner startAnimating ] ;
@ -175,7 +325,7 @@ NSString *const kCompletedRegistrationSegue = @"CompletedRegistration";
} ] ;
} ] ;
}
}
- ( IBAction) sendCode VoiceAction: ( id ) sender {
- ( void) sendCodeVia VoiceAction: ( id ) sender {
[ self enableServerActions : NO ] ;
[ self enableServerActions : NO ] ;
[ _requestCallSpinner startAnimating ] ;
[ _requestCallSpinner startAnimating ] ;
@ -209,6 +359,9 @@ NSString *const kCompletedRegistrationSegue = @"CompletedRegistration";
[ _sendCodeViaVoiceButton setEnabled : enabled ] ;
[ _sendCodeViaVoiceButton setEnabled : enabled ] ;
}
}
- ( void ) backButtonPressed : ( id ) sender {
[ self . navigationController popViewControllerAnimated : YES ] ;
}
#pragma mark - Keyboard notifications
#pragma mark - Keyboard notifications
@ -249,14 +402,15 @@ NSString *const kCompletedRegistrationSegue = @"CompletedRegistration";
return YES ;
return YES ;
}
}
- ( void ) adjustScreenSizes
- ( BOOL ) textFieldShouldReturn : ( UITextField * ) textField {
{
[ self verifyChallengeAction : nil ] ;
CGFloat screenHeight = [ UIScreen mainScreen ] . bounds . size . height ;
[ textField resignFirstResponder ] ;
return NO ;
}
if ( screenHeight < 667 ) { / / iphone 5
- ( void ) setVerificationCodeAndTryToVerify : ( NSString * ) verificationCode {
self . signalLogo . hidden = YES ;
self . challengeTextField . text = verificationCode ;
_headerConstraint . constant = 120 ;
[ self verifyChallengeAction : nil ] ;
}
}
}
#pragma mark - Logging
#pragma mark - Logging