Expand reach of cdc in user model
This commit is contained in:
parent
1bd0f1e0c1
commit
dc340a1d5e
|
@ -116,7 +116,7 @@ class LexiconConfigDirectoryContext(ConfigDirectoryContext):
|
||||||
self.draft = ConfigDirectoryContext(os.path.join(self.path, 'draft'))
|
self.draft = ConfigDirectoryContext(os.path.join(self.path, 'draft'))
|
||||||
self.src = ConfigDirectoryContext(os.path.join(self.path, 'src'))
|
self.src = ConfigDirectoryContext(os.path.join(self.path, 'src'))
|
||||||
|
|
||||||
def config(edit=False):
|
def config(self, edit=False):
|
||||||
if edit:
|
if edit:
|
||||||
return self.edit('config')
|
return self.edit('config')
|
||||||
else:
|
else:
|
||||||
|
@ -127,7 +127,7 @@ class UserConfigDirectoryContext(ConfigDirectoryContext):
|
||||||
"""
|
"""
|
||||||
A config context for a user's config directory.
|
A config context for a user's config directory.
|
||||||
"""
|
"""
|
||||||
def config(edit=False):
|
def config(self, edit=False):
|
||||||
if edit:
|
if edit:
|
||||||
return self.edit('config')
|
return self.edit('config')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -8,7 +8,7 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
from amanuensis.errors import (
|
from amanuensis.errors import (
|
||||||
ArgumentError, MissingConfigError, IndexMismatchError)
|
ArgumentError, MissingConfigError, IndexMismatchError)
|
||||||
from amanuensis.config import prepend, json_ro, json_rw
|
from amanuensis.config import prepend, json_rw, root
|
||||||
from amanuensis.resources import get_stream
|
from amanuensis.resources import get_stream
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class UserModel(UserMixin):
|
||||||
if not uid and not name:
|
if not uid and not name:
|
||||||
raise ArgumentError("One of uid or name must be not None")
|
raise ArgumentError("One of uid or name must be not None")
|
||||||
if not uid:
|
if not uid:
|
||||||
with json_ro('user', 'index.json') as index:
|
with root.user.index() as index:
|
||||||
uid = index.get(name)
|
uid = index.get(name)
|
||||||
if not uid:
|
if not uid:
|
||||||
return None
|
return None
|
||||||
|
@ -41,7 +41,8 @@ class UserModel(UserMixin):
|
||||||
"""User model initializer, assume all checks were done by by()"""
|
"""User model initializer, assume all checks were done by by()"""
|
||||||
self.id = str(uid) # Flask-Login checks for this
|
self.id = str(uid) # Flask-Login checks for this
|
||||||
self.config_path = prepend('user', uid, 'config.json')
|
self.config_path = prepend('user', uid, 'config.json')
|
||||||
with json_ro(self.config_path) as j:
|
self.ctx = root.user[self.id]
|
||||||
|
with self.ctx.config() as j:
|
||||||
self.config = j
|
self.config = j
|
||||||
|
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
|
@ -57,12 +58,12 @@ class UserModel(UserMixin):
|
||||||
|
|
||||||
def set_password(self, pw):
|
def set_password(self, pw):
|
||||||
h = generate_password_hash(pw)
|
h = generate_password_hash(pw)
|
||||||
with json_rw(self.config_path) as j:
|
with self.ctx.config(edit=True) as j:
|
||||||
j['password'] = h
|
j['password'] = h
|
||||||
|
|
||||||
def check_password(self, pw):
|
def check_password(self, pw):
|
||||||
with json_ro(self.config_path) as j:
|
with self.ctx.config() as cfg:
|
||||||
return check_password_hash(j['password'], pw)
|
return check_password_hash(cfg.password, pw)
|
||||||
|
|
||||||
def in_lexicon(self, lexicon):
|
def in_lexicon(self, lexicon):
|
||||||
return self.id in lexicon.join.joined
|
return self.id in lexicon.join.joined
|
||||||
|
|
Loading…
Reference in New Issue