Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Website with new functionality - Waiting for your vision!

Trying to be developer ^^
Loyal Member
Joined
Jul 21, 2010
Messages
1,072
Reaction score
360
Hello,

i belive you guys have nice ideas for website functionality.
I am here, waiting for your purposes - If I add something from your list gonna post progress below.
I am able to add almost everything you wish.
Just give a shoot, who knows maybe when i finish i'll release it here ^^

Functions which will be implemented today:
- News system
- Register
- Login
- Server time status
- TOP 3 Honor players
- Channel status + show ~how many players are online.
- Ranking system
- Saint holder

Everything wrote on smooth code (MVC PHP + Rain TPL)
Dens666 - Website with new functionality - Waiting for your vision! - RaGEZONE Forums

Dens666 - Website with new functionality - Waiting for your vision! - RaGEZONE Forums
 
Junior Spellweaver
Joined
Jan 24, 2013
Messages
183
Reaction score
80
Just give a shoot, who knows maybe when i finish i'll release it here ^^

why people should share their unique ideas for ur webpage if you are not sure you will share it or not :))
 
Joined
Jul 24, 2011
Messages
806
Reaction score
615
Some must have functions idea:

Registration:
->Captcha's, Email Verification (EP8 Client have implemented AuthType for email confirmation checking... (AuthType=3 if i good remember))
->Multiple IP warn system for admins

Login:
->Login / Password Reset / Sub Password Reset

Admin Panel:
->News Manager
->GM Manager
->Online Player management
->Server Log viewer (may you can do a good filterable function with regexp's...)

For players
->Stat adder, Nation changer, EQ viewer, Vote system, Forum <-> Ingame Account merger
->News, NationWar, FC, Valkalitan Timer, Current Proc - Cap rates, Current Running Events
->Community Functions like facebook share, twitter post etc.

I will think about it and edit it if i get any more idea but this is a most important, at least for me.
 
Junior Spellweaver
Joined
Dec 19, 2013
Messages
183
Reaction score
37
Sounds good to my, I'm a total pleb when it comes to that stuff tbh. :D
I really like what DextR suggested in the post above,
and I'm wishing you good luck implementing that & to finish the site the way you want it to.
Can't wait to see the final outcome! :)

€dit: Of course I'll drop some ideas if I get some that DextR did not post already.
 
┌П┐(•_•)┌П┐
Joined
Dec 22, 2009
Messages
958
Reaction score
318
Or just angular altogether :)

Dens666: Drop PHP already. If you are doing this for fun then do it in a cooler language and learn something from it. PHP? not cool.

Off: I'm already doing that, building angularjs website for cabal with an api written in phalcon due its amazing speed. So far so good. I might get to an alpha stage pretty soon. I'm in luv' with the angular xD
 
Trying to be developer ^^
Loyal Member
Joined
Jul 21, 2010
Messages
1,072
Reaction score
360
I have no idea what you have to PHP :O
It's very simple, fast and flexible language.
I can write what I want on it.

I'm not sure if worth for me to learn angular since I don't know JS.
Give me tip :)
 
┌П┐(•_•)┌П┐
Joined
Dec 22, 2009
Messages
958
Reaction score
318
Phalcon its a PHP framework and if you search after benchmarks between frameworks you'll see that phalcon always comes to 1st place because of its amazing speed and because its written in C#, so that this framework always stays in the Ram. Either way, learning angularjs is not that complicated as you may think but once you do, you will never want to come back writting websites in PHP, maybe API, like i do. The purpose and benefit of writting an angularjs website for cabal is that it will load way faster also you can do a lot of stuff like getting real-time data or log in with no refresh and many other. For example, on my website that i am building, i wrote some directives that checks connection of the internet like when you remain with no internet a popup will appear with some specific message and it will not go away until you have internet or idle, like when you are logged in and you are not doing anything on website or not moving the cursor at all, after an x time a popup will appear with some message, after x count of idle you are getting logged out. Also i can show real-time players that are online, rates and many other data like this. Building a cabal website based on angularjs not only that will be fun but you'll really enjoy knowing that you can manipulate everything just the way you want.
And as i said above with my web being close to an alpha stage, i might make a thread about it soon.
Also my API contain most of decodes of binaries from cabal database :).
For authentication, i use basic auth, that generates me a token and after i'm saving it to local storage and with that token i can auth to which request i want to do to the API. Of course that token contains also an expire time.

