Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login Form in Navbar #44

Open
wants to merge 1 commit into
base: feature/authentication-logic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<script src="js/routeProvider.js"></script>
<script src="js/translateProvider.js"></script>
<script src="js/controllers/RegisterController.js"></script>
<script src="js/controllers/NavigationController.js"></script>
<script src="js/controllers/LoginController.js"></script>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="bower_components/bootstrap-social/bootstrap-social.css" />
<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css" />
Expand All @@ -32,15 +32,24 @@
<body>

<div class="container">
<nav class="navbar navbar-default" ng-controller="NavigationController as ctrl">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="http://come2.help/">come2.help</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right" ng-show="ctrl.authenticated()">
<li><a href="" ng-click="ctrl.logout()">{{ 'Logout' | translate }}</a></li>
</ul>
<div class="navbar-right" ng-controller="LoginController as ctrl">
<form class="navbar-form" ng-hide="ctrl.authenticated()" ng-submit="ctrl.login()">
<div class="form-group">
<label class="sr-only" for="login-email">{{ 'Email' | translate}}</label>
<input type="email" class="form-control" id="login-email" ng-bind="ctrl.user.email" placeholder="{{ 'Email' | translate}}">
</div>
<div class="form-group">
<label class="sr-only" for="login-password">{{ 'Password' | translate}}</label>
<input type="password" class="form-control col-xs-4" id="login-password" ng-bind="ctrl.user.password" placeholder="{{ 'Password' | translate }}">
</div>
<button type="submit" class="btn btn-default btn-success">{{ 'Log in' | translate }}</button>
</form>
<button type="button" href="" ng-click="ctrl.logout()" class="btn navbar-btn btn-link" ng-show="ctrl.authenticated()">{{ 'Logout' | translate }}</button>
</div>
</div>
</nav>
Expand Down
22 changes: 22 additions & 0 deletions js/controllers/LoginController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
angular.module('Come2HelpApp')
.controller('LoginController', ['$auth', '$location', function($auth, $location) {
var vm = this;

vm.credentials = {};

vm.login = function() {
// User transport object
var transUser = {
email: vm.user.email || '',
password: vm.user.password || ''
};
$auth.login(transUser);
};

vm.authenticated = $auth.isAuthenticated.bind($auth);

vm.logout = function() {
$auth.removeToken();
$location.path('/');
};
}]);
10 changes: 0 additions & 10 deletions js/controllers/NavigationController.js

This file was deleted.