Git Product home page Git Product logo

javieraviles / carryme Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 7.55 MB

My very first project at university (UPCT, Spain) back in 2013: AngularJS + Firebase, including authentication and real-time database. Car sharing app. **Full of bad practices**, but it works.

Home Page: http://carryme.tritogether.net

License: MIT License

CSS 6.46% HTML 61.18% JavaScript 32.12% Python 0.10% Shell 0.01% PHP 0.14%
angularjs firebase angularfire bootstrap carsharing university-project

carryme's Introduction

CarryMe

My very first project at university (UPCT, Spain) back in 2013: AngularJS + Firebase, including authentication and real-time database. Car sharing app. Full of bad practices, but it works.

Live demo

I didn't use bower, which at that time would have been the ideal tool as a frontEnd package manager, so angularJS 1.1 can be found in the /lib directory. For styling, Bootstrap 3 was used, can be found in /css folder.

Each view has it's own controller, where the business logic resides; the access to the firebase cloudDB endpoints is done from there. At least for the auth a service was used, so that part doesn't look that bad.

Routing

    $routeProvider.
        when('/', {
        templateUrl: 'partials/identification.html',
        controller: 'loginController'
      }).
        when('/profile', {
        templateUrl: 'partials/user-profile.html',
        controller: 'profileController'
      }).
        when('/login', {
        templateUrl: 'partials/login.html',
        controller: 'loginController'
      }).
        when('/my-cars', {
        templateUrl: 'partials/my-cars.html',
        controller: 'myCarsController'
      }).
        when('/chosen-cars', {
        templateUrl: 'partials/chosen-cars.html',
        controller: 'chosenCarsController'
      }).
        when('/new-car', {
        templateUrl: 'partials/new-car.html',
        controller: 'carController'
      }).
        when('/looking-for-car', {
        templateUrl: 'partials/looking-for-car.html',
        controller: 'lookingController'
      }).
      otherwise({
        redirectTo: '/'
      });

AuthService

    init: function() {

        var databaseRef = new Firebase('https://tfg.firebaseio.com');
        return loginObj = $firebaseSimpleLogin(databaseRef);
    },
    

    login: function(email, pass) {
        $rootScope.loginError = null;
        loginObj.$login('password', {
            email: email,
            password: pass
        }).then(function(user) {
            console.log('Logged in as: ', user.uid);
            
            
            var keys = users.$getIndex();
            angular.forEach(keys, function(key) {
                if(users[key].id===user.uid){
                    $rootScope.user = users[key];
                    $rootScope.userKey = key;
                }
            });
            $location.path('/profile');
        }, function(error) {
            console.error('Login failed: ', error);
            $rootScope.loginError = error;
        });
        
        
    },
    
    changePassword: function(email, oldPass, newPass){
        $rootScope.loginError = null;
        loginObj.$changePassword(email, oldPass, newPass)
            .then(function(user){
                console.log('Password change succeded');
                $rootScope.change = true;
            }, function(error){
                console.error('Password change failed: ', error);
                $rootScope.loginError = error;
            });
    },
        
    logout: function() {
        $rootScope.loginError = null;
        loginObj.$logout();
        $rootScope.user = null;
    },


    createAccount: function(email, pass, name, phone) {
        $rootScope.loginError = null;
        loginObj.$createUser(email, pass)
            .then(function(user) { 
                console.log('User created as: ', user.uid); 
                users.$add({
                    "name": name,
                    "email": email,
                    "id": user.uid,
                    "phoneNumber": phone,
                    "chosenCars": false
                });
                
                loginObj.$login('password', {
                    email: email,
                    password: pass
                }).then(function(user) {
                    console.log('Logged in as: ', user.uid);


                    var keys = users.$getIndex();
                    angular.forEach(keys, function(key) {
                        if(users[key].id===user.uid){
                            $rootScope.user = users[key];
                            $rootScope.userKey = key;
                        }
                    });
                    $location.path('/profile');
                }, function(error) {
                    $rootScope.loginError = error;
                    console.error('Login failed: ', error);
                });
                
                
                
            }, function(error) {
                console.error('User creation failed: ', error);
                $rootScope.loginError = error;
        });  
        
    }

Controller example

    tfgControllers.controller('loginController', ['$scope', '$firebase', 'loginService', '$rootScope', function($scope, $firebase, loginService, $rootScope) {

    
    
        $scope.login = function() {
                 $rootScope.loginError = null;
                 if( !$scope.email ) {
                    $rootScope.loginError = 'Please insert an email address';
                 }
                 else if( !$scope.pass ) {
                    $rootScope.loginError = 'The password is needed';
                 }
                 else {
                    loginService.login($scope.email, $scope.pass);
                 }
        };


        $scope.createUser = function() {
                 $rootScope.loginError = null;
                 if( !$scope.email ) {
                    $rootScope.loginError = 'Please insert an email address';
                 }
                 else if( !$scope.pass ) {
                    $rootScope.loginError = 'The password is needed';
                 }
                 else if( $scope.pass !== $scope.confirm ) {
                    $rootScope.loginError = 'Both passwords must be equal!';
                 }
                 else{
                    loginService.createAccount($scope.email, $scope.pass, $scope.name, $scope.phone);
                }
        };

    }]);

View example

    <div ng-show='loginObj.user === null'>
        <h1 align="center">Welcome to CarryMe!</h1>
        <h4 align="center">Traveling with empty seats? You are losing money!</h4>
        <h4 align="center">Try now CarryMe, the easiest way of sharing car.</h4>
        
        <form class="form-signin" role="form">
            <input type="email" ng-model="email" class="form-control" placeholder="email address" required="" autofocus="">
            <input type="password" ng-model="pass" class="form-control" placeholder="Password" required="">
            <button class="btn btn-lg btn-success btn-block" ng-click="login()">Sign in</button>
            <a style="color:white;" href="#/login"><p class="text-center">Sign up</p></a>
            <div ng-show='loginError!=null' class="alert alert-danger" role="alert">Something went wrong: {{loginError}}</div>
        </form>
    </div>
    <div ng-show='loginObj.user != null'>
        <h1>¡Welcome to CarryMe, {{user.name}}!</h1>
        <a href='#/profile'><button type="button" class="btn btn-success">My profile</button></a>
        <button type="button" class="btn btn-danger" ng-click="loginObj.$logout()">Logout</button>
    </div>

carryme's People

Contributors

javieraviles avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.