Esempio n. 1
0
    def post(self):
        """Attempts to create an account with the credentials provided in the
        post arguments.

        Successful creation logs the user in and sends them to '/'.

        Failure returns the user to the account create screen and tells them
        what went wrong.
        """
        username = self.get_argument('username')
        password = self.get_argument('password')
        email = self.get_argument('email')

        try:
            u = User.create_user(username, password, email)
            u.validate()
            save_user(self.db_conn, u)
        except Exception, e:
            logging.error('Credentials failed')
            logging.error(e)
            return self.render_template('accounts/create.html')
Esempio n. 2
0
    def post(self):
        """Attempts to create an account with the credentials provided in the
        post arguments.

        Successful creation logs the user in and sends them to '/'.

        Failure returns the user to the account create screen and tells them
        what went wrong.
        """
        username = self.get_argument('username')
        password = self.get_argument('password')
        email = self.get_argument('email')

        try:
            u = User.create_user(username, password, email)
            u.validate()
            save_user(self.db_conn, u)
        except Exception, e:
            logging.error('Credentials failed')
            logging.error(e)
            return self.render_template('accounts/create.html')
Esempio n. 3
0
#!/usr/bin/env python

from brubeck.request_handling import Brubeck, WebMessageHandler
from brubeck.models import User
from brubeck.auth import web_authenticated, UserHandlingMixin
from brubeck.templating import Jinja2Rendering, load_jinja2_env
from brubeck.connections import Mongrel2Connection
import sys
import logging

###
### Hardcoded authentication
###

demo_user = User.create_user('jd', 'foo')

class CustomAuthMixin(WebMessageHandler, UserHandlingMixin):
    """This Mixin provides a `get_current_user` implementation that
    validates auth against our hardcoded user: `demo_user`
    """
    def get_current_user(self):
        """Attempts to load user information from cookie. If that
        fails, it looks for credentials as arguments.

        If then attempts auth with the found credentials.
        """
        # Try loading credentials from cookie
        username = self.get_cookie('username')
        password = self.get_cookie('password')

        # Fall back to args if cookie isn't provided
Esempio n. 4
0
#!/usr/bin/env python

import sys
import logging
from brubeck.request_handling import Brubeck, WebMessageHandler
from brubeck.models import User
from brubeck.auth import authenticated, UserHandlingMixin

### Hardcode a user for the demo
demo_user = User.create_user('jd', 'foo')


class DemoHandler(WebMessageHandler, UserHandlingMixin):
    def get_current_user(self):
        """Attempts to load authentication credentials from a request and validate
        them. Returns an instantiated User if credentials were good.

        `get_current_user` is a callback triggered by decorating a function
        with @authenticated.
        """
        username = self.get_argument('username')
        password = self.get_argument('password')

        if demo_user.username != username:
            logging.error('Auth fail: username incorrect')
            return

        if not demo_user.check_password(password):
            logging.error('Auth fail: password incorrect')
            return
Esempio n. 5
0
#!/usr/bin/env python

import sys
import logging
from brubeck.request_handling import Brubeck, WebMessageHandler
from brubeck.models import User
from brubeck.auth import web_authenticated, UserHandlingMixin
from brubeck.templating import Jinja2Rendering, load_jinja2_env

###
### Hardcoded authentication
###

demo_user = User.create_user("jd", "foo")


class CustomAuthMixin(WebMessageHandler, UserHandlingMixin):
    """This Mixin provides a `get_current_user` implementation that
    validates auth against our hardcoded user: `demo_user`
    """

    def get_current_user(self):
        """Attempts to load user information from cookie. If that
        fails, it looks for credentials as arguments.

        If then attempts auth with the found credentials.
        """
        # Try loading credentials from cookie
        username = self.get_cookie("username")
        password = self.get_cookie("password")