And PHP ain't fast enough as other frameworks, like for instance, GOLANG, this framework is 10000x times way faster than PHP and can parse large amount of data in milliseconds, ain't kidding.

Plus, separating the website between a FRONTEND and API, is good for security purposes :).
 
Last edited:
┌П┐(•_•)┌П┐
Joined
Dec 22, 2009
Messages
958
Reaction score
318
Thats the authentication service:

Code:
(function() {
  'use strict';

  angular
    .module('hekate.auth.service', [
      'restangular',
      'LocalStorageModule',
      'base64'
    ])
    .service('HekateAuth', HekateAuthService);

  HekateAuthService.$inject = [
    '$rootScope', '$q', '$base64', 'Restangular', 'localStorageService', 'AUTH_EVENTS'
  ];

  function HekateAuthService($rootScope, $q, $base64, Restangular, localStorageService, AUTH_EVENTS) {
    return {
      login: login,
      isAuthenticated: isAuthenticated,
      logout: logout
    };

    function login(params) {
      return $q(function(resolve, reject) {
        if(angular.isObject(params) && angular.isDefined(params.username) && angular.isDefined(params.password)) {
          Restangular
            .one('accounts')
            .one('authenticate')
            .post(null, {}, {}, {Authorization: 'Basic ' + $base64.encode(params.username + ':' + params.password)})
            .then(function(response) {
              localStorageService.set('user', {token: response.token, expires: response.expires});
              if(localStorageService.get('idle')) {
                localStorageService.set('idle', 0);
              }
              $rootScope.$broadcast(AUTH_EVENTS.loginSuccess);
              resolve('You successfully logged in.');
            }, function(error) {
              reject(error);
            });
        } else {
          reject('Username and/or password fields is empty.');
        }
      });
    }

    function isAuthenticated() {
      var user = localStorageService.get('user');
      return $q(function(resolve, reject) {
        if (user && user.expires > Math.floor(Date.now() / 1000)) {
          resolve('You are authenticated.');
        } else {
          reject('You are not authenticated.');
        }
      });
    }

    function logout() {
      localStorageService.remove('user');
      $rootScope.$broadcast(AUTH_EVENTS.logoutSuccess);
      return $q.resolve('You successfully logged out.');
    }
  }
})();
 
Trying to be developer ^^
Loyal Member
Joined
Jul 21, 2010
Messages
1,072
Reaction score
360
Oh Jesus, its looks horrible for me :D
Can you show me one more example? If you want you can send me it on private. I just want to try love this language but all examples looks so strange and hard xd
 
┌П┐(•_•)┌П┐
Joined
Dec 22, 2009
Messages
958
Reaction score
318
Thats not horrible. If you write you the code in angularjs as they say on their docs, when you'll want to minify the code you'll get all sort of errors. What you saw right there, $inject, its structure, is best practices in angular.

Also, before you start learning angularjs, you must know some vanilla javascript too :).
 
Joined
Jul 24, 2011
Messages
806
Reaction score
615
Phalcon is a very promising project. Easy, simple, and very flexible.. AngularJS is very good too. If you are really want to learn a web development than try to understand them and you will get a right way to use harder frameworks like Zend engine... If you can learn them well than you can get a very good job with it. I'm currently working and dont have time for learning...PHP 7 is now get closer to a higher programming languages. Example for me was hard to relearn an sql query with pdo and sadly adodb dont working on php7 yet...
 
Joined
Mar 22, 2009
Messages
1,231
Reaction score
502
Phalcon its a PHP framework and if you search after benchmarks between frameworks you'll see that phalcon always comes to 1st place because of its amazing speed and because its written in C#, so that this framework always stays in the Ram. Either way, learning angularjs is not that complicated as you may think but once you do, you will never want to come back writting websites in PHP, maybe API, like i do. The purpose and benefit of writting an angularjs website for cabal is that it will load way faster also you can do a lot of stuff like getting real-time data or log in with no refresh and many other. For example, on my website that i am building, i wrote some directives that checks connection of the internet like when you remain with no internet a popup will appear with some specific message and it will not go away until you have internet or idle, like when you are logged in and you are not doing anything on website or not moving the cursor at all, after an x time a popup will appear with some message, after x count of idle you are getting logged out. Also i can show real-time players that are online, rates and many other data like this. Building a cabal website based on angularjs not only that will be fun but you'll really enjoy knowing that you can manipulate everything just the way you want.
And as i said above with my web being close to an alpha stage, i might make a thread about it soon.
Also my API contain most of decodes of binaries from cabal database :).
For authentication, i use basic auth, that generates me a token and after i'm saving it to local storage and with that token i can auth to which request i want to do to the API. Of course that token contains also an expire time.

And PHP ain't fast enough as other frameworks, like for instance, GOLANG, this framework is 10000x times way faster than PHP and can parse large amount of data in milliseconds, ain't kidding.

Plus, separating the website between a FRONTEND and API, is good for security purposes :).

You mean separation between frontend and backend. For cabal I think a node.js backend would make much sense since it has lot of intensive I/O operations, mainly reading/writing to database.
Another point is...speed. While nodejs would be extremely fast, probably faster than any PHP framework, that's not all. The code should be easy to maintain, develop, test, manages the complexity well and the list goes on and on. Again node.js is a good candidate. Maybe this PHP framework also, I don't know.
Bottom line is that you need to know what to use for the task you have at hand.
Btw, what? No auth0?

Oh Jesus, its looks horrible for me :D
Can you show me one more example? If you want you can send me it on private. I just want to try love this language but all examples looks so strange and hard xd

Angular is not hard when you know javascript and had touched node.js and the likes, otherwise it can get hairy and it's rather easy to fall to the path of no return. Also there are a couple of angular specific concepts and problems, most notoriously being that the code runs in the browser so you don't ever want to store anything sensitive there and is highly recommended that it runs over https.

Phalcon is a very promising project. Easy, simple, and very flexible.. AngularJS is very good too. If you are really want to learn a web development than try to understand them and you will get a right way to use harder frameworks like Zend engine... If you can learn them well than you can get a very good job with it. I'm currently working and dont have time for learning...PHP 7 is now get closer to a higher programming languages. Example for me was hard to relearn an sql query with pdo and sadly adodb dont working on php7 yet...

PHP is a no go.

More angular code (authentication -> auth0):

Code:
angular.module('authenticationModule')
  .factory('authenticationService', [
    '$q', '$location', '$cookies', 'auth', 'store', 'jwtHelper', 'environmentService',
    function($q, $location, $cookies, auth, store, jwtHelper, environmentService) {
      var authChangedCallbacks = [];


      return {
        logOut: logOut,
        logIn: logIn,
        authenticateAndRedirect: authenticateAndRedirect,
        getIsLoggedIn: getIsLoggedIn,
        addAuthChangeCallback: addAuthChangeCallback,
        processLogin: processLogin,
        processLoginFailure: processLoginFailure,
        getClientId: getClientId,
      };




      function getIsLoggedIn() {
        var token = store.get('smc_auth_token');
        var profile = store.get('smc_auth_profile');
        if (token && !jwtHelper.isTokenExpired(token)) {
          if (!auth.isAuthenticated) {
            return auth.authenticate(profile, token)
              .then(function(result) {
                return result;
              });
          }


          return $q.when({
            profile: profile,
            token: token,
          });
        }
        return $q.when(false);
      }


      function logIn() {
        auth.signin(
          {
            disableSignupAction: true,
          }
        );
      }


      function authenticateAndRedirect(redirectPath) {
        var deferred = $q.defer();


        return getIsLoggedIn()
          .then(function(authData) {
            if (authData) {
              deferred.resolve(authData);
            } else {
              $cookies.put('returnTo', redirectPath);
              logIn();
            }
          })
          .then(function() {
            return deferred.promise ? $q.when(deferred.promise) : $q.reject({authenticated: false});
          });
      }


      function processLogin(profile, idToken) {
        store.set('smc_auth_profile', profile);
        store.set('smc_auth_token', idToken);
        var redirect = $cookies.get('returnTo') || '/';
        $location.url(redirect);
        $cookies.remove('returnTo');


        notifyAll({
          profile: profile,
          token: idToken,
        });
      }


      function processLoginFailure() {
        $location.path('/error');
      }


      function logOut() {
        auth.signout();
        store.remove('smc_auth_profile');
        store.remove('smc_auth_token');
        $location.path('/');


        notifyAll();
      }


      function addAuthChangeCallback(callback) {
        authChangedCallbacks.push(callback);
      }


      function getClientId() {
        if (environmentService.getEnvironment() === 'PRD') {
          return '0lqvllBTphFILz1Awjlxo5stP8C6pMLn';
        }
        return 'fuMX6JViIhikzymPiXEjsHh8dhplEirc';
      }


      function notifyAll(authData) {
        authChangedCallbacks.forEach(function(cb) {
          cb(authData);
        });
      }
    },
  ]);

Code:
angular.module('authenticationModule', ['ngCookies', 'environmentModule']);

Testing is easy. Below are the unit tests for the service above. Integration and acceptance are also easy. you can mime humans clicking on buttons etc.

Code:
describe('Authentication service', function() {
  var authenticationService;
  var $q;
  var auth;
  var store;
  var location;
  var jwtHelper;
  var cookies;


  beforeEach(module('authenticationModule'));


  beforeEach(module(function($provide) {
    auth = {
      isAuthenticated: '',
      authenticate: jasmine.createSpy(),
      signin: jasmine.createSpy(),
      signout: jasmine.createSpy(),
    };
    $provide.value('auth', auth);


    store = {
      get: jasmine.createSpy(),
      set: jasmine.createSpy(),
      remove: jasmine.createSpy(),
    };
    $provide.value('store', store);


    location = {
      path: jasmine.createSpy(),
      url: jasmine.createSpy(),
    };
    $provide.value('$location', location);


    jwtHelper = {
      isTokenExpired: jasmine.createSpy(),
    };
    $provide.value('jwtHelper', jwtHelper);


    cookies = {
      get: jasmine.createSpy(),
      set: jasmine.createSpy(),
      remove: jasmine.createSpy(),
    };
    $provide.value('$cookies', cookies);


    environmentService = {
      getEnvironment: jasmine.createSpy(),
    };
    $provide.value('environmentService', environmentService);
  }));


  beforeEach(inject(function(_authenticationService_, _$q_) {
    authenticationService = _authenticationService_;
    $q = _$q_;
  }));


  it('should determine that the user is unauthenticated if no token is present', function() {
    store.get.and.callFake(
      function() {
        return null;
      });


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeFalsey;
      expect(store.get).toHaveBeenCalledWith('smc_auth_token');
    });




  });


  it('should determine that the user is unauthenticated if the token is expired', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return true;
      });


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeFalsey;
      expect(jwtHelper.isTokenExpired).toHaveBeenCalledWith('myToken');
    });




  });


  it('should determine that the user is authenticated if request is authenticated', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = true;


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeTruthy;
    });
  });


  it('should determine that the user is authenticated if token auth succeeds', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = false;


    auth.authenticate.and.callFake(function() {return $q.when(true);});


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeTruthy;
      expect(auth.authenticate).toHaveBeenCalledWith('myToken', 'myToken');
    });
  });


  it('should return the authentication information if the user is logged in', function() {
    store.get.and.callFake(
      function(key) {
        return key + '_value';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = true;


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeTruthy;
      expect(result.profile).toEqual('profile_value');
      expect(result.token).toEqual('token_value');
    });
  });


  it('should determine that the user is unauthenticated if token authentication fails', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = false;


    auth.authenticate.and.callFake(function() {return $q.when(false);});


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeFalsey;
      expect(auth.authenticate).toHaveBeenCalledWith('myToken', 'myToken');
    });
  });


  it('should sign out and clear the tokens when logging out', function() {
    authenticationService.logOut();


    expect(auth.signout).toHaveBeenCalled();
    expect(store.remove).toHaveBeenCalledWith('smc_auth_token');
    expect(store.remove).toHaveBeenCalledWith('smc_auth_profile');
  });


  it('should redirect to the home page when logging out', function() {
    authenticationService.logOut();
    expect(location.path).toHaveBeenCalledWith('/');
  });


  it('should call any callbacks when logging out', function() {
    var foo = 0;
    authenticationService.addAuthChangeCallback(function() {
      foo = 1;
    });


    authenticationService.logOut();
    expect(foo).toEqual(1);
  });


  it('should continue instead of re-logging in if the user is already authenticated', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = true;


    authenticationService.authenticateAndRedirect().then(function(status) {
      expect(status).toBeTruthy();
    });
  });


  it('should stop and redirect to the login page if the user is not authenticated', function() {
    store.get.and.callFake(
      function() {
        return null;
      });


    authenticationService.authenticateAndRedirect().then(function(status) {
      expect(status).toBeUndefined();
      expect(auth.signin).toHaveBeenCalled();
    });
  });


  it('should call the authentication provider when logging in', function() {
    authenticationService.logIn();
    expect(auth.signin).toHaveBeenCalledWith({disableSignupAction: true,});
  });


  it('should redirect to an error page if login fails', function() {
    authenticationService.processLoginFailure();
    expect(location.path).toHaveBeenCalledWith('/error');
  });


  it('should save the auth tokens when login is successful', function() {
    authenticationService.processLogin('profile1', 'token2');


    expect(store.set).toHaveBeenCalledWith('smc_auth_profile', 'profile1');
    expect(store.set).toHaveBeenCalledWith('smc_auth_token', 'token2');
  });


  it('should redirect, if specified, and then clear the cookie', function() {
    cookies.get.and.callFake(function() {
      return '/foo';
    });


    authenticationService.processLogin();


    expect(location.url).toHaveBeenCalledWith('/foo');
    expect(cookies.remove).toHaveBeenCalledWith('returnTo');
  });


  it('should use the prod authentication app in production', function() {
    environmentService.getEnvironment.and.callFake(function() {
      return 'PRD';
    });


    expect(authenticationService.getClientId()).toEqual('0lqvllBTphFILz1Awjlxo5stP8C6pMLn');
  });


  it('should use the non-prod authentication app outside production', function() {
    environmentService.getEnvironment.and.callFake(function() {
      return 'TST';
    });


    expect(authenticationService.getClientId()).toEqual('fuMX6JViIhikzymPiXEjsHh8dhplEirc');
  });
});
 
Last edited:
┌П┐(•_•)┌П┐
Joined
Dec 22, 2009
Messages
958
Reaction score
318
You mean separation between frontend and backend. For cabal I think a node.js backend would make much sense since it has lot of intensive I/O operations, mainly reading/writing to database.
Another point is...speed. While nodejs would be extremely fast, probably faster than any PHP framework, that's not all. The code should be easy to maintain, develop, test, manages the complexity well and the list goes on and on. Again node.js is a good candidate. Maybe this PHP framework also, I don't know.
Bottom line is that you need to know what to use for the task you have at hand.
Btw, what? No auth0?



Angular is not hard when you know javascript and had touched node.js and the likes, otherwise it can get hairy and it's rather easy to fall to the path of no return. Also there are a couple of angular specific concepts and problems, most notoriously being that the code runs in the browser so you don't ever want to store anything sensitive there and is highly recommended that it runs over https.



PHP is a no go.

More angular code (authentication -> auth0):

Code:
angular.module('authenticationModule')
  .factory('authenticationService', [
    '$q', '$location', '$cookies', 'auth', 'store', 'jwtHelper', 'environmentService',
    function($q, $location, $cookies, auth, store, jwtHelper, environmentService) {
      var authChangedCallbacks = [];


      return {
        logOut: logOut,
        logIn: logIn,
        authenticateAndRedirect: authenticateAndRedirect,
        getIsLoggedIn: getIsLoggedIn,
        addAuthChangeCallback: addAuthChangeCallback,
        processLogin: processLogin,
        processLoginFailure: processLoginFailure,
        getClientId: getClientId,
      };




      function getIsLoggedIn() {
        var token = store.get('smc_auth_token');
        var profile = store.get('smc_auth_profile');
        if (token && !jwtHelper.isTokenExpired(token)) {
          if (!auth.isAuthenticated) {
            return auth.authenticate(profile, token)
              .then(function(result) {
                return result;
              });
          }


          return $q.when({
            profile: profile,
            token: token,
          });
        }
        return $q.when(false);
      }


      function logIn() {
        auth.signin(
          {
            disableSignupAction: true,
          }
        );
      }


      function authenticateAndRedirect(redirectPath) {
        var deferred = $q.defer();


        return getIsLoggedIn()
          .then(function(authData) {
            if (authData) {
              deferred.resolve(authData);
            } else {
              $cookies.put('returnTo', redirectPath);
              logIn();
            }
          })
          .then(function() {
            return deferred.promise ? $q.when(deferred.promise) : $q.reject({authenticated: false});
          });
      }


      function processLogin(profile, idToken) {
        store.set('smc_auth_profile', profile);
        store.set('smc_auth_token', idToken);
        var redirect = $cookies.get('returnTo') || '/';
        $location.url(redirect);
        $cookies.remove('returnTo');


        notifyAll({
          profile: profile,
          token: idToken,
        });
      }


      function processLoginFailure() {
        $location.path('/error');
      }


      function logOut() {
        auth.signout();
        store.remove('smc_auth_profile');
        store.remove('smc_auth_token');
        $location.path('/');


        notifyAll();
      }


      function addAuthChangeCallback(callback) {
        authChangedCallbacks.push(callback);
      }


      function getClientId() {
        if (environmentService.getEnvironment() === 'PRD') {
          return '0lqvllBTphFILz1Awjlxo5stP8C6pMLn';
        }
        return 'fuMX6JViIhikzymPiXEjsHh8dhplEirc';
      }


      function notifyAll(authData) {
        authChangedCallbacks.forEach(function(cb) {
          cb(authData);
        });
      }
    },
  ]);

