Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //app.js
- var app = angular.module('bahquiz', ['ionic'])
- app.config(function($stateProvider, $urlRouterProvider) {
- // Ionic uses AngularUI Router which uses the concept of states
- // Learn more here: https://github.com/angular-ui/ui-router
- // Set up the various states which the app can be in.
- // Each state's controller can be found in controllers.js
- $stateProvider
- // setup an abstract state for the tabs directive
- .state('tab', {
- url: '/tab',
- abstract: true,
- templateUrl: 'templates/tabs.html'
- })
- // Each tab has its own nav history stack:
- .state('tab.profile', {
- url: '/profile',
- views: {
- 'tab-profile': {
- templateUrl: 'templates/tab-profile.html',
- controller: 'ProfileCtrl'
- }
- }
- })
- ...
- .state('tab.settings', {
- url: '/settings',
- views: {
- 'tab-settings': {
- templateUrl: 'templates/tab-settings.html',
- controller: 'SettingsCtrl'
- }
- }
- });
- // if none of the above states are matched, use this as the fallback
- $urlRouterProvider.otherwise('/tab/profile');
- });
- app.run(function($ionicPlatform) {
- $ionicPlatform.ready(function() {
- // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
- // for form inputs)
- if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
- cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
- cordova.plugins.Keyboard.disableScroll(true);
- }
- if (window.StatusBar) {
- // org.apache.cordova.statusbar required
- StatusBar.styleDefault();
- }
- });
- })
- --------------------------------------------------------------------------------------------
- //services.js
- app.service('questionService', function() { //Later to be replaced by service with http requests
- ...
- app.factory('userFactory', ['$http', function($http){
- var userFactory = {};
- var username;
- var password;
- userFactory.getList = function() {
- console.log("success");
- return $http.get('http://localhost:3000/users');
- };
- userFactory.setUser = function(name,pass) {
- username = name;
- password = pass;
- }
- userFactory.getUser = function() {
- if(username != null){
- return username;
- }
- }
- return userFactory;
- }]);
- --------------------------------------------------------
- //one of my controllers, ProfileCtrl.js. Ignore the lack of authentication and any other questionable logic. Not done yet
- app.controller('ProfileCtrl', ['$scope','userFactory', function($scope,userFactory) {
- $scope.username;
- $scope.password;
- $scope.register = function(){
- var i;
- var registered;
- $scope.username = document.getElementById("username");
- $scope.password = document.getElementById("password");
- while($scope.users[i] != null){
- if($scope.username == $scope.users[i].username){
- //somehow print the user exsits
- registered = true;
- break;
- }
- i++;
- }
- if(registered != true){
- //post request
- $scope.signedIn = true;
- updateBar();
- }
- }
- $scope.authenticate = function(){
- var i;
- $scope.username = document.getElementById("username");
- $scope.password = document.getElementById("password");
- getUsers();
- while($scope.users[i] != null){
- if($scope.username == $scope.users[i].username){
- if($scope.password == $scope.users[i].password){
- $scope.signedIn = true;
- updateBar();
- break;
- } else{
- //somehow display the password is incorrect
- break;
- }
- }
- i++;
- }
- if($scope.signedIn != true){
- //somehow display the username is incorrect
- }
- }
- function updateBar() {
- var elem = document.getElementById("progressBar");
- var width = 0;
- var interval = setInterval(frame, 10);
- function frame() {
- if (width >= 76) { // this will be user progress number
- clearInterval(interval);
- } else {
- width++;
- elem.style.width = width + '%';
- document.getElementById("label").innerHTML = width * 1 + '%';
- }
- }
- }
- function getUsers(){
- userFactory.getList()
- .then(function (response) {
- $scope.users = response.data.users; //check on this
- }, function (error) {
- $scope.status = 'unable to load users in controller: ' + error.message;
- });
- }
- }])
Add Comment
Please, Sign In to add comment