Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <reference path="angular.js" />
- /// <reference path="jquery-2.1.3.min.js" />
- var serviceRequester = (function () {
- function getAllAds($scope, $http) {
- //attempt1: gets ALL ads from the db, same as the normal GET
- //var a = JSON.stringify({
- // Authorization: 'Bearer ZnYAvr-V_up0MdXdZTpLrTLU1uoArtImybd6r2aUwzYVMidNonVR7G9s44yW1XMXsIjUkL4OJJOe8a0v8fdUdRc3D90J-goUTKZRBXN1NHIXarpizeMz5AdEfszXMWmYY0tiZEg6QtnGV2DLhC7msi9VOU0f8tZNnCjDRVUa1CZv0yFQEt9SGewTbwIawDhfN3Onqzn7SKIEQbcYWBR21xqQ5CsDT6xLuQ2-Yj-yszR9nduBY8SZrkdQEozj9WOrBIPdCxjOsObbv6X5SnB1ob1JLJiWOTw2WUk8JNBsLQ_Ak3nl9xTYEJVLMRlrcvryLM6te8B1yW9s7mv4EjehxNy7_znlEW0MRK4N7hXoaprLK8_6HwVdZQFu4zWaeU9xEYpJPXm7vtmaj4wvN-lduQZ0I0hCAo_fTNJ65--UaToSw8x-wawAHHBsQ8zdGnhcp5JHdgVVmVVvV76dxpb3KNdMAIpFLLMbn_eQl9a16so'
- //});
- //$http({
- // method: 'GET', url: 'http://localhost:1337/api/ads', headers: a
- //});
- //attempt2: gets ALL ads from the db, same as the normal GET
- //$http.get('http://localhost:1337/api/ads', {
- // headers: {
- // Authorization : "Bearer ZnYAvr-V_up0MdXdZTpLrTLU1uoArtImybd6r2aUwzYVMidNonVR7G9s44yW1XMXsIjUkL4OJJOe8a0v8fdUdRc3D90J-goUTKZRBXN1NHIXarpizeMz5AdEfszXMWmYY0tiZEg6QtnGV2DLhC7msi9VOU0f8tZNnCjDRVUa1CZv0yFQEt9SGewTbwIawDhfN3Onqzn7SKIEQbcYWBR21xqQ5CsDT6xLuQ2-Yj-yszR9nduBY8SZrkdQEozj9WOrBIPdCxjOsObbv6X5SnB1ob1JLJiWOTw2WUk8JNBsLQ_Ak3nl9xTYEJVLMRlrcvryLM6te8B1yW9s7mv4EjehxNy7_znlEW0MRK4N7hXoaprLK8_6HwVdZQFu4zWaeU9xEYpJPXm7vtmaj4wvN-lduQZ0I0hCAo_fTNJ65--UaToSw8x-wawAHHBsQ8zdGnhcp5JHdgVVmVVvV76dxpb3KNdMAIpFLLMbn_eQl9a16so"
- // }
- //}).
- // success(function (data, status, headers, config) {
- // $scope.data = data;
- // console.log("Ads loaded successfully!");
- // }).
- // error(function (data, status, headers, config) {
- // console.log("Ad loading failed!");
- // });
- // working way with jQuery, but when it comes to printing it into the DOM with ng-view, nothing happens
- //
- //var headers;
- //if (sessionStorage.getItem('access_token') != null) {
- // headers = { Authorization: 'Bearer ' + sessionStorage.getItem('access_token') };
- // $.ajax({
- // type: 'GET',
- // url: 'http://localhost:1337/api/user/ads',
- // contentType: "application/json",
- // headers: headers,
- // success: function (data) {
- // alert("done!");
- // $scope.data = data;
- // console.log(data);
- // },
- // error: function (e) {
- // alert(e.error());
- // console.log(e.error());
- // }
- // });
- //}
- //else {
- // $http.get('http://localhost:1337/api/ads').
- // success(function (data, status, headers, config) {
- // $scope.data = data;
- // console.log("Ads loaded successfully!");
- // }).
- // error(function (data, status, headers, config) {
- // console.log("Ad loading failed!");
- // });
- //}
- }
- function login() {
- var un = $('#login-view-username').val();
- var pass = $('#login-view-password').val();
- var btnLogin = $('#login-view-btn');
- var dt = JSON.stringify({ username: un, password: pass });
- $.ajax({
- type: 'POST',
- url: 'http://localhost:1337/api/user/Login',
- contentType: "application/json",
- data: dt,
- success: function (data) {
- saveData(data);
- console.log(data);
- },
- error: function (e) {
- alert(e.error());
- console.log(e.error());
- }
- });
- // window.location.href = '/index.html#/home';
- }
- function register() {
- var username = $("#register-view-username").val();
- var password = $("#register-view-password").val();
- var repeatPassword = $("#register-view-repeat-password").val();
- var name = $("#register-view-name").val();
- var email = $("#register-view-email").val();
- var phone = $("#register-view-phone").val();
- var town = $("#register-view-towns").val();
- var dt = JSON.stringify({
- username: username,
- password: password,
- confirmPassword: repeatPassword,
- name: name,
- email: email,
- phone: phone,
- townId: town
- });
- $.ajax({
- type: 'POST',
- url: 'http://localhost:1337/api/user/register',
- contentType: "application/json",
- data: dt,
- success: function (data) {
- saveData(data);
- console.log(data);
- },
- error: function (e) {
- alert(e.error());
- console.log(e.error());
- }
- });
- }
- function logout() {
- sessionStorage.removeItem("access_token");
- sessionStorage.removeItem("username");
- }
- function saveData(data) {
- sessionStorage.setItem('username', data.username);
- sessionStorage.setItem('access_token', data.access_token);
- }
- return {
- getAds: getAllAds,
- login: login,
- register: register,
- logout: logout
- };
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement