Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 
  2. function authSignInOnLoad() {
  3.     authSignInInitControls();
  4. }
  5.  
  6. function authSignUpOnLoad() {
  7.     authSignUpInitControls();
  8. }
  9.  
  10. function authProfileActivationOnLoad() {
  11.     authProfileActivationInitControls();
  12. }
  13.  
  14. function authRecoveryOnLoad() {
  15.     authRecoveryInitControls();
  16. }
  17.  
  18. function authSignInInitControls() {
  19.     $('#signInInputs input').keyup(function (e) {
  20.         if (e.keyCode === 13) {
  21.             $('#Button-signIn').trigger('click');
  22.         }
  23.     });
  24.  
  25.     $('.facebook')
  26.     .click(function () {
  27.             authFacebookLogin();
  28.         });
  29.     $('.google')
  30.     .click(function () {
  31.         //getInfo();
  32.     });
  33.  
  34.     $('#Button-signIn').click(function () {
  35.         FieldErrors.RemoveAllFieldErrors();
  36.         var email = $('#Email-singIn').val();
  37.         var password = $('#Password-singIn').val();
  38.         authAuthenticate(email, password);
  39.         return false;
  40.     });
  41. }
  42.  
  43. function authSignUpInitControls(){
  44.     $('#signUpInputs input').keyup(function (e) {
  45.         if (e.keyCode === 13) {
  46.             $('#Button-signUp').trigger('click');
  47.         }
  48.     });
  49.  
  50.     $('#Button-signUp').click(function () {
  51.         FieldErrors.RemoveAllFieldErrors();
  52.         globals.temp = Math.floor((Math.random() * 1000000) + 100000);
  53.         globals.temp = +(globals.temp.toString().slice(0, 6));
  54.         $.ajax({
  55.             type: 'POST',
  56.             url: globals.apiUrl + 'registration',
  57.             data: {
  58.                 Email: $('#Email-signUp').val(),
  59.                 Password: $('#Password-signUp').val(),
  60.                 Firstname: $('#Firstname-signUp').val(),
  61.                 Lastname: $('#Lastname-signUp').val(),
  62.                 ActivationCode: globals.temp
  63.             },
  64.             success: function (response) {
  65.                 globals.mainView.router.loadPage('profileActivation.html');
  66.             }
  67.         });
  68.  
  69.         return false;
  70.     });
  71. }
  72.  
  73. function authProfileActivationInitControls() {
  74.  
  75.     $('#Code-profileActivation').keyup(function (e) {
  76.         if (e.keyCode === 13) {
  77.             $('#Button-profileActivation').trigger('click');
  78.         }
  79.     });
  80.  
  81.     $('#Button-profileActivation').click(function () {
  82.         var email = $('#Email-signUp').val();
  83.         FieldErrors.RemoveAllFieldErrors();
  84.         if ($('#Code-profileActivation').val() == globals.temp) {
  85.             $.ajax({
  86.                 type: 'POST',
  87.                 url: globals.apiUrl + 'activation',
  88.                 data: { Email: email},
  89.                 success: function (response) {
  90.                     globals.temp = null;
  91.                     authAuthenticate(email, $('#Password-signUp').val());
  92.                 }
  93.             });
  94.         } else {
  95.             $(".terms-block").addClass("hidden");
  96.             FieldErrors.Init({
  97.                 type: FieldErrors.GetFormValidationType() == 'auth' ? 'auth' : null,
  98.                 errors: [{
  99.                     Code: "1003.01",
  100.                     ErrorMessage: globals.messages.validationCodeIsNotCorrect
  101.                 }]
  102.             });
  103.             FieldErrors.ShowAllFieldErrors();
  104.         }
  105.  
  106.         return false;
  107.     });
  108.  
  109. }
  110.        
  111. function authRecoveryInitControls() {
  112.  
  113.     $('#Email-recovery').keyup(function (e) {
  114.         if (e.keyCode === 13) {
  115.             $('#ButtonFirst-recovery').trigger('click');
  116.         }
  117.     });
  118.  
  119.     $('#ButtonFirst-recovery').click(function () {
  120.  
  121.         FieldErrors.RemoveAllFieldErrors();
  122.         globals.temp = Math.floor((Math.random() * 1000000) + 100000);
  123.         globals.temp = +(globals.temp.toString().slice(0, 6));
  124.         $.ajax({
  125.             type: 'POST',
  126.             url: globals.apiUrl + 'password-recover',
  127.             data: {
  128.                 Email: $('#Email-recovery').val(),
  129.                 ActivationCode: globals.temp
  130.             },
  131.             success: function (response) {
  132.                 globals.F7.accordionOpen('[data-step="2"]');
  133.                 $(".terms-block").removeClass("hidden");
  134.                 $(".terms-block p").html("Recovery code has been sent to " + $('#Email-recovery').val());
  135.             }
  136.         });
  137.  
  138.         return false;
  139.     });
  140.  
  141.  
  142.     $('#recoveryInputs input').keyup(function (e) {
  143.         if (e.keyCode === 13) {
  144.             $('#ButtonSecond-recovery').trigger('click');
  145.         }
  146.     });
  147.  
  148.     $('#ButtonSecond-recovery').click(function () {
  149.  
  150.         FieldErrors.RemoveAllFieldErrors();
  151.  
  152.         if ($('#Code-recovery').val() == globals.temp) {
  153.             $.ajax({
  154.                 type: 'POST',
  155.                 url: globals.apiUrl + 'password-recover-activation',
  156.                 data: {
  157.                     Email: $('#Email-recovery').val(),
  158.                     ActivationCode: $('#Code-recovery').val(),
  159.                     Password: $('#Password-recovery').val(),
  160.                     RepeatPassword: $('#RepeatPassword-recovery').val()
  161.                 },
  162.                 success: function (response) {
  163.                     globals.temp = null;
  164.                     authAuthenticate($('#Email-recovery').val(), $('#Password-recovery').val());
  165.                 }
  166.             });
  167.         } else {
  168.             $(".terms-block").addClass("hidden");
  169.             FieldErrors.Init({
  170.                 type: FieldErrors.GetFormValidationType() == 'auth' ? 'auth' : null,
  171.                 errors: [{
  172.                     Code: "1003.01",
  173.                     ErrorMessage: globals.messages.validationCodeIsNotCorrect
  174.                 }]
  175.             });
  176.             FieldErrors.ShowAllFieldErrors();
  177.         }
  178.  
  179.         return false;
  180.     });
  181. }
  182.  
  183.  
  184. function authAuthenticate(email, password) {
  185.     if (email && password) {
  186.         $.ajax({
  187.             type: 'POST',
  188.             url: globals.apiUrl + 'auth/login',
  189.             data: {
  190.                 Email: email,
  191.                 Password: password
  192.             },
  193.             success: function (response) {
  194.                 onAuthSuccess(response, email, password);
  195.             }
  196.         });
  197.     }
  198. }
  199.  
  200. function onAuthSuccess(response,email,password) {
  201.     SignalR.init().start();
  202.     globals.userId = response.Data.UserId;
  203.     globals.userObject = response.Data.UserObject;
  204.     globals.userObject.Avatar = globals.getAvatarSrc(globals.userObject.Avatar);
  205.     globals.userObject.mandala = response.Data.Mandala;
  206.     globals.accessToken = response.Data.AccessToken;
  207.     globals.deviceWidth = $(document).width();
  208.     if (email&&password) {
  209.         globals.saveUserToStorage(email, password);
  210.     } else {
  211.         globals.removeUserFromStorage();
  212.     }
  213.     $('input').blur();
  214.     homeInsertCircles();
  215.     getAllNotifications(true);
  216.     globals.mainView.router.loadPage('home.html');
  217. }
  218.  
  219.      // Defaults to sessionStorage for storing the Facebook token
  220.     openFB.init({
  221.         appId: globals.facebookAppId,
  222.         cordovaOAuthRedirectURL: 'http://odeliz.63bits.com/Content/login_success.html'
  223.     });
  224. //  Uncomment the line below to store the Facebook token in localStorage instead of sessionStorage
  225. //  openFB.init({appId: 'YOUR_FB_APP_ID', tokenStore: window.localStorage});
  226. function authFacebookLogin() {
  227.     openFB.login(authFacebookAuthorization, { scope: 'email,user_birthday' });
  228. }
  229.  
  230. function authFacebookAuthorization(fbResponse) {
  231.     if (fbResponse && fbResponse.status == 'connected') {
  232.         openFB.api({
  233.             path: '/me',
  234.             success: function (user) {
  235.                 $.ajax({
  236.                     type: "POST",
  237.                     url: globals.apiUrl + 'auth/fb-auth/',
  238.                     data: {
  239.                         FacebookID: user.id,
  240.                         FacebookAccessToken: fbResponse.authResponse.accessToken,
  241.                         Email: user.email
  242.                         //ProfileImageName: "//graph.facebook.com/" + user.id + "/picture"
  243.                     },
  244.                     dataType: 'json',
  245.                     success: function (response) {
  246.                         if (response.IsSuccess) {
  247.                             switch (response.Data.StatusCode) {
  248.                                 case globals.facebookAuthStatusCodes.new_user:
  249.                                     {
  250.                                         globals.mainView.router.loadPage('signUp.html');
  251.                                         setTimeout(function() {
  252.                                                 $('#Email-signUp').val(user.email);
  253.                                                 $('#Firstname-signUp').val(user.first_name);
  254.                                                 $('#Lastname-signUp').val(user.last_name);
  255.                                                 $('#Password-signUp').focus();
  256.                                             },
  257.                                             2000);
  258.                                         break;
  259.                                     }
  260.                                 case globals.facebookAuthStatusCodes.without_fb:
  261.                                     {
  262.                                         if (response.Data) {
  263.                                             onAuthSuccess(response);
  264.                                         }
  265.                                         break;
  266.                                     }
  267.                                 case globals.facebookAuthStatusCodes.with_fb:
  268.                                     {
  269.                                         if (response.Data) {
  270.                                             console.log(response);
  271.                                             onAuthSuccess(response);
  272.                                         }
  273.                                         break;
  274.                                     }
  275.                             }
  276.                         } else {
  277.                             alert(response.Data.Message);
  278.                         }
  279.                     }
  280.                 });
  281.             },
  282.             error: function() {
  283.                
  284.             }
  285.         });
  286.     }
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement