Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
-
- function authSignInOnLoad() {
- authSignInInitControls();
- }
- function authSignUpOnLoad() {
- authSignUpInitControls();
- }
- function authProfileActivationOnLoad() {
- authProfileActivationInitControls();
- }
- function authRecoveryOnLoad() {
- authRecoveryInitControls();
- }
- function authSignInInitControls() {
- $('#signInInputs input').keyup(function (e) {
- if (e.keyCode === 13) {
- $('#Button-signIn').trigger('click');
- }
- });
- $('.facebook')
- .click(function () {
- authFacebookLogin();
- });
- $('.google')
- .click(function () {
- //getInfo();
- });
- $('#Button-signIn').click(function () {
- FieldErrors.RemoveAllFieldErrors();
- var email = $('#Email-singIn').val();
- var password = $('#Password-singIn').val();
- authAuthenticate(email, password);
- return false;
- });
- }
- function authSignUpInitControls(){
- $('#signUpInputs input').keyup(function (e) {
- if (e.keyCode === 13) {
- $('#Button-signUp').trigger('click');
- }
- });
- $('#Button-signUp').click(function () {
- FieldErrors.RemoveAllFieldErrors();
- globals.temp = Math.floor((Math.random() * 1000000) + 100000);
- globals.temp = +(globals.temp.toString().slice(0, 6));
- $.ajax({
- type: 'POST',
- url: globals.apiUrl + 'registration',
- data: {
- Email: $('#Email-signUp').val(),
- Password: $('#Password-signUp').val(),
- Firstname: $('#Firstname-signUp').val(),
- Lastname: $('#Lastname-signUp').val(),
- ActivationCode: globals.temp
- },
- success: function (response) {
- globals.mainView.router.loadPage('profileActivation.html');
- }
- });
- return false;
- });
- }
- function authProfileActivationInitControls() {
- $('#Code-profileActivation').keyup(function (e) {
- if (e.keyCode === 13) {
- $('#Button-profileActivation').trigger('click');
- }
- });
- $('#Button-profileActivation').click(function () {
- var email = $('#Email-signUp').val();
- FieldErrors.RemoveAllFieldErrors();
- if ($('#Code-profileActivation').val() == globals.temp) {
- $.ajax({
- type: 'POST',
- url: globals.apiUrl + 'activation',
- data: { Email: email},
- success: function (response) {
- globals.temp = null;
- authAuthenticate(email, $('#Password-signUp').val());
- }
- });
- } else {
- $(".terms-block").addClass("hidden");
- FieldErrors.Init({
- type: FieldErrors.GetFormValidationType() == 'auth' ? 'auth' : null,
- errors: [{
- Code: "1003.01",
- ErrorMessage: globals.messages.validationCodeIsNotCorrect
- }]
- });
- FieldErrors.ShowAllFieldErrors();
- }
- return false;
- });
- }
- function authRecoveryInitControls() {
- $('#Email-recovery').keyup(function (e) {
- if (e.keyCode === 13) {
- $('#ButtonFirst-recovery').trigger('click');
- }
- });
- $('#ButtonFirst-recovery').click(function () {
- FieldErrors.RemoveAllFieldErrors();
- globals.temp = Math.floor((Math.random() * 1000000) + 100000);
- globals.temp = +(globals.temp.toString().slice(0, 6));
- $.ajax({
- type: 'POST',
- url: globals.apiUrl + 'password-recover',
- data: {
- Email: $('#Email-recovery').val(),
- ActivationCode: globals.temp
- },
- success: function (response) {
- globals.F7.accordionOpen('[data-step="2"]');
- $(".terms-block").removeClass("hidden");
- $(".terms-block p").html("Recovery code has been sent to " + $('#Email-recovery').val());
- }
- });
- return false;
- });
- $('#recoveryInputs input').keyup(function (e) {
- if (e.keyCode === 13) {
- $('#ButtonSecond-recovery').trigger('click');
- }
- });
- $('#ButtonSecond-recovery').click(function () {
- FieldErrors.RemoveAllFieldErrors();
- if ($('#Code-recovery').val() == globals.temp) {
- $.ajax({
- type: 'POST',
- url: globals.apiUrl + 'password-recover-activation',
- data: {
- Email: $('#Email-recovery').val(),
- ActivationCode: $('#Code-recovery').val(),
- Password: $('#Password-recovery').val(),
- RepeatPassword: $('#RepeatPassword-recovery').val()
- },
- success: function (response) {
- globals.temp = null;
- authAuthenticate($('#Email-recovery').val(), $('#Password-recovery').val());
- }
- });
- } else {
- $(".terms-block").addClass("hidden");
- FieldErrors.Init({
- type: FieldErrors.GetFormValidationType() == 'auth' ? 'auth' : null,
- errors: [{
- Code: "1003.01",
- ErrorMessage: globals.messages.validationCodeIsNotCorrect
- }]
- });
- FieldErrors.ShowAllFieldErrors();
- }
- return false;
- });
- }
- function authAuthenticate(email, password) {
- if (email && password) {
- $.ajax({
- type: 'POST',
- url: globals.apiUrl + 'auth/login',
- data: {
- Email: email,
- Password: password
- },
- success: function (response) {
- onAuthSuccess(response, email, password);
- }
- });
- }
- }
- function onAuthSuccess(response,email,password) {
- SignalR.init().start();
- globals.userId = response.Data.UserId;
- globals.userObject = response.Data.UserObject;
- globals.userObject.Avatar = globals.getAvatarSrc(globals.userObject.Avatar);
- globals.userObject.mandala = response.Data.Mandala;
- globals.accessToken = response.Data.AccessToken;
- globals.deviceWidth = $(document).width();
- if (email&&password) {
- globals.saveUserToStorage(email, password);
- } else {
- globals.removeUserFromStorage();
- }
- $('input').blur();
- homeInsertCircles();
- getAllNotifications(true);
- globals.mainView.router.loadPage('home.html');
- }
- // Defaults to sessionStorage for storing the Facebook token
- openFB.init({
- appId: globals.facebookAppId,
- cordovaOAuthRedirectURL: 'http://odeliz.63bits.com/Content/login_success.html'
- });
- // Uncomment the line below to store the Facebook token in localStorage instead of sessionStorage
- // openFB.init({appId: 'YOUR_FB_APP_ID', tokenStore: window.localStorage});
- function authFacebookLogin() {
- openFB.login(authFacebookAuthorization, { scope: 'email,user_birthday' });
- }
- function authFacebookAuthorization(fbResponse) {
- if (fbResponse && fbResponse.status == 'connected') {
- openFB.api({
- path: '/me',
- success: function (user) {
- $.ajax({
- type: "POST",
- url: globals.apiUrl + 'auth/fb-auth/',
- data: {
- FacebookID: user.id,
- FacebookAccessToken: fbResponse.authResponse.accessToken,
- Email: user.email
- //ProfileImageName: "//graph.facebook.com/" + user.id + "/picture"
- },
- dataType: 'json',
- success: function (response) {
- if (response.IsSuccess) {
- switch (response.Data.StatusCode) {
- case globals.facebookAuthStatusCodes.new_user:
- {
- globals.mainView.router.loadPage('signUp.html');
- setTimeout(function() {
- $('#Email-signUp').val(user.email);
- $('#Firstname-signUp').val(user.first_name);
- $('#Lastname-signUp').val(user.last_name);
- $('#Password-signUp').focus();
- },
- 2000);
- break;
- }
- case globals.facebookAuthStatusCodes.without_fb:
- {
- if (response.Data) {
- onAuthSuccess(response);
- }
- break;
- }
- case globals.facebookAuthStatusCodes.with_fb:
- {
- if (response.Data) {
- console.log(response);
- onAuthSuccess(response);
- }
- break;
- }
- }
- } else {
- alert(response.Data.Message);
- }
- }
- });
- },
- error: function() {
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement