Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <li ng-show="currentUser">
- <a ui-sref="report" ui-sref-active="active">Report</a>
- </li>
- .config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
- $stateProvider
- .state('user-report', {
- url: '/user-report',
- templateUrl: 'views/user-report.html',
- controller: 'UserReportController',
- authenticate: true
- })
- .state('report', {
- url: '/report',
- templateUrl: 'views/report.html',
- controller: 'ReportController',
- authenticate: true
- });
- angular
- .module('app')
- .controller('AuthLoginController', ['$scope', 'AuthService', '$state',
- function($scope, AuthService, $state) {
- $scope.user = {
- email: '',
- password: ''
- };
- $scope.login = function() {
- AuthService.login($scope.user.email, $scope.user.password)
- .then(function() {
- $state.go('report');
- });
- };
- }])
- .controller('AuthLogoutController', ['$scope', 'AuthService', '$state',
- function($scope, AuthService, $state) {
- AuthService.logout()
- .then(function() {
- $state.go('contact');
- });
- }]);
- angular
- .module('app')
- .factory('AuthService', ['Viewer', '$q', '$rootScope', function(User, $q,
- $rootScope) {
- function login(email, password) {
- return User
- .login({email: email, password: password})
- .$promise
- .then(function(response) {
- $rootScope.currentUser = {
- id: response.user.id,
- tokenId: response.id,
- email: email
- };
- });
- }
- function logout() {
- return User
- .logout()
- .$promise
- .then(function() {
- $rootScope.currentUser = null;
- });
- }
- return {
- login: login,
- logout: logout
- };
- }]);
- var async = require('async');
- module.exports = function(app) {
- //data sources
- var db = app.dataSources.db;
- //create all models
- async.parallel({
- viewers: async.apply(createViewers)
- },function(err, results) {
- if (err) throw err;
- });
- //create viewers
- function createViewers(cb) {
- db.automigrate('Viewer', function(err) {
- if (err) return cb(err);
- app.models.Viewer.create([
- {email: 'example01@gmail.com', password: 'example123'},
- {email: 'example02@gmail.com', password: 'example456'},
- {email: 'example03@gmail.com', password: 'example789'}
- ], cb);
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement