Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular
- .module('security.authorisation')
- .factory('AuthorisationService', [
- '$http',
- 'security.endpoints',
- 'toastr',
- AuthorisationService
- ]);
- function AuthorisationService($http, Endpoints, toastr) {
- var authService = {};
- var _getAuthServiceModel = {
- user: {
- email: '',
- password: '',
- grant_type: 'password'
- }
- };
- // Initialisation.
- function init() {
- authService.initModel = _getAuthServiceModel;
- }
- // Login function.
- authService.login = function (user, success, error) {
- var login_url = Endpoints.getUrl("login");
- $http.post(login_url)
- .success(function (data) {
- }).then(function (temp) {
- console.log("suc");
- }, function (err) {
- console.log("err");
- });
- //toaster.pop('success', "title", "text");
- };
- init(); // Runs on during creation on factory.
- return authService;
- }
- (function () {
- 'use strict';
- angular
- .module('public.login')
- .controller('LoginController', [
- '$scope',
- 'AuthorisationService',
- LoginController
- ]);
- function LoginController($scope, AuthorisationService) {
- $scope.submit = function submit() {
- $scope.app = AuthorisationService.initModel;
- AuthorisationService.login($scope.app)
- .then(function (greeting) {
- alert('Success: ' + greeting);
- }, function (reason) {
- alert('Failed: ' + reason);
- });
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement