コード例 #1
0
ファイル: authenticator.py プロジェクト: rgrp/openspending
 def authenticate(self, environ, identity):
     if not 'login' in identity or not 'password' in identity:
         return None
     acc = account.find_one_by('name', identity['login'])
     if acc is None:
         return None
     if check_password_hash(acc['password_hash'], identity['password']):
         return acc['name']
     return None
コード例 #2
0
ファイル: authenticator.py プロジェクト: rgrp/openspending
 def authenticate(self, environ, identity):
     authorization = AUTHORIZATION(environ)
     try:
         authmeth, auth = authorization.split(' ', 1)
     except ValueError: # not enough values to unpack
         return None
     if authmeth.lower() == 'apikey':
         acc = account.find_one_by('api_key', auth.strip())
         if acc is not None:
             return acc['name']
コード例 #3
0
ファイル: user.py プロジェクト: openstate/openspending
def grant_admin(username):
    from openspending.model import account

    a = account.find_one_by('name', username)

    if a is None:
        print "Account `%s' not found." % username
        return 1

    account.add_role(a, 'admin')

    return 0
コード例 #4
0
ファイル: user.py プロジェクト: Web5design/openspending
def grant_admin(username):
    from openspending.model import account

    a = account.find_one_by('name', username)

    if a is None:
        print "Account `%s' not found." % username
        return 1

    account.add_role(a, 'admin')

    return 0
コード例 #5
0
ファイル: account.py プロジェクト: rgrp/openspending
    def register(self):
        if app_globals.sandbox_mode:
            default_roles = ["user", "admin"]
        else:
            default_roles = ["user"]

        errors, values = {}, None
        if request.method == 'POST':
            try:
                schema = Register()
                values = request.params
                acc = schema.deserialize(values)
                exists = account.find_one_by('name', acc['name'])
                if exists:
                    raise colander.Invalid(
                        Register.name,
                        _("Login name already exists, please choose a "
                          "different one"))
                if not acc['password1'] == acc['password2']:
                    raise colander.Invalid(Register.password1, _("Passwords \
                        don't match!"))
                password = acc['password1']
                acc['password_hash'] = generate_password_hash(password)
                del acc['password1']
                del acc['password2']
                acc['roles'] = default_roles
                account.create(acc)
                who_api = get_api(request.environ)
                authenticated, headers = who_api.login({
                    "login": acc['name'],
                    "password": password
                })
                response.headers.extend(headers)
                return redirect("/")
            except colander.Invalid, i:
                errors = i.asdict()