"use strict"; function CLoginPromptManager( strBaseURL, rgOptions ) { // normalize with trailing slash this.m_strBaseURL = strBaseURL + ( strBaseURL.substr(-1) == '/' ? '' : '/' ) + ( this.m_bIsMobile ? 'mobilelogin' : 'login' ) + '/'; this.m_strSiteBaseURL = strBaseURL; // Actual base url, not the login base url above. // read options rgOptions = rgOptions || {}; this.m_bIsMobile = rgOptions.bIsMobile || false; this.m_strMobileClientType = rgOptions.strMobileClientType || ''; this.m_strMobileClientVersion = rgOptions.strMobileClientVersion || ''; this.m_bIsMobileSteamClient = ( this.m_strMobileClientType ? true : false ); this.m_bMobileClientSupportsPostMessage = rgOptions.bMobileClientSupportsPostMessage || false; this.m_$LogonForm = $JFromIDOrElement( rgOptions.elLogonForm || document.forms['logon'] ); this.m_fnOnFailure = rgOptions.fnOnFailure || null; this.m_fnOnSuccess = rgOptions.fnOnSuccess || null; this.m_strRedirectURL = rgOptions.strRedirectURL || (this.m_bIsMobile ? '' : strBaseURL); this.m_strSessionID = rgOptions.strSessionID || null; this.m_strUsernameEntered = null; this.m_strUsernameCanonical = null; if ( rgOptions.gidCaptcha ) this.UpdateCaptcha( rgOptions.gidCaptcha ); else this.RefreshCaptcha(); // check if needed this.m_bLoginInFlight = false; this.m_bInEmailAuthProcess = false; this.m_bInTwoFactorAuthProcess = false; this.m_TwoFactorModal = null; this.m_bEmailAuthSuccessful = false; this.m_bLoginTransferInProgress = false; this.m_bEmailAuthSuccessfulWantToLeave = false; this.m_bTwoFactorAuthSuccessful = false; this.m_bTwoFactorAuthSuccessfulWantToLeave = false; this.m_sOAuthRedirectURI = 'steammobile://mobileloginsucceeded'; this.m_sAuthCode = ""; this.m_sPhoneNumberLastDigits = "??"; this.m_bTwoFactorReset = false; // values we collect from the user this.m_steamidEmailAuth = ''; // record keeping this.m_iIncorrectLoginFailures = 0; // mobile reveals password after a couple failures var _this = this; this.m_$LogonForm.submit( function(e) { _this.DoLogin(); e.preventDefault(); }); // find buttons and make them clickable $J('#login_btn_signin' ).children('a, button' ).click( function() { _this.DoLogin(); } ); this.InitModalContent(); // these modals need to be in the body because we refer to elements by name before they are ready this.m_$ModalAuthCode = this.GetModalContent( 'loginAuthCodeModal' ); this.m_$ModalAuthCode.find('[data-modalstate]' ).each( function() { $J(this).click( function() { _this.SetEmailAuthModalState( $J(this).data('modalstate') ); } ); }); this.m_$ModalAuthCode.find('form').submit( function(e) { _this.SetEmailAuthModalState('submit'); e.preventDefault(); }); this.m_EmailAuthModal = null; this.m_$ModalIPT = this.GetModalContent( 'loginIPTModal' ); this.m_$ModalTwoFactor = this.GetModalContent( 'loginTwoFactorCodeModal' ); this.m_$ModalTwoFactor.find( '[data-modalstate]' ).each( function() { $J(this).click( function() { _this.SetTwoFactorAuthModalState( $J(this).data('modalstate') ); } ); }); this.m_$ModalTwoFactor.find( 'form' ).submit( function(e) { // Prevent submit if nothing was entered if ( $J('#twofactorcode_entry').val() != '' ) { // Push the left button var $btnLeft = _this.m_$ModalTwoFactor.find( '.auth_buttonset:visible .auth_button.leftbtn ' ); $btnLeft.trigger( 'click' ); } e.preventDefault(); }); // register to listen to IOS two factor callback $J(document).on('SteamMobile_ReceiveAuthCode', function( e, authcode ) { _this.m_sAuthCode = authcode; }); $J('#captchaRefreshLink' ).click( $J.proxy( this.RefreshCaptcha, this ) ); // include some additional scripts we may need if ( typeof BigNumber == 'undefined' ) $J.ajax( { url: 'https://store.st.dl.eccdnx.com/public/shared/javascript/crypto/jsbn.js', type: 'get', dataType: 'script', cache: true } ); if ( typeof RSA == 'undefined' ) $J.ajax( { url: 'https://store.st.dl.eccdnx.com/public/shared/javascript/crypto/rsa.js', type: 'get', dataType: 'script', cache: true } ); } CLoginPromptManager.prototype.BIsIos = function() { return this.m_strMobileClientType == 'ios'; }; CLoginPromptManager.prototype.BIsAndroid = function() { return this.m_strMobileClientType == 'android'; }; CLoginPromptManager.prototype.BIsWinRT = function() { return this.m_strMobileClientType == 'winrt'; }; CLoginPromptManager.prototype.BIsUserInMobileClientVersionOrNewer = function( nMinMajor, nMinMinor, nMinPatch ) { if ( (!this.BIsIos() && !this.BIsAndroid() && !this.BIsWinRT() ) || this.m_strMobileClientVersion == '' ) return false; var version = this.m_strMobileClientVersion.match( /(?:(\d+) )?\(?(\d+)\.(\d+)(?:\.(\d+))?\)?/ ); if ( version && version.length >= 3 ) { var nMajor = parseInt( version[2] ); var nMinor = parseInt( version[3] ); var nPatch = parseInt( version[4] ); return nMajor > nMinMajor || ( nMajor == nMinMajor && ( nMinor > nMinMinor || ( nMinor == nMinMinor && nPatch >= nMinPatch ) ) ); } }; CLoginPromptManager.prototype.GetParameters = function( rgParams ) { var rgDefaultParams = { 'donotcache': new Date().getTime() }; if ( this.m_strSessionID ) rgDefaultParams['sessionid'] = this.m_strSessionID; return $J.extend( rgDefaultParams, rgParams ); }; CLoginPromptManager.prototype.$LogonFormElement = function( strElementName ) { var $Form = this.m_$LogonForm; var elInput = this.m_$LogonForm[0].elements[ strElementName ]; if ( !elInput ) { var $Input = $J('', {type: 'hidden', name: strElementName } ); $Form.append( $Input ); return $Input; } else { return $J( elInput ); } }; CLoginPromptManager.prototype.HighlightFailure = function( msg ) { if ( this.m_fnOnFailure ) { this.m_fnOnFailure( msg ); // always blur on mobile so the error can be seen if ( this.m_bIsMobile && msg ) $J('input:focus').blur(); } else { var $ErrorElement = $J('#error_display'); if ( msg ) { $ErrorElement.text( msg ); $ErrorElement.slideDown(); if ( this.m_bIsMobile ) $J('input:focus').blur(); } else { $ErrorElement.hide(); } } }; //Refresh the catpcha image CLoginPromptManager.prototype.RefreshCaptcha = function() { var _this = this; $J.post( this.m_strBaseURL + 'refreshcaptcha/', this.GetParameters( {} ) ) .done( function( data ) { _this.UpdateCaptcha( data.gid ); }); }; CLoginPromptManager.prototype.UpdateCaptcha = function( gid ) { if ( gid != -1 ) { $J('#captcha_entry').show(); var $ImageElement = $J('#captchaImg'); var strURL = this.m_strBaseURL + 'rendercaptcha/?gid=' + gid; if ( $ImageElement.data( 'noborder' ) ) { strURL += '&noborder=1'; } $ImageElement.attr( 'src', strURL ); this.$LogonFormElement('captcha_text').val(''); } else { $J('#captcha_entry' ).hide(); } this.m_gidCaptcha = gid; }; CLoginPromptManager.prototype.DoLogin = function() { var form = this.m_$LogonForm[0]; var username = form.elements['username'].value; this.m_strUsernameEntered = username; username = username.replace( /[^\x00-\x7F]/g, '' ); // remove non-standard-ASCII characters this.m_strUsernameCanonical = username; var password = form.elements['password'].value; password = password.replace( /[^\x00-\x7F]/g, '' ); // remove non-standard-ASCII characters if ( this.m_bLoginInFlight || password.length == 0 || username.length == 0 ) return; this.m_bLoginInFlight = true; $J('#login_btn_signin').hide(); $J('#login_btn_wait').show(); // reset some state this.HighlightFailure( '' ); var _this = this; $J.post( this.m_strBaseURL + 'getrsakey/', this.GetParameters( { username: username } ) ) .done( $J.proxy( this.OnRSAKeyResponse, this ) ) .fail( function () { ShowAlertDialog( '错误', '与 Steam 服务器通信时出现问题。请稍后重试。' ); $J('#login_btn_signin').show(); $J('#login_btn_wait').hide(); _this.m_bLoginInFlight = false; }); }; // used to get mobile client to execute a steammobile URL CLoginPromptManager.prototype.RunLocalURL = function(url) { var $IFrame = $J('