|
- /**
- * Created by Benny on 12.10.2014.
- */
-
- "use strict";
-
- var TB = TB || {};
- TB.Control = TB.Control || {};
-
- TB.Control.Auth = {
- login : function( params )
- {
- var page = new TB.Page( 'auth' ),
- redirect = params && params.redirect ? params.redirect : null;
-
- page.onEnter = function( params )
- {
- $( '#main').hide();
- $( '#main_auth').show();
- this.$container = $( '#main_auth' );
- TB.Page.prototype.onEnter.call( this, params );
- };
- page.onLeave = function()
- {
- TB.Page.prototype.onLeave.call( this );
- $( '#main_auth').hide();
- $( '#main').show();
- };
- TB.GUI.show( page, { activeTab: 'login' } );
-
- // Login Button
- page.$container.find( '#btn_login').click( function() {
-
- if ( !TB.GUI.performFormValidation( $( '#form_login' ) ) )
- {
- return false;
- }
-
- TB.Service.request( 'Auth', 'login', {
- 'email' : page.$container.find( 'input[name="login.email"]' ).val(),
- 'pass' : page.$container.find( 'input[name="login.pass"]' ).val()
- },
- function( data ) {
- if ( data && data.account && data.profile && data.session && data.profiles && data.teams ) {
- TB.Client.setSessionData( data.account, data.profile, data.session, data.profiles, data.teams );
- TB.Ext.Push.register();
- TB.GUI.setTeamName();
- if ( redirect )
- {
- TB.Controller.do( 'Auth', 'redirect', { redirect : redirect } );
- TB.Utils.trackEvent( 'auth', 'redirect' );
- }
- else
- {
- TB.Controller.do( 'News' );
- TB.Utils.trackEvent( 'auth', 'login' );
- }
- } else if ( data && data.error && data.error == 'not_validated' )
- {
- TB.Ext.Notification.show( 'Deine Email Adresse ist noch nicht validiert. Bitte schau in deine Emails und klicke auf den Aktivierungslink.', TB.Ext.Notification.TYPE_WARNING );
- }
- else
- {
- TB.Ext.Notification.show( 'Anmeldung gescheitert. Passwort und/oder Email sind fehlerhaft.', TB.Ext.Notification.TYPE_DANGER );
- }
- },
- $( this )
- );
- return false;
- });
-
- // Forgot passwort link / Register actions
- page.$container.find( '[data-refdivid]').click( function() {
- TB.Controller.do( 'Auth', $(this).attr( 'data-refdivid') );
- });
-
- },
-
- registertrainer : function( params ) {
- var page = new TB.Page( 'auth' );
- page.onEnter = function( params ) {
- $( '#main').hide();
- $( '#main_auth').show();
- this.$container = $( '#main_auth' );
- TB.Page.prototype.onEnter.call( this, params );
- // Track registration
- try {
- TB.Utils.trackEvent( 'form', 'contactform' );
- } catch (e) {
- // Fail silently
- }
- };
- page.onLeave = function() {
- TB.Page.prototype.onLeave.call( this );
- $( '#main_auth').hide();
- $( '#main').show();
- };
-
- var buildRegistration = function( tmplData ) {
- TB.GUI.show( page, tmplData );
-
- $( '#main_auth').on( 'blur', "#form_register_trainer input", function() {
- TB.GUI.performInputValidation( $( this ) );
- });
-
- page.$container.find( '#btn_register_trainer').click( function() {
-
- if ( !TB.GUI.performFormValidation( $( '#form_register_trainer' ) ) ) {
- return false;
- }
-
- TB.Service.request( 'Auth', 'registerTrainer', {
- 'gender' : page.$container.find( '#form_register_trainer input[name="register.gender"]:checked' ).val(),
- 'team_name' : page.$container.find( '#form_register_trainer input[name="register.team_name"]' ).val(),
- 'team_category' : page.$container.find( '#form_register_trainer input[name="register.team_category"]' ).val(),
- 'email' : page.$container.find( '#form_register_trainer input[name="register.email"]' ).val(),
- 'pass' : page.$container.find( '#form_register_trainer input[name="register.pass"]' ).val(),
- 'first_name' : page.$container.find( '#form_register_trainer input[name="register.first_name"]').val(),
- 'last_name' : page.$container.find( '#form_register_trainer input[name="register.last_name"]').val(),
- 'subscribed_news' : page.$container.find( '#form_register_trainer input[name="register.subscribe_news"]').is(":checked" ) ? "on" : "off",
- 'token' : page.$container.find( '#form_register_trainer input[name="register.token"]').val()
- },
- function( data ) {
- if ( data && data.account && data.profile ) {
- TB.GUI.show( page, { activeTab: 'register_trainer_done' } );
- page.$container.find( '[data-refdivid]').click( function() {
- TB.Controller.do( 'Auth', $(this).attr( 'data-refdivid') );
- });
-
- // Tracking
- try {
- TB.Utils.trackEvent( 'auth', 'team_created' );
-
- // Google Tracking
- window.goog_report_conversion && window.goog_report_conversion();
-
- // Facebook Tracking
- window.fbq && fbq('track', 'CompleteRegistration');
-
- } catch( err ) {
- // Fail silently
- }
-
- } else {
- if ( data.error == "invalid-credentials" ) {
- TB.Ext.Alert.show( 'Accountdaten', 'Die eingegebene Email+Password Kombination stimmt nicht überein.' );
- }
- }
- },
- $( this ),
- function( data ) {
- if ( data && data.gen_err && "email_already_exists" == data.gen_err ) {
- TB.Ext.Notification.show( 'Die EMail Adresse existiert bereits. Wenn Du schon einen Account hast, dann kannst Du unter den Menüpunkt "Profile" im Seitenmenü ein neues Team anlegen.', TB.Ext.Notification.TYPE_INFO);
- } else {
- TB.Ext.Notification.show( 'Registrierung fehlgeschlagen. Bitte versuche es zu einem späteren Zeitpunkt nochmal.', TB.Ext.Notification.TYPE_DANGER );
- }
- }
- );
-
- return false;
- });
-
- // Forgot passwort link / Register actions
- page.$container.find( '[data-refdivid]').click( function() {
- TB.Controller.do( 'Auth', $(this).attr( 'data-refdivid') );
- });
-
- page.$container.find( '#registerteamcategory' ).easyAutocomplete({
- // Note:
- // Duplicate list
- data : TB.Config.General.team_categories,
- list: {
- maxNumberOfElements: 10,
- match: {
- enabled: true
- }
- }
- });
-
- };
-
- buildRegistration( { activeTab: 'register_trainer' } );
-
- },
-
- registerplayer : function( params ) {
- var page = new TB.Page( 'auth' );
- page.onEnter = function( params ) {
- $( '#main').hide();
- $( '#main_auth').show();
- this.$container = $( '#main_auth' );
- TB.Page.prototype.onEnter.call( this, params );
- };
- page.onLeave = function() {
- TB.Page.prototype.onLeave.call( this );
- $( '#main_auth').hide();
- $( '#main').show();
- };
-
- var token = ( params && params.t ) ? params.t : null;
-
- $( '#main_auth').on( 'blur', "#form_register_player input", function() {
- TB.GUI.performInputValidation( $( this ) );
- });
-
- var buildRegistration = function( tmplData ) {
- TB.GUI.show( page, tmplData );
- // Forgot passwort link / Register actions
- page.$container.find( '[data-refdivid]').click( function() {
- TB.Controller.do( 'Auth', $(this).attr( 'data-refdivid') );
- });
-
- page.$container.find( '#btn_register_player').click( function() {
- if ( !TB.GUI.performFormValidation( $( '#form_register_player' ) ) ) {
- return false;
- }
-
- TB.Service.request( 'Auth', 'registerPlayer', {
- 'pass' : page.$container.find( '#form_register_player input[name="register.pass"]' ).val(),
- 'subscribed_news' : page.$container.find( '#form_register_player input[name="register.subscribe_news"]').is(":checked" ) ? "on" : "off",
- 'token' : page.$container.find( '#form_register_player input[name="register.token"]').val()
- },
- function( data ) {
- if ( data && data.account && data.profile && data.session && data.profiles && data.teams ) {
- TB.Client.setSessionData( data.account, data.profile, data.session, data.profiles, data.teams );
- TB.Ext.Push.register();
- TB.Controller.do( 'News' );
- TB.Utils.trackEvent( 'auth', 'player_created' );
- } else {
- if ( data.error == "invalid-credentials" ) {
- TB.Ext.Alert.show( 'Accountdaten', 'Die eingegebene Email+Password Kombination stimmt nicht überein.' );
- } else if ( data.error == "invalid-token" ) {
- TB.Ext.Alert.show( 'Einladung ungültig', 'Deine Einladung ist leider nicht mehr gültig. Bitte frage den Trainer nach einer neuen.' );
- }
- }
- },
- $( this )
- );
-
- return false;
- });
- };
-
- TB.Service.request( 'Auth', 'getInvitation', { token: token },
- function( data ) {
- buildRegistration( {
- activeTab: 'register_player',
- token: data.token,
- invitation: data.invitation,
- account : data.account,
- inviter : data.inviter,
- team : data.team } );
- }
- );
- },
-
- forgot_password : function() {
- var page = new TB.Page( 'auth' );
- page.onEnter = function( params ) {
- $( '#main').hide();
- $( '#main_auth').show(); this.$container = $( '#main_auth' );
- TB.Page.prototype.onEnter.call( this, params );
- };
- page.onLeave = function() {
- TB.Page.prototype.onLeave.call( this );
- $( '#main_auth').hide();
- $( '#main').show();
- };
- TB.GUI.show( page, { activeTab: 'forgot_password' } );
-
- $( '#main_auth').on( 'blur', "form input", function() {
- TB.GUI.performInputValidation( $( this ) );
- });
-
- // Login Button
- page.$container.find( '#btn_forgot_password').click( function() {
- if (!TB.GUI.performFormValidation($('#form_forgot_password'))) {
- return false;
- }
-
- TB.Service.request( 'Auth', 'requestPasswordReset', {
- 'email' : page.$container.find( '#form_forgot_password input[name="forgot_password.email"]' ).val()
- },
- function( data ) {
- if ( data.res == "account_not_found" ) {
- TB.Ext.Notification.show( 'Es existiert kein Account mit angegebener Email Adresse.', TB.Ext.Notification.TYPE_DANGER );
- } else if ( data.res == "already_sent" ) {
- TB.Ext.Notification.show( 'Die Email ist bereits unterwegs. Ist sie etwa in Deinem Spam Ordner gelandet?', TB.Ext.Notification.TYPE_WARNING );
- } else {
- TB.Ext.Alert.modal( {
- title: 'Erfolg!',
- text: 'Eine Email an Dich ist unterwegs. Bitte schau in Dein Postfach und folge den Anweisungen, um ein neues Passwort zu erstellen.',
- type: 'success',
- showCancelButton: false
- }, function() {
- TB.Controller.do( 'Auth', 'login' );
- });
- }
- },
- $( this )
- );
-
- return false;
- }
- );
-
-
- // Forgot passwort link / Register actions
- page.$container.find( '[data-refdivid]').click( function() {
- TB.Controller.do( 'Auth', $(this).attr( 'data-refdivid') );
- });
- },
-
- reset_password : function( params ) {
- var page = new TB.Page( 'auth'),
- token = ( params && params.t ) ? params.t : null;;
- page.onEnter = function( params ) {
- $( '#main').hide();
- $( '#main_auth').show(); this.$container = $( '#main_auth' );
- TB.Page.prototype.onEnter.call( this, params );
- };
- page.onLeave = function() {
- TB.Page.prototype.onLeave.call( this );
- $( '#main_auth').hide();
- $( '#main').show();
- };
-
- TB.GUI.show( page, { activeTab: 'reset_password', pwrtoken: token } );
-
- $( '#main_auth').on( 'blur', "#form_reset_password input", function() {
- TB.GUI.performInputValidation( $( this ) );
- });
-
-
- // Reset Password Button
- page.$container.find( '#btn_reset_password').click( function() {
- if (!TB.GUI.performFormValidation($('#form_reset_password'))) {
- return false;
- }
-
- TB.Service.request( 'Auth', 'resetPassword', {
- 'token' : page.$container.find( '#form_reset_password input[name="reset_password.token"]' ).val(),
- 'password1' : page.$container.find( '#form_reset_password input[name="reset_password.password1"]' ).val(),
- 'password2' : page.$container.find( '#form_reset_password input[name="reset_password.password2"]' ).val()
- },
- function( data ) {
-
- if ( data.res == 'ok' ) {
- TB.Ext.Alert.modal( {
- title: 'Erfolg!',
- text: 'Dein Passwort wurde erfolgreich geändert. Logge Dich gleich damit ein.',
- type: 'success',
- showCancelButton: false
- }, function() {
- TB.Client.logout();
- TB.Controller.do( 'Auth', 'login' );
- });
- } else {
- TB.Ext.Alert.modal( {
- title: 'Oooopps.',
- text: 'Leider ist bei der Aktion ein Fehler aufgetreten. Versuche es erneut oder kontaktiere unseren Support.',
- type: 'warning',
- showCancelButton: false
- }, function() {
- TB.Controller.do( 'Auth', 'login' );
- });
- }
- },
- $( this )
- );
-
- return false;
- }
- );
-
-
- // Forgot passwort link / Register actions
- page.$container.find( '[data-refdivid]').click( function() {
- TB.Controller.do( 'Auth', $(this).attr( 'data-refdivid') );
- });
- },
-
- confirm_email_change : function( params ) {
-
- var page = new TB.Page( 'auth'),
- token = ( params && params.t ) ? params.t : null;;
-
- page.onEnter = function( params ) {
- $( '#main').hide();
- $( '#main_auth').show(); this.$container = $( '#main_auth' );
- TB.Page.prototype.onEnter.call( this, params );
- };
- page.onLeave = function() {
- TB.Page.prototype.onLeave.call( this );
- $( '#main_auth').hide();
- $( '#main').show();
- };
-
- TB.Service.request( 'Auth', 'confirmEmailChange', { token : token }, function( res ) {
- var actionResult = 'nok';
- if ( res && res.email_change_result ) {
- switch ( res.email_change_result ) {
- case 'ok':
- actionResult = 'ok';
- break;
-
- case 'timeup':
- actionResult = 'timeup'
- break;
- }
- }
-
- TB.GUI.show( page, { activeTab: 'confirm_email_change', actionResult : actionResult } );
-
- page.$container.find( '#btn-continue-after-confirm-email').click( function() {
- if ( TB.Client.isLoggedIn() ) {
- TB.Controller.do( 'News' );
- } else {
- TB.Controller.do( 'Auth', 'login' );
- }
- return false;
- });
- });
- },
-
- validate_email : function( params ) {
- var token = ( params && params.t ) ? params.t : null;
-
- $( '#main').hide();
- $( '#main_auth').show();
-
- TB.Service.request('Auth', 'validateEmail', {token: token}, function (data) {
- if (data.res == 'ok') {
- TB.Ext.Alert.modal( {
- title: 'Super!',
- text: 'Dein Account ist nun erfolgreich validiert.',
- type: 'success',
- showCancelButton: false
- }, function() {
- if ( TB.Client.isLoggedIn() ) {
- if ( data.profile ) {
- TB.Client.updateSessionProfile( data.profile );
- }
-
- $( '#main_auth').hide();
- $( '#main').show();
-
- TB.Controller.do( 'News' );
- } else {
- TB.Controller.do( 'Auth', 'login' );
- }
- });
- } else {
- TB.Ext.Alert.modal( {
- title: 'Oooopps.',
- text: 'Leider ist bei der Aktion ein Fehler aufgetreten. Versuche es später erneut oder kontaktiere unseren Support.',
- type: 'warning',
- showCancelButton: false
- }, function() {
- TB.Controller.do( 'Auth', 'login' );
- });
- }
- });
- },
-
- redirect : function( params )
- {
- var target = params && params.redirect ? decodeURIComponent( params.redirect ) : null,
- reObj = TB.Utils.decoreRedirect( target ),
- targetProfileId = null,
- isValidTargetId = false;
-
- if ( false === TB.Client.isLoggedIn() )
- {
- TB.Controller.do( 'Auth', 'login', { redirect : ( params && params.redirect ? params.redirect : null ) } );
- }
- else if ( reObj && reObj.c && reObj.a )
- {
- if ( reObj.targetTeamId && TB.Client.profile.team_id != reObj.targetTeamId )
- {
- // Check if targetTeamId is valid for current session account
- for ( var pi = 0; pi < TB.Client.profiles.length; pi++ )
- {
- if ( TB.Client.profiles[ pi ].team_id == reObj.targetTeamId )
- {
- targetProfileId = TB.Client.profiles[ pi ].id;
- isValidTargetId = true;
- break;
- }
- }
-
-
- if ( true === isValidTargetId )
- {
- // If valid
- TB.Service.request( 'Profile', 'change', { profile_id : targetProfileId },
- function( data )
- {
- if ( data && data.session && data.profile && data.profiles && data.teams )
- {
- TB.Client.setSessionData( TB.Client.account, data.profile, data.session, data.profiles, data.teams );
- $( window ).off( 'hashchange' );
- TB.Controller.updateHash( reObj.c, reObj.a, reObj.params );
- location.reload( true );
- }
- }
- );
-
- }
- else
- {
- // If not - redirect to News index
- TB.Controller.do( 'News', 'index' );
- }
- }
- else
- {
- TB.Controller.do( reObj.c, reObj.a, reObj.params );
- }
- }
- else
- {
- // Default case - redirect to News index
- TB.Controller.do( 'News', 'index' );
- }
- }
- };
|