Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Most recent changes.

  • Loading branch information...
commit 7b6ab6934f9c336b7f5b1c18887f9a55095a5faf 1 parent 58d84a9
Seb Insua authored January 01, 2012
6  modules/app/controller/home.py
@@ -3,4 +3,8 @@
3 3
 
4 4
 @bp.route("/")
5 5
 def show_home():
6  
-    return render_template("home.html")
  6
+    # Getting out the username proves that you are logged in... ;)
  7
+    from mu.model.repository.user import fetch_user_with_uuid
  8
+    user = fetch_user_with_uuid(session['uuid'])
  9
+
  10
+    return render_template("home.html", username=user.username)
2  modules/app/model/domain/user.py
@@ -15,7 +15,7 @@ def register(self, email, username, password, force_login=False):
15 15
     def login(self, user_identity, password):
16 16
         user = fetch_user_with_identity(user_identity)
17 17
 
18  
-        if check_password(password):
  18
+        if user is not None and user.check_password(password):
19 19
             session['uuid'] = user.uuid
20 20
             return True
21 21
         return False
32  modules/app/model/repository/user.py
... ...
@@ -1,18 +1,36 @@
  1
+from sqlalchemy.orm.exc import NoResultFound
  2
+
1 3
 from helper.database import db
2 4
 from mu.model.entity.user import User
3 5
 
4  
-def add_user(self, user):
  6
+def add_user(user):
5 7
     db.session.add(user)
6 8
     db.session.commit()
7 9
     return user.user_id
8 10
 
9  
-def fetch_user_with_identity(self, user_identity):
  11
+def fetch_user_with_identity(user_identity):
10 12
     query = db.session.query(User).filter(db.or_(User.username == user_identity, \
11 13
                                                  User.email == user_identity))
12  
-    user = query.one()
13  
-    return user
  14
+    try:
  15
+        user = query.one()
  16
+        return user
  17
+    except NoResultFound, e:
  18
+        return None
14 19
 
15  
-def fetch_user_with_user_id(self, user_id):
  20
+def fetch_user_with_user_id(user_id):
16 21
     query = db.session.query(User).filter(User.user_id == user_id)
17  
-    user = query.one()
18  
-    return user
  22
+
  23
+    try:
  24
+        user = query.one()
  25
+        return user
  26
+    except NoResultFound, e:
  27
+        return None
  28
+
  29
+def fetch_user_with_uuid(uuid):
  30
+    query = db.session.query(User).filter(User.uuid == uuid)
  31
+
  32
+    try:
  33
+        user = query.one()
  34
+        return user
  35
+    except NoResultFound, e:
  36
+        return None
2  modules/app/templates/home.html
@@ -2,5 +2,5 @@
2 2
 {% extends layout_template if layout_template is defined else "main-layout.html" %}
3 3
 
4 4
 {% block content %}
5  
-Test
  5
+Test. {{ username }}
6 6
 {% endblock %}
2  modules/helper/app.py
@@ -20,7 +20,7 @@ def load_app():
20 20
 
21 21
 def get_app_name():
22 22
     try:
23  
-        f = open(os.getcwd() + '/APPLICATION_NAME')
  23
+        f = open(os.getcwd() + '/service_name')
24 24
         APPLICATION_NAME = f.read().strip();
25 25
     except IOError:
26 26
         pass
0  README → readme
File renamed without changes
0  APPLICATION_NAME → service_name
File renamed without changes
0  TODO → todo
File renamed without changes
0  VERSION → version
File renamed without changes

0 notes on commit 7b6ab69

Please sign in to comment.
Something went wrong with that request. Please try again.