email for new users and users cache
Este commit está contenido en:
padre
42ad0756de
commit
ccda304533
Se han modificado 3 ficheros con 25 adiciones y 7 borrados
|
@ -7,7 +7,7 @@
|
|||
<div class="panel-body">
|
||||
<form method="POST">
|
||||
<div class="input-group input-group-lg">
|
||||
<span class="input-group-addon min150">{{'Username' | translate}}</span>
|
||||
<span class="input-group-addon min150">{{'Username or email' | translate}}</span>
|
||||
<input type="text" id="username" name="username" ng-model="loginData.username" class="form-control">
|
||||
</div>
|
||||
<div class="input-group input-group-lg top10">
|
||||
|
@ -29,11 +29,15 @@
|
|||
<form method="POST">
|
||||
<div class="input-group input-group-lg">
|
||||
<span class="input-group-addon min150">{{'Username' | translate}}</span>
|
||||
<input type="text" id="username" name="username" ng-model="newUser.username" class="form-control">
|
||||
<input type="text" id="new-username" name="new-username" ng-model="newUser.username" class="form-control" ng-required="1">
|
||||
</div>
|
||||
<div class="input-group input-group-lg top10">
|
||||
<span class="input-group-addon min150">{{'Email' | translate}}</span>
|
||||
<input type="email" id="new-email" name="new-email" ng-model="newUser.email" class="form-control">
|
||||
</div>
|
||||
<div class="input-group input-group-lg top10">
|
||||
<span class="input-group-addon min150">{{'Password' | translate}}</span>
|
||||
<input type="password" id="password" name="password" ng-model="newUser.password" class="form-control">
|
||||
<input type="password" id="new-password" name="new-password" ng-model="newUser.password" class="form-control" ng-required="1">
|
||||
</div>
|
||||
<button type="submit" ng-click="register()" class="btn btn-success top10">{{'register' | translate}}</button>
|
||||
</form>
|
||||
|
|
|
@ -131,7 +131,7 @@ class EventManDB(object):
|
|||
results = self.query(collection, convert({'_id': _id}))
|
||||
return results and results[0] or {}
|
||||
|
||||
def query(self, collection, query=None):
|
||||
def query(self, collection, query=None, condition='or'):
|
||||
"""Get multiple documents matching a query.
|
||||
|
||||
:param collection: search for documents in this collection
|
||||
|
@ -144,6 +144,8 @@ class EventManDB(object):
|
|||
"""
|
||||
db = self.connect()
|
||||
query = convert(query or {})
|
||||
if isinstance(query, (list, tuple)):
|
||||
query = {'$%s' % condition: query}
|
||||
return list(db[collection].find(query))
|
||||
|
||||
def add(self, collection, data, _id=None):
|
||||
|
|
|
@ -92,6 +92,8 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||
'users|create': True
|
||||
}
|
||||
|
||||
_users_cache = {}
|
||||
|
||||
# A property to access the first value of each argument.
|
||||
arguments = property(lambda self: dict([(k, v[0])
|
||||
for k, v in self.request.arguments.iteritems()]))
|
||||
|
@ -161,6 +163,8 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||
def current_user_info(self):
|
||||
"""Information about the current user, including their permissions."""
|
||||
current_user = self.current_user
|
||||
if current_user in self._users_cache:
|
||||
return self._users_cache[current_user]
|
||||
user_info = {'permissions': set([k for (k, v) in self.permissions.iteritems() if v is True])}
|
||||
if current_user:
|
||||
user_info['username'] = current_user
|
||||
|
@ -169,6 +173,7 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||
user = res[0]
|
||||
user_info['permissions'].update(set(user.get('permissions') or []))
|
||||
user_info['permissions'] = list(user_info['permissions'])
|
||||
self._users_cache[current_user] = user_info
|
||||
return user_info
|
||||
|
||||
def has_permission(self, permission):
|
||||
|
@ -199,6 +204,8 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||
|
||||
def logout(self):
|
||||
"""Remove the secure cookie used fro authentication."""
|
||||
if self.current_user in self._users_cache:
|
||||
del self._users_cache[self.current_user]
|
||||
self.clear_cookie("user")
|
||||
|
||||
|
||||
|
@ -699,12 +706,14 @@ class UsersHandler(CollectionHandler):
|
|||
def filter_input_post_all(self, data):
|
||||
username = (data.get('username') or '').strip()
|
||||
password = (data.get('password') or '').strip()
|
||||
email = (data.get('email') or '').strip()
|
||||
if not (username and password):
|
||||
raise InputException('missing username or password')
|
||||
res = self.db.query('users', {'username': username})
|
||||
if res:
|
||||
raise InputException('username already exists')
|
||||
return {'username': username, 'password': utils.hash_password(password)}
|
||||
return {'username': username, 'password': utils.hash_password(password),
|
||||
'email': email, '_id': self.gen_id()}
|
||||
|
||||
|
||||
class EbCSVImportPersonsHandler(BaseHandler):
|
||||
|
@ -852,9 +861,12 @@ class LoginHandler(BaseHandler):
|
|||
with open(self.angular_app_path + "/login.html", 'r') as fd:
|
||||
self.write(fd.read())
|
||||
|
||||
def _authorize(self, username, password):
|
||||
def _authorize(self, username, password, email=None):
|
||||
"""Return True is this username/password is valid."""
|
||||
res = self.db.query('users', {'username': username})
|
||||
query = [{'username': username}]
|
||||
if email is not None:
|
||||
query.append({'email': email})
|
||||
res = self.db.query('users', query)
|
||||
if not res:
|
||||
return False
|
||||
user = res[0]
|
||||
|
|
Cargando…
Referenciar en una nueva incidencia