Advertisement
Guest User

Untitled

a guest
May 15th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <li ng-show="currentUser">
  2. <a ui-sref="report" ui-sref-active="active">Report</a>
  3. </li>
  4.  
  5. .config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  6. $stateProvider
  7. .state('user-report', {
  8. url: '/user-report',
  9. templateUrl: 'views/user-report.html',
  10. controller: 'UserReportController',
  11. authenticate: true
  12. })
  13. .state('report', {
  14. url: '/report',
  15. templateUrl: 'views/report.html',
  16. controller: 'ReportController',
  17. authenticate: true
  18. });
  19.  
  20. angular
  21. .module('app')
  22. .controller('AuthLoginController', ['$scope', 'AuthService', '$state',
  23. function($scope, AuthService, $state) {
  24. $scope.user = {
  25. email: '',
  26. password: ''
  27. };
  28.  
  29. $scope.login = function() {
  30. AuthService.login($scope.user.email, $scope.user.password)
  31. .then(function() {
  32. $state.go('report');
  33. });
  34. };
  35. }])
  36. .controller('AuthLogoutController', ['$scope', 'AuthService', '$state',
  37. function($scope, AuthService, $state) {
  38. AuthService.logout()
  39. .then(function() {
  40. $state.go('contact');
  41. });
  42. }]);
  43.  
  44. angular
  45. .module('app')
  46. .factory('AuthService', ['Viewer', '$q', '$rootScope', function(User, $q,
  47. $rootScope) {
  48. function login(email, password) {
  49. return User
  50. .login({email: email, password: password})
  51. .$promise
  52. .then(function(response) {
  53. $rootScope.currentUser = {
  54. id: response.user.id,
  55. tokenId: response.id,
  56. email: email
  57. };
  58. });
  59. }
  60.  
  61. function logout() {
  62. return User
  63. .logout()
  64. .$promise
  65. .then(function() {
  66. $rootScope.currentUser = null;
  67. });
  68. }
  69.  
  70. return {
  71. login: login,
  72. logout: logout
  73. };
  74. }]);
  75.  
  76. var async = require('async');
  77.  
  78. module.exports = function(app) {
  79. //data sources
  80. var db = app.dataSources.db;
  81. //create all models
  82. async.parallel({
  83. viewers: async.apply(createViewers)
  84. },function(err, results) {
  85. if (err) throw err;
  86. });
  87. //create viewers
  88. function createViewers(cb) {
  89. db.automigrate('Viewer', function(err) {
  90. if (err) return cb(err);
  91.  
  92. app.models.Viewer.create([
  93. {email: 'example01@gmail.com', password: 'example123'},
  94. {email: 'example02@gmail.com', password: 'example456'},
  95. {email: 'example03@gmail.com', password: 'example789'}
  96. ], cb);
  97. });
  98. }
  99. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement