@ -30,7 +30,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
@@ -30,7 +30,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
LayoutSwitchService . start ( ) ;
} )
. controller ( 'AppLoginController' , function ( $scope , $rootScope , $location , $timeout , $modal , $modalStack , MtpApiManager , ErrorService , NotificationsManager , ChangelogNotifyService , IdleManager , LayoutSwitchService , TelegramMeWebService , _ ) {
. controller ( 'AppLoginController' , function ( $scope , $rootScope , $location , $timeout , $modal , $modalStack , MtpApiManager , ErrorService , NotificationsManager , PasswordManager , ChangelogNotifyService , IdleManager , LayoutSwitchService , TelegramMeWebService , _ ) {
$modalStack . dismissAll ( ) ;
IdleManager . start ( ) ;
@ -156,6 +156,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
@@ -156,6 +156,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var callTimeout ;
var updatePasswordTimeout = false ;
function saveAuth ( result ) {
MtpApiManager . setUserAuth ( options . dcID , {
@ -204,7 +205,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
@@ -204,7 +205,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
phone _number : $scope . credentials . phone _full ,
// sms_type: 5,
api _id : Config . App . id ,
api _hash : Config . App . hash
api _hash : Config . App . hash ,
lang _code : navigator . language || 'en'
} , options ) . then ( function ( sentCode ) {
$scope . progress . enabled = false ;
@ -290,6 +292,16 @@ angular.module('myApp.controllers', ['myApp.i18n'])
@@ -290,6 +292,16 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} else if ( error . code == 400 && error . type == 'PHONE_NUMBER_OCCUPIED' ) {
error . handled = true ;
return $scope . logIn ( false ) ;
} else if ( error . code == 401 && error . type == 'SESSION_PASSWORD_NEEDED' ) {
$scope . progress . enabled = true ;
updatePasswordState ( ) . then ( function ( ) {
$scope . progress . enabled = false ;
$scope . credentials . phone _code _valid = true ;
$scope . credentials . password _needed = true ;
$scope . about = { } ;
} ) ;
error . handled = true ;
return ;
}
@ -312,6 +324,82 @@ angular.module('myApp.controllers', ['myApp.i18n'])
@@ -312,6 +324,82 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} ;
$scope . checkPassword = function ( ) {
return PasswordManager . check ( $scope . password , $scope . credentials . password , options ) . then ( saveAuth , function ( error ) {
switch ( error . type ) {
case 'PASSWORD_HASH_INVALID' :
$scope . error = { field : 'password' } ;
error . handled = true ;
break ;
}
} ) ;
} ;
$scope . forgotPassword = function ( event ) {
PasswordManager . requestRecovery ( $scope . password , options ) . then ( function ( emailRecovery ) {
var scope = $rootScope . $new ( ) ;
scope . recovery = emailRecovery ;
scope . options = options ;
var modal = $modal . open ( {
scope : scope ,
templateUrl : templateUrl ( 'password_recovery_modal' ) ,
controller : 'PasswordRecoveryModalController' ,
windowClass : 'md_simple_modal_window mobile_modal'
} ) ;
modal . result . then ( function ( result ) {
if ( result && result . user ) {
saveAuth ( result ) ;
} else {
$scope . canReset = true ;
}
} ) ;
} , function ( error ) {
switch ( error . type ) {
case 'PASSWORD_EMPTY' :
$scope . logIn ( ) ;
break ;
case 'PASSWORD_RECOVERY_NA' :
$timeout ( function ( ) {
$scope . canReset = true ;
} , 1000 ) ;
break ;
}
} )
return cancelEvent ( event ) ;
} ;
$scope . resetAccount = function ( ) {
ErrorService . confirm ( {
type : 'RESET_ACCOUNT'
} ) . then ( function ( ) {
$scope . progress . enabled = true ;
MtpApiManager . invokeApi ( 'account.deleteAccount' , {
reason : 'Forgot password'
} , options ) . then ( function ( ) {
delete $scope . progress . enabled ;
delete $scope . credentials . password _needed ;
$scope . credentials . phone _unoccupied = true ;
} , function ( ) {
delete $scope . progress . enabled ;
} )
} ) ;
} ;
function updatePasswordState ( ) {
// $timeout.cancel(updatePasswordTimeout);
// updatePasswordTimeout = false;
return PasswordManager . getState ( options ) . then ( function ( result ) {
return $scope . password = result ;
// if (result._ == 'account.noPassword' && result.email_unconfirmed_pattern) {
// updatePasswordTimeout = $timeout(updatePasswordState, 5000);
// }
} ) ;
}
ChangelogNotifyService . checkUpdate ( ) ;
LayoutSwitchService . start ( ) ;
} )
@ -364,6 +452,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
@@ -364,6 +452,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} ) ;
} ;
// setTimeout($scope.openSettings, 1000);
$scope . openFaq = function ( ) {
var url = 'https://telegram.org/faq' ;
switch ( Config . I18n . locale ) {
@ -2535,10 +2625,17 @@ angular.module('myApp.controllers', ['myApp.i18n'])
@@ -2535,10 +2625,17 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope . password = { _ : 'account.noPassword' } ;
updatePasswordState ( ) ;
var updatePasswordTimeout = false ;
$scope . changePassword = function ( options ) {
options = options || { } ;
if ( options . action == 'cancel_email' ) {
return ErrorService . confirm ( { type : 'PASSWORD_ABORT_SETUP' } ) . then ( function ( ) {
PasswordManager . updateSettings ( $scope . password , { email : '' } ) . then ( updatePasswordState ) ;
} ) ;
}
var scope = $rootScope . $new ( ) ;
scope . password = $scope . password ;
angular . extend ( scope , options ) ;
var modal = $modal . open ( {
scope : scope ,
@ -2550,9 +2647,14 @@ angular.module('myApp.controllers', ['myApp.i18n'])
@@ -2550,9 +2647,14 @@ angular.module('myApp.controllers', ['myApp.i18n'])
modal . result [ 'finally' ] ( updatePasswordState ) ;
} ;
function updatePasswordState ( argument ) {
PasswordManager . getPasswordState ( ) . then ( function ( result ) {
function updatePasswordState ( ) {
$timeout . cancel ( updatePasswordTimeout ) ;
updatePasswordTimeout = false ;
PasswordManager . getState ( ) . then ( function ( result ) {
$scope . password = result ;
if ( result . _ == 'account.noPassword' && result . email _unconfirmed _pattern ) {
updatePasswordTimeout = $timeout ( updatePasswordState , 5000 ) ;
}
} ) ;
}
@ -2882,7 +2984,141 @@ angular.module('myApp.controllers', ['myApp.i18n'])
@@ -2882,7 +2984,141 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} )
} )
. controller ( 'PasswordUpdateModalController' , function ( $scope , PasswordManager , MtpApiManager ) {
. controller ( 'PasswordUpdateModalController' , function ( $scope , $q , _ , PasswordManager , MtpApiManager , ErrorService , $modalInstance ) {
$scope . passwordSettings = { } ;
$scope . updatePassword = function ( ) {
delete $scope . passwordSettings . error _field ;
var confirmPromise ;
if ( $scope . action == 'disable' ) {
confirmPromise = $q . when ( ) ;
}
else {
if ( ! $scope . passwordSettings . new _password ) {
$scope . passwordSettings . error _field = 'new_password' ;
$scope . $broadcast ( 'new_password_focus' ) ;
return false ;
}
if ( $scope . passwordSettings . new _password != $scope . passwordSettings . confirm _password ) {
$scope . passwordSettings . error _field = 'confirm_password' ;
$scope . $broadcast ( 'confirm_password_focus' ) ;
return false ;
}
confirmPromise = $scope . passwordSettings . email
? $q . when ( )
: ErrorService . confirm ( { type : 'RECOVERY_EMAIL_EMPTY' } ) ;
}
$scope . passwordSettings . loading = true ;
confirmPromise . then ( function ( ) {
PasswordManager . updateSettings ( $scope . password , {
cur _password : $scope . passwordSettings . cur _password || '' ,
new _password : $scope . passwordSettings . new _password ,
email : $scope . passwordSettings . email ,
hint : $scope . passwordSettings . hint
} ) . then ( function ( result ) {
delete $scope . passwordSettings . loading ;
$modalInstance . close ( true ) ;
if ( $scope . action == 'disable' ) {
ErrorService . alert (
_ ( 'error_modal_password_disabled_title' ) ,
_ ( 'error_modal_password_disabled_descripion' )
) ;
} else {
ErrorService . alert (
_ ( 'error_modal_password_success_title' ) ,
_ ( 'error_modal_password_success_descripion' )
) ;
}
} , function ( error ) {
switch ( error . type ) {
case 'PASSWORD_HASH_INVALID' :
case 'NEW_PASSWORD_BAD' :
$scope . passwordSettings . error _field = 'cur_password' ;
error . handled = true ;
$scope . $broadcast ( 'cur_password_focus' ) ;
break ;
case 'NEW_PASSWORD_BAD' :
$scope . passwordSettings . error _field = 'new_password' ;
error . handled = true ;
break ;
case 'EMAIL_INVALID' :
$scope . passwordSettings . error _field = 'email' ;
error . handled = true ;
break ;
case 'EMAIL_UNCONFIRMED' :
ErrorService . alert (
_ ( 'error_modal_email_unconfirmed_title' ) ,
_ ( 'error_modal_email_unconfirmed_descripion' )
) ;
$modalInstance . close ( true ) ;
error . handled = true ;
break ;
}
delete $scope . passwordSettings . loading ;
} ) ;
} )
}
switch ( $scope . action ) {
case 'disable' :
$scope . passwordSettings . new _password = '' ;
break ;
case 'create' :
onContentLoaded ( function ( ) {
$scope . $broadcast ( 'new_password_focus' ) ;
} ) ;
break ;
}
$scope . $watch ( 'passwordSettings.new_password' , function ( newValue ) {
var len = newValue && newValue . length || 0 ;
if ( ! len ) {
$scope . passwordSettings . hint = '' ;
}
else if ( len <= 3 ) {
$scope . passwordSettings . hint = '***' ;
}
else {
$scope . passwordSettings . hint = newValue . charAt ( 0 ) + ( new Array ( len - 1 ) ) . join ( '*' ) + newValue . charAt ( len - 1 ) ;
}
$scope . $broadcast ( 'value_updated' ) ;
} )
} )
. controller ( 'PasswordRecoveryModalController' , function ( $scope , $q , _ , PasswordManager , MtpApiManager , ErrorService , $modalInstance ) {
$scope . checkCode = function ( ) {
$scope . recovery . updating = true ;
PasswordManager . recover ( $scope . recovery . code , $scope . options ) . then ( function ( result ) {
ErrorService . alert (
_ ( 'error_modal_password_disabled_title' ) ,
_ ( 'error_modal_password_disabled_descripion' )
) ;
$modalInstance . close ( result ) ;
} , function ( error ) {
delete $scope . recovery . updating ;
switch ( error . type ) {
case 'CODE_EMPTY' :
case 'CODE_INVALID' :
$scope . recovery . error _field = 'code' ;
error . handled = true ;
break ;
case 'PASSWORD_EMPTY' :
case 'PASSWORD_RECOVERY_NA' :
case 'PASSWORD_RECOVERY_EXPIRED' :
$modalInstance . dismiss ( ) ;
error . handled = true ;
break ;
}
} ) ;
} ;
} )