コード例 #1
0
ファイル: account.py プロジェクト: asuffield/openspending
 def register(self):
     require.account.create()
     errors, values = {}, None
     if request.method == 'POST':
         try:
             schema = AccountRegister()
             values = request.params
             data = schema.deserialize(values)
             if Account.by_name(data['name']):
                 raise colander.Invalid(
                     AccountRegister.name,
                     _("Login name already exists, please choose a "
                       "different one"))
             if not data['password1'] == data['password2']:
                 raise colander.Invalid(AccountRegister.password1, _("Passwords \
                     don't match!"))
             account = Account()
             account.name = data['name']
             account.fullname = data['fullname']
             account.email = data['email']
             account.password = generate_password_hash(data['password1'])
             db.session.add(account)
             db.session.commit()
             who_api = get_api(request.environ)
             authenticated, headers = who_api.login({
                 "login": account.name,
                 "password": data['password1']
             })
             response.headers.extend(headers)
             return redirect("/")
         except colander.Invalid, i:
             errors = i.asdict()
コード例 #2
0
 def register(self):
     require.account.create()
     self._disable_cache()
     errors, values = {}, None
     if request.method == 'POST':
         try:
             schema = AccountRegister()
             values = request.params
             data = schema.deserialize(values)
             if Account.by_name(data['name']):
                 raise colander.Invalid(
                     AccountRegister.name,
                     _("Login name already exists, please choose a "
                       "different one"))
             if not data['password1'] == data['password2']:
                 raise colander.Invalid(AccountRegister.password1,
                                        _("Passwords don't match!"))
             account = Account()
             account.name = data['name']
             account.fullname = data['fullname']
             account.email = data['email']
             account.password = generate_password_hash(data['password1'])
             db.session.add(account)
             db.session.commit()
             who_api = get_api(request.environ)
             authenticated, headers = who_api.login({
                 "login": account.name,
                 "password": data['password1']
             })
             response.headers.extend(headers)
             return redirect("/")
         except colander.Invalid, i:
             errors = i.asdict()
コード例 #3
0
def shell_account():
    account = Account.by_name(SHELL_USER)
    if account is not None:
        return account
    account = Account()
    account.name = SHELL_USER
    db.session.add(account)
    return account
コード例 #4
0
def shell_account():
    account = Account.by_name(SHELL_USER)
    if account is not None:
        return account
    account = Account()
    account.name = SHELL_USER
    db.session.add(account)
    return account
コード例 #5
0
ファイル: test_account.py プロジェクト: smellman/openspending
 def test_settings(self, model_mock, update_mock):
     account = Account()
     account.name = 'mockaccount'
     db.session.add(account)
     db.session.commit()
     model_mock.return_value = account
     update_mock.return_value = True
     self.app.get(url(controller='account', action='settings'),
                  extra_environ={'REMOTE_USER': '******'})
コード例 #6
0
 def test_settings(self, model_mock, update_mock):
     account = Account()
     account.name = 'mockaccount'
     db.session.add(account)
     db.session.commit()
     model_mock.return_value = account
     update_mock.return_value = True
     self.app.get(url(controller='account', action='settings'),
                  extra_environ={'REMOTE_USER': '******'})
コード例 #7
0
    def register(self):
        require.account.create()
        c.config = config
        self._disable_cache()
        errors, values = {}, None
        if request.method == 'POST':
            try:
                schema = AccountRegister()
                values = request.params
                data = schema.deserialize(values)
                if Account.by_name(data['name']):
                    raise colander.Invalid(
                        AccountRegister.name,
                        _("Login name already exists, please choose a "
                          "different one"))
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountRegister.password1,
                                           _("Passwords don't match!"))
                account = Account()
                account.name = data['name']
                account.fullname = data['fullname']
                account.email = data['email']
                account.password = generate_password_hash(data['password1'])
                db.session.add(account)
                db.session.commit()
                who_api = get_api(request.environ)
                authenticated, headers = who_api.login({
                    "login":
                    account.name,
                    "password":
                    data['password1']
                })

                errors = subscribe_lists(('community', 'developer'), data)
                if errors:
                    h.flash_notice(
                        _("Subscription to the following mailing " +
                          "lists probably failed: %s.") % ', '.join(errors))

                response.headers.extend(headers)
                return redirect("/")
            except colander.Invalid, i:
                errors = i.asdict()
コード例 #8
0
ファイル: helpers.py プロジェクト: ToroidalATLAS/openspending
def make_account(name='test', fullname='Test User',
                 email='*****@*****.**', twitter='testuser',
                 admin=False):
    from openspending.model.account import Account

    # First see if the account already exists and if so, return it
    account = Account.by_name(name)
    if account:
        return account

    # Account didn't exist so we create it and return it
    account = Account()
    account.name = name
    account.fullname = fullname
    account.email = email
    account.twitter_handle = twitter
    account.admin = admin
    db.session.add(account)
    db.session.commit()

    return account
