Example #1
0
    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
                account = schema.deserialize(values)
                exists = model.Account.find_one({"name": account['name']})
                if exists:
                    raise colander.Invalid(
                        Register.name,
                        _("Login name already exists, please choose a "
                          "different one"))
                if not account['password1'] == account['password2']:
                    raise colander.Invalid(Register.password1, _("Passwords \
                        don't match!"))
                password = account['password1']
                account['password_hash'] = \
                    generate_password_hash(password)
                del account['password1']
                del account['password2']
                account['_roles'] = default_roles
                model.Account.c.insert(account)
                who_api = get_api(request.environ)
                authenticated, headers = who_api.login(
                    {"login": account['name'], "password": password})
                response.headers.extend(headers)
                return redirect("/")
            except colander.Invalid, i:
                errors = i.asdict()
Example #2
0
 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()
Example #3
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()
Example #4
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()
Example #5
0
    def settings(self):
        errors, values = {}, c.account
        if request.method == 'POST':
            try:
                schema = Settings()
                values = request.params
                data = schema.deserialize(values)
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(Register.password1,
                                           _("Passwords don't match!"))

                if len(data['password1']):
                    password = data['password1']
                    data['password_hash'] = generate_password_hash(password)
                del data['password1']
                del data['password2']
                account.update(c.account, {"$set": data})
                h.flash_success(_("Your settings have been updated."))
            except colander.Invalid, i:
                errors = i.asdict()
Example #6
0
    def settings(self):
        require.account.update(c.account)
        errors, values = {}, c.account
        if request.method == 'POST':
            try:
                schema = AccountSettings()
                values = request.params
                data = schema.deserialize(values)
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountSettings.password1,
                                           _("Passwords don't match!"))

                c.account.fullname = data['fullname']
                c.account.email = data['email']
                if data['password1'] is not None and len(data['password1']):
                    c.account.password = generate_password_hash(data['password1'])
                db.session.add(c.account)
                db.session.commit()
                h.flash_success(_("Your settings have been updated."))
            except colander.Invalid, i:
                errors = i.asdict()
Example #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()
Example #8
0
    def settings(self):
        require.account.update(c.account)
        errors, values = {}, c.account
        if request.method == 'POST':
            try:
                schema = AccountSettings()
                values = request.params
                data = schema.deserialize(values)
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountSettings.password1,
                                           _("Passwords don't match!"))

                c.account.fullname = data['fullname']
                c.account.email = data['email']
                if data['password1'] is not None and len(data['password1']):
                    c.account.password = generate_password_hash(
                        data['password1'])
                db.session.add(c.account)
                db.session.commit()
                h.flash_success(_("Your settings have been updated."))
            except colander.Invalid, i:
                errors = i.asdict()
Example #9
0
    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()
Example #10
0
    def settings(self):
        """
        Change settings for the logged in user
        """

        # The logged in user must be able to update the account
        require.account.update(c.account)

        # Disable the cache
        self._disable_cache()

        # Initial values and errors
        errors, values = {}, c.account

        # If POST the user is trying to update the settings
        if request.method == 'POST':
            try:
                # Get the account settings schema (for validation)
                schema = AccountSettings()

                # 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)

                # If the passwords don't match we notify the user
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountSettings.password1,
                                           _("Passwords don't match!"))

                # Update full name
                c.account.fullname = data['fullname']
                
                # Update the script root
                c.account.script_root = data['script_root']
                
                # Update email and whether email should be public
                c.account.email = data['email']
                c.account.public_email = data['public_email']

                # If twitter handle is provided we update it
                # (and if it should be public)
                if data['twitter'] is not None:
                    c.account.twitter_handle = data['twitter'].lstrip('@')
                    c.account.public_twitter = data['public_twitter']

                # If a new password was provided we update it as well
                if data['password1'] is not None and len(data['password1']):
                    c.account.password = generate_password_hash(data['password1'])

                # Do the actual update in the database
                db.session.add(c.account)
                db.session.commit()
                
                # Let the user know we've updated successfully
                h.flash_success(_("Your settings have been updated."))
            except colander.Invalid, i:
                # Load errors if we get here
                errors = i.asdict()
Example #11
0
    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)
Example #12
0
    def settings(self):
        """
        Change settings for the logged in user
        """

        # The logged in user must be able to update the account
        require.account.update(c.account)

        # Disable the cache
        self._disable_cache()

        # Initial values and errors
        errors, values = {}, c.account

        # If POST the user is trying to update the settings
        if request.method == 'POST':
            try:
                # Get the account settings schema (for validation)
                schema = AccountSettings()

                # 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)

                # If the passwords don't match we notify the user
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountSettings.password1,
                                           _("Passwords don't match!"))

                # Update full name
                c.account.fullname = data['fullname']

                # Update the script root
                c.account.script_root = data['script_root']

                # Update email and whether email should be public
                c.account.email = data['email']
                c.account.public_email = data['public_email']

                # If twitter handle is provided we update it
                # (and if it should be public)
                if data['twitter'] is not None:
                    c.account.twitter_handle = data['twitter'].lstrip('@')
                    c.account.public_twitter = data['public_twitter']

                # If a new password was provided we update it as well
                if data['password1'] is not None and len(data['password1']):
                    c.account.password = generate_password_hash(
                        data['password1'])

                # Do the actual update in the database
                db.session.add(c.account)
                db.session.commit()

                # Let the user know we've updated successfully
                h.flash_success(_("Your settings have been updated."))
            except colander.Invalid as i:
                # Load errors if we get here
                errors = i.asdict()
        else:
            # Get the account values to autofill the form
            values = c.account.as_dict()

            # We need to put public checks separately because they're not
            # a part of the dictionary representation of the account
            if c.account.public_email:
                values['public_email'] = c.account.public_email
            if c.account.public_twitter:
                values['public_twitter'] = c.account.public_twitter

        # Return the rendered template
        return templating.render('account/settings.html',
                                 form_fill=values,
                                 form_errors=errors)