Code:
angular.module('authenticationModule', ['ngCookies', 'environmentModule']);

Testing is easy. Below are the unit tests for the service above. Integration and acceptance are also easy. you can mime humans clicking on buttons etc.

Code:
describe('Authentication service', function() {
  var authenticationService;
  var $q;
  var auth;
  var store;
  var location;
  var jwtHelper;
  var cookies;


  beforeEach(module('authenticationModule'));


  beforeEach(module(function($provide) {
    auth = {
      isAuthenticated: '',
      authenticate: jasmine.createSpy(),
      signin: jasmine.createSpy(),
      signout: jasmine.createSpy(),
    };
    $provide.value('auth', auth);


    store = {
      get: jasmine.createSpy(),
      set: jasmine.createSpy(),
      remove: jasmine.createSpy(),
    };
    $provide.value('store', store);


    location = {
      path: jasmine.createSpy(),
      url: jasmine.createSpy(),
    };
    $provide.value('$location', location);


    jwtHelper = {
      isTokenExpired: jasmine.createSpy(),
    };
    $provide.value('jwtHelper', jwtHelper);


    cookies = {
      get: jasmine.createSpy(),
      set: jasmine.createSpy(),
      remove: jasmine.createSpy(),
    };
    $provide.value('$cookies', cookies);


    environmentService = {
      getEnvironment: jasmine.createSpy(),
    };
    $provide.value('environmentService', environmentService);
  }));


  beforeEach(inject(function(_authenticationService_, _$q_) {
    authenticationService = _authenticationService_;
    $q = _$q_;
  }));


  it('should determine that the user is unauthenticated if no token is present', function() {
    store.get.and.callFake(
      function() {
        return null;
      });


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeFalsey;
      expect(store.get).toHaveBeenCalledWith('smc_auth_token');
    });




  });


  it('should determine that the user is unauthenticated if the token is expired', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return true;
      });


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeFalsey;
      expect(jwtHelper.isTokenExpired).toHaveBeenCalledWith('myToken');
    });




  });


  it('should determine that the user is authenticated if request is authenticated', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = true;


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeTruthy;
    });
  });


  it('should determine that the user is authenticated if token auth succeeds', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = false;


    auth.authenticate.and.callFake(function() {return $q.when(true);});


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeTruthy;
      expect(auth.authenticate).toHaveBeenCalledWith('myToken', 'myToken');
    });
  });


  it('should return the authentication information if the user is logged in', function() {
    store.get.and.callFake(
      function(key) {
        return key + '_value';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = true;


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeTruthy;
      expect(result.profile).toEqual('profile_value');
      expect(result.token).toEqual('token_value');
    });
  });


  it('should determine that the user is unauthenticated if token authentication fails', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = false;


    auth.authenticate.and.callFake(function() {return $q.when(false);});


    authenticationService.getIsLoggedIn().then(function(result) {
      expect(result).toBeFalsey;
      expect(auth.authenticate).toHaveBeenCalledWith('myToken', 'myToken');
    });
  });


  it('should sign out and clear the tokens when logging out', function() {
    authenticationService.logOut();


    expect(auth.signout).toHaveBeenCalled();
    expect(store.remove).toHaveBeenCalledWith('smc_auth_token');
    expect(store.remove).toHaveBeenCalledWith('smc_auth_profile');
  });


  it('should redirect to the home page when logging out', function() {
    authenticationService.logOut();
    expect(location.path).toHaveBeenCalledWith('/');
  });


  it('should call any callbacks when logging out', function() {
    var foo = 0;
    authenticationService.addAuthChangeCallback(function() {
      foo = 1;
    });


    authenticationService.logOut();
    expect(foo).toEqual(1);
  });


  it('should continue instead of re-logging in if the user is already authenticated', function() {
    store.get.and.callFake(
      function() {
        return 'myToken';
      });


    jwtHelper.isTokenExpired.and.callFake(
      function() {
        return false;
      });


    auth.isAuthenticated = true;


    authenticationService.authenticateAndRedirect().then(function(status) {
      expect(status).toBeTruthy();
    });
  });


  it('should stop and redirect to the login page if the user is not authenticated', function() {
    store.get.and.callFake(
      function() {
        return null;
      });


    authenticationService.authenticateAndRedirect().then(function(status) {
      expect(status).toBeUndefined();
      expect(auth.signin).toHaveBeenCalled();
    });
  });


  it('should call the authentication provider when logging in', function() {
    authenticationService.logIn();
    expect(auth.signin).toHaveBeenCalledWith({disableSignupAction: true,});
  });


  it('should redirect to an error page if login fails', function() {
    authenticationService.processLoginFailure();
    expect(location.path).toHaveBeenCalledWith('/error');
  });


  it('should save the auth tokens when login is successful', function() {
    authenticationService.processLogin('profile1', 'token2');


    expect(store.set).toHaveBeenCalledWith('smc_auth_profile', 'profile1');
    expect(store.set).toHaveBeenCalledWith('smc_auth_token', 'token2');
  });


  it('should redirect, if specified, and then clear the cookie', function() {
    cookies.get.and.callFake(function() {
      return '/foo';
    });


    authenticationService.processLogin();


    expect(location.url).toHaveBeenCalledWith('/foo');
    expect(cookies.remove).toHaveBeenCalledWith('returnTo');
  });


  it('should use the prod authentication app in production', function() {
    environmentService.getEnvironment.and.callFake(function() {
      return 'PRD';
    });


    expect(authenticationService.getClientId()).toEqual('0lqvllBTphFILz1Awjlxo5stP8C6pMLn');
  });


  it('should use the non-prod authentication app outside production', function() {
    environmentService.getEnvironment.and.callFake(function() {
      return 'TST';
    });


    expect(authenticationService.getClientId()).toEqual('fuMX6JViIhikzymPiXEjsHh8dhplEirc');
  });
});
emi, well, thanks for your feedback also there is a really nice piece of auth code :). I might give it a try to node.js too. But i want to head to GOLANG as it seems is way faster than node.js :).
 
Trying to be developer ^^
Loyal Member
Joined
Jul 21, 2010
Messages
1,072
Reaction score
360
Wooow, I read some articles about AngularJS and its veeeery nice. I going to try learn it. I am just afraid of taking objects from database and connection with msswl but we will see. Thanks guys so much I going to start over again using angular. You think use pure angular is good idea?
 
┌П┐(•_•)┌П┐
Joined
Dec 22, 2009
Messages
958
Reaction score
318
Well you have to write some API firstly before you start writing the website in angularjs. In what language you'll write the API, well thats up to you.
 
Back
Top