コード例 #9
0
ファイル: account.py プロジェクト: AlbertoPeon/openspending
    def register(self):
        require.account.create()
        c.config = config
        self._disable_cache()
        errors, values = {}, None
        if request.method == 'POST':
            try:
                schema = AccountRegister()
                values = request.params
                data = schema.deserialize(values)
                if Account.by_name(data['name']):
                    raise colander.Invalid(
                        AccountRegister.name,
                        _("Login name already exists, please choose a "
                          "different one"))
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountRegister.password1,
                                           _("Passwords don't match!"))
                account = Account()
                account.name = data['name']
                account.fullname = data['fullname']
                account.email = data['email']
                account.password = generate_password_hash(data['password1'])
                db.session.add(account)
                db.session.commit()
                who_api = get_api(request.environ)
                authenticated, headers = who_api.login({
                    "login": account.name,
                    "password": data['password1']
                })

                errors = subscribe_lists(('community', 'developer'), data)
                if errors:
                    h.flash_notice(_("Subscription to the following mailing " +
                            "lists probably failed: %s.") % ', '.join(errors))

                response.headers.extend(headers)
                return redirect("/")
            except colander.Invalid, i:
                errors = i.asdict()
コード例 #10
0
def make_account(name='test',
                 fullname='Test User',
                 email='*****@*****.**',
                 twitter='testuser',
                 admin=False):
    from openspending.model.account import Account

    # First see if the account already exists and if so, return it
    account = Account.by_name(name)
    if account:
        return account

    # Account didn't exist so we create it and return it
    account = Account()
    account.name = name
    account.fullname = fullname
    account.email = email
    account.twitter_handle = twitter
    account.admin = admin
    db.session.add(account)
    db.session.commit()

    return account
コード例 #11
0
ファイル: account.py プロジェクト: RandyMoore/openspending
    def register(self):
        """
        Perform registration of a new user
        """

        # We must allow account creation
        require.account.create()

        # We add the config as a context variable in case anything happens
        # (like with login we need this to allow subscriptions to mailing lists)
        c.config = config

        # Disable the cache (don't want anything getting in the way)
        self._disable_cache()

        # Initial values and errors
        errors, values = {}, None

        # If this is a POST operation somebody is trying to register
        if request.method == 'POST':
            try:
                # Get the account register schema (for validation)
                schema = AccountRegister()

                # Set values from the request parameters
                # (for validation and so we can autofill forms)
                values = request.params

                # Grab the actual data and validate it
                data = schema.deserialize(values)

                # Check if the username already exists, return an error if so
                if Account.by_name(data['name']):
                    raise colander.Invalid(
                        AccountRegister.name,
                        _("Login name already exists, please choose a "
                          "different one"))

                # Check if passwords match, return error if not
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountRegister.password1,
                                           _("Passwords don't match!"))

                # Create the account
                account = Account()

                # Set username and full name
                account.name = data['name']
                account.fullname = data['fullname']

                # Set email and if email address should be public
                account.email = data['email']
                account.public_email = data['public_email']

                # Hash the password and store the hash
                account.password = generate_password_hash(data['password1'])

                # Commit the new user account to the database
                db.session.add(account)
                db.session.commit()

                # Perform a login for the user
                who_api = get_api(request.environ)
                authenticated, headers = who_api.login({
                    "login": account.name,
                    "password": data['password1']
                })
                # Add the login headers
                response.headers.extend(headers)

                # Subscribe the user to the mailing lists
                errors = subscribe_lists(('community', 'developer'), data)
                # Notify if the mailing list subscriptions failed
                if errors:
                    h.flash_notice(_("Subscription to the following mailing " +
                            "lists probably failed: %s.") % ', '.join(errors))

                # Registration successful - Redirect to the front page
                return redirect("/")
            except colander.Invalid, i:
                # Mark colander errors
                errors = i.asdict()
コード例 #12
0
ファイル: account.py プロジェクト: serchaos/openspending
    def register(self):
        """
        Perform registration of a new user
        """

        # We must allow account creation
        require.account.create()

        # We add the config as a context variable in case anything happens
        # (like with login we need this for subscriptions to mailing lists)
        c.config = config

        # Disable the cache (don't want anything getting in the way)
        self._disable_cache()

        # Initial values and errors
        errors, values = {}, None

        # If this is a POST operation somebody is trying to register
        if request.method == 'POST':
            try:
                # Get the account register schema (for validation)
                schema = AccountRegister()

                # Set values from the request parameters
                # (for validation and so we can autofill forms)
                values = request.params

                # Grab the actual data and validate it
                data = schema.deserialize(values)

                # Check if the username already exists, return an error if so
                if Account.by_name(data['name']):
                    raise colander.Invalid(
                        AccountRegister.name,
                        _("Login name already exists, please choose a "
                          "different one"))

                # Check if passwords match, return error if not
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountRegister.password1,
                                           _("Passwords don't match!"))

                # Create the account
                account = Account()

                # Set username and full name
                account.name = data['name']
                account.fullname = data['fullname']

                # Set email and if email address should be public
                account.email = data['email']
                account.public_email = data['public_email']

                # Hash the password and store the hash
                account.password = generate_password_hash(data['password1'])

                # Commit the new user account to the database
                db.session.add(account)
                db.session.commit()

                # Perform a login for the user
                who_api = get_api(request.environ)
                authenticated, headers = who_api.login({
                    "login":
                    account.name,
                    "password":
                    data['password1']
                })
                # Add the login headers
                response.headers.extend(headers)

                # Subscribe the user to the mailing lists
                errors = subscribe_lists(('community', 'developer'), data)
                # Notify if the mailing list subscriptions failed
                if errors:
                    h.flash_notice(
                        _("Subscription to the following mailing " +
                          "lists probably failed: %s.") % ', '.join(errors))

                # Registration successful - Redirect to the front page
                return redirect("/")
            except colander.Invalid as i:
                # Mark colander errors
                errors = i.asdict()

        # Show the templates (with possible errors and form values)
        return templating.render('account/login.html',
                                 form_fill=values,
                                 form_errors=errors)