Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startApp() {
- sessionStorage.clear();
- showHideMenuLinks();
- showView('viewHome');
- $("#linkHome").click(showHomeView);
- $("#formLogin").submit(loginUser);
- $("form").submit(function(e) { e.preventDefault() });
- $("#linkHome").click(showHomeView);
- $("#linkLogin").click(showLoginView);
- $("#linkRegister").click(showRegisterView);
- $("#linkListBooks").click(listBooks);
- $("#linkCreateBook").click(showCreateBookView);
- $("#linkLogout").click(logoutUser);
- $("#buttonLoginUser").click(loginUser);
- $("#buttonRegisterUser").click(registerUser);
- $("#buttonCreateBook").click(createBook);
- $("#buttonEditBook").click(editBook);
- $("#infoBox, #errorBox").click(function() {
- $(this).fadeOut();
- });
- $(document).on({
- ajaxStart: function() { $("#loadingBox").show() },
- ajaxStop: function() { $("#loadingBox").hide() }
- });
- const kinveyBaseUrl = "https://baas.kinvey.com/";
- const kinveyAppKey = "kid_rJgqxWyml";
- const kinveyAppSecret = "a69a6d3222ce4cca9f4d2c075d6090fb";
- const kinveyAppAuthHeaders = {
- 'Authorization': "Basic " +
- btoa(kinveyAppKey + ":" + kinveyAppSecret)
- };
- function showHideMenuLinks() {
- $("#linkHome").show();
- if (sessionStorage.getItem('authToken')) {
- // We have logged in user
- $("#linkLogin").hide();
- $("#linkRegister").hide();
- $("#linkListBooks").show();
- $("#linkCreateBook").show();
- $("#linkLogout").show();
- } else {
- // No logged in user
- $("#linkLogin").show();
- $("#linkRegister").show();
- $("#linkListBooks").hide();
- $("#linkCreateBook").hide();
- $("#linkLogout").hide();
- }
- }
- function showView(viewName) {
- $('main > section').hide();
- $('#' + viewName).show();
- }
- function showHomeView() {
- showView('viewHome');
- }
- function showLoginView() {
- showView('viewLogin');
- $('#formLogin').trigger('reset');
- }
- function showRegisterView() {
- $('#formRegister').trigger('reset');
- showView('viewRegister');
- }
- function listBooks() {
- }
- function showCreateBookView() {
- $('#formCreateBook').trigger('reset');
- showView('viewCreateBook');
- }
- function logoutUser() {
- }
- function loginUser() {
- }
- function registerUser() {
- let userData = {
- username: $('#formRegister input[name=username]').val(),
- password: $('#formRegister input[name=passwd]').val()
- };
- console.dir(userData)
- $.ajax({
- method: "POST",
- url: kinveyBaseUrl + "user/" + kinveyAppKey + "/",
- headers: kinveyAppAuthHeaders,
- data: Json.stringify(userData),
- contentType: 'application/json',
- success: registerSuccess,
- error: handleAjaxError
- });
- function registerSuccess() {
- alert('ok');
- //saveAuthInSession(userInfo);
- //showHideMenuLinks();
- //listBooks();
- //showInfo('User registration successful.');
- }
- }
- function createBook() {
- }
- function editBook() {
- }
- function handleAjaxError() {
- alert('error')
- }
- }
Add Comment
Please, Sign In to add comment