Skip to content

Commit

Permalink
Fixed #91 : Admin registration process - Part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre BM committed Apr 11, 2015
1 parent 716237e commit 840c3d7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
16 changes: 14 additions & 2 deletions first_run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os

from database import init_db
from controllers import category_controller, slide_controller
from controllers import (
category_controller, slide_controller,
administrator_controller
)


if __name__ == '__main__':
Expand All @@ -12,6 +15,14 @@
def init():
init_db()

print("Creating super admin")
administrator_controller.create(
nickname="", # add nickniame here
email="", # add persona email
active=True,
super_admin=True
)

print("Createing the a test category..")
category_controller.create(name="Test")
category_controller.create(name="Uncategorised")
Expand All @@ -21,6 +32,7 @@ def init():
screenshot="img/badge-reserved.jpg",
description="test desc",
url="https://github.com/moztn/firefoxOSAppDay-Slides",
category=1
category=1,
owner=1
)
print("Fixtures created successfully")
19 changes: 17 additions & 2 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy import Boolean, Column, Integer, String, ForeignKey
from database import Base
from sqlalchemy.orm import relationship, backref
from flask.ext.login import UserMixin
Expand All @@ -7,14 +7,28 @@
class AdministratorModel(Base,UserMixin):
__tablename__ = 'administrators'
id = Column(Integer, primary_key=True)
nickname = Column(String(10), unique=True)
email = Column(String(90), unique=True)
active = Column(Boolean)
super_admin = Column(Boolean)


def __init__(self, email=None):
def __init__(self, nickname=None, email=None, active=False, super_admin=False):
self.nickname = nickname
self.email = email
self.active = active
self.super_admin = super_admin

def __repr__(self):
return '<Administrator %r>' %(self.email)

def is_active(self):
return self.active

def has_nickname(self):
return self.nickname is not None and \
len(self.nickname) is not 0

class SlideModel(Base):
__tablename__ = 'slides'
id = Column(Integer, primary_key=True)
Expand All @@ -24,6 +38,7 @@ class SlideModel(Base):
category = Column(Integer, ForeignKey('categories.id'), nullable=False)
# category = relationship('Category', backref=backref('slides', lazy='dynamic'))
screenshot = Column(String(255))
owner = Column(Integer, ForeignKey('administrators.id'), nullable=False)

def __repr__(self):
return '<Slide %s>' %(self.title)
Expand Down
15 changes: 13 additions & 2 deletions slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@

from database import db_session
from models import AdministratorModel, SlideModel, CategoryModel
from controllers import category_controller, slide_controller
from controllers import (
category_controller, slide_controller, administrator_controller
)

from flask.ext.login import LoginManager , login_required
from flask.ext.browserid import BrowserID



def get_admin_by_id(aId):
try:
print "get_admin_by_id : {0}".format(aId)
admin = AdministratorModel.query.get(int(aId))
return admin
except NoResultFound:
Expand All @@ -21,9 +27,14 @@ def get_admin_by_id(aId):
def get_admin(kwargs):
try:
admin = AdministratorModel.query.filter_by(email=kwargs['email']).first()

if(admin is None):
raise NoResultFound
return admin
except NoResultFound:
return None
admin = administrator_controller.create(email=kwargs['email'])
print admin
return admin

app = Flask(__name__)

Expand Down
21 changes: 19 additions & 2 deletions templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@
}

</script>

{% if not current_user.is_authenticated() %}
<div class="alert alert-error">
{% if login == 'Success' and not current_user.is_active() %}
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">x</button>
<h4>
<span>
<strong>Ooops !</strong> Your account is not yet activated !</strong>
<p><strong> Please wait for activation, an admin has been notified.</strong>
</span>
</h4>
</div>
{% else %}
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">x</button>
<h4>
<span>
Expand All @@ -16,15 +28,20 @@ <h4>
</span>
</h4>
</div>

{% endif %}
{% elif current_user.is_authenticated() and not current_user.has_nickname() %}
<p> TODO : fill form </p>
{% else %}
{% if login == 'Success' %}
{% if login == 'Success' and current_user.is_active() %}
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<h4>
<span> You have been successfully logged in ! </span>
</h4>
</div>
{% endif %}

{% if status == True %}
{% if operation == 'categories' %}
<div class="alert alert-success">
Expand Down

0 comments on commit 840c3d7

Please sign in to comment.