Permalink
Browse files

Finishing up Login/logout/signup/nav

  • Loading branch information...
sreecodeslayer committed Jan 19, 2017
1 parent 8637c5e commit e794ddbc2bb0b047cd3af38af03241067c30cb25
Showing with 76 additions and 19 deletions.
  1. +5 −1 app.py
  2. +4 −0 requirements.txt
  3. +37 −1 static/js/app.js
  4. +30 −17 templates/index.html
6 app.py
@@ -21,7 +21,11 @@ def load_user(user):
# ------------------------------------------------------------------------------------
@app.route("/")
def index():
return render_template('index.html')
try:
user = User.objects.get(id=current_user.id)
return render_template('index.html', username = current_user.username)
except (AttributeError, DoesNotExist):
return render_template('index.html', username = False)

@app.route("/login", methods=['POST'])
def login():
@@ -1 +1,5 @@
python_bcrypt==0.3.1
Flask==0.12
Werkzeug==0.11.15
bcrypt
flask-mongoengine
@@ -2,7 +2,7 @@ var tApp = angular.module('todoApp', ['ngRoute'],function($interpolateProvider){
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
});
tApp.controller('TodoController', ['$scope', '$http', '$location', '$route', function($scope, $http, $location, $route) {
tApp.controller('TodoController', ['$scope', '$http', '$window', '$route', function($scope, $http, $window, $route) {
$scope.login = function(){
$http({
url: '/login',
@@ -14,6 +14,42 @@ tApp.controller('TodoController', ['$scope', '$http', '$location', '$route', fun
headers: {'Content-Type':'application/json'}
}).then(function(response){
console.log(response['status'] + ' ' + response['statusText']);
if(response.data['status'] == true){
$window.location.reload();
}
else{
console.log(response.data);
}
});
}

$scope.signup = function(){
$http({
url: '/signup',
method: 'POST',
data: JSON.stringify({
'username':$scope.signup.username,
'password':$scope.signup.password
}),
headers: {'Content-Type':'application/json'}
}).then(function(response){
console.log(response['status'] + ' ' + response['statusText']);
});
}

$scope.logout = function(){
$http({
url: '/logout',
method: 'POST',
headers: {'Content-Type':'application/json'}
}).then(function(response){
console.log(response['status'] + ' ' + response['statusText']);
if(response.data['status'] == true){
$window.location.reload();
}
else{
console.log(response.data);
}
});
}
}]);
@@ -25,16 +25,24 @@
<img id="icon" href="/" src = "{{ url_for('static' , filename='images/icon.png') }}" alt="" />
</div>
<!--Links-->
<ul class="nav navbar-nav pull-right">
<ul class="nav navbar-nav navbar-right">
<li class="nav-item" data-toggle="modal" data-target="#aboutModal">
<a class="nav-link" href="#">About</a>
</li>
{% if username %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">{{ username | capitalize }}<b class="caret"></b></a>
<ul class="dropdown-menu">
<li style="cursor: pointer;"><a ng-click="logout()">Logout</a></li>
</ul>
</li>
{% endif %}
</ul>
</div>
</div>
<!-- Main Content Goes Here -->
</nav>

{% if not username %}
<div id="main-wrapper" class="bg">
<div class="card card-1">
<h5 class="text-muted">Howdi user,<br>Login/Signup and start ticking off those tasks!</h5>
@@ -43,18 +51,6 @@ <h5 class="text-muted">Howdi user,<br>Login/Signup and start ticking off those t
<button data-toggle="modal" data-target="#signupModal" class="btn btn-success">Signup</button>
</div>
<!-- </div> -->
<!-- About Modal -->
<div class="modal fade" id="aboutModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h5 class="lead text-center text-muted">About</h5>
<p class="text-info">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed porttitor mauris a dignissim molestie. Aenean id ante commodo, consequat metus id, mattis nisl. Nulla quis tortor imperdiet, molestie nisl vel. </p>
<p class="text-info">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce accumsan odio vel dolor lacinia, sit amet mollis dui sodales. Duis gravida magna eget tristique efficitur. Aenean dignissim nisl vel enim interdum viverra. Duis metus lorem, facilisis quis ornare a, porttitor.</p>
</div>
</div>
</div>
</div>
<!-- Login Modal -->
<div class="modal fade" id="loginModal" role="dialog">
<div class="modal-dialog" >
@@ -84,13 +80,13 @@ <h5 class="lead text-center text-muted">Login</h5>
<div class="modal-dialog" >
<div class="modal-content">
<div class="modal-body">
<form>
<form ng-submit="signup()">
<div class="form-group">
<label class="text-success">Username: </label>&nbsp;<input class="form-control" type="text" name="username" placeholder="Case insensitive">
<label class="text-success">Username: </label>&nbsp;<input class="form-control" ng-model="signup.username"type="text" name="username" placeholder="Case insensitive">
</div>

<div class="form-group">
<label class="text-success">Password: </label>&nbsp;<input class="form-control" type="password" name="password">
<label class="text-success">Password: </label>&nbsp;<input class="form-control" ng-model="signup.password"type="password" name="password">
</div>

<div class="form-group">
@@ -103,6 +99,23 @@ <h5 class="lead text-center text-muted">Login</h5>
</div>
</div>
</div>
{% else %}
<div id="main-wrapper" class="bg">
<p> {{ username }} </p>
</div>
{% endif %}
<!-- About Modal -->
<div class="modal fade" id="aboutModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h5 class="lead text-center text-muted">About</h5>
<p class="text-info">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed porttitor mauris a dignissim molestie. Aenean id ante commodo, consequat metus id, mattis nisl. Nulla quis tortor imperdiet, molestie nisl vel. </p>
<p class="text-info">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce accumsan odio vel dolor lacinia, sit amet mollis dui sodales. Duis gravida magna eget tristique efficitur. Aenean dignissim nisl vel enim interdum viverra. Duis metus lorem, facilisis quis ornare a, porttitor.</p>
</div>
</div>
</div>
</div>
</div>

</body>

0 comments on commit e794ddb

Please sign in to comment.