Exemplo n.º 1
0
 def authenticate(self, password):
     password = escape(unicode(password))
     log.debug(
         __name__ + ' :: Authenticating "{0}"/"{1}" '
         'on hash "{2}" ...'.format(self.name, password, self.pw_hash))
     if self.check_password(password):
         self.authenticated = True
     else:
         self.authenticated = False
Exemplo n.º 2
0
 def authenticate(self, password):
     password = escape(unicode(password))
     log.debug(__name__ + ' :: Authenticating "{0}"/"{1}" '
                              'on hash "{2}" ...'.
         format(self.name, password, self.pw_hash))
     if self.check_password(password):
         self.authenticated = True
     else:
         self.authenticated = False
Exemplo n.º 3
0
    def register_user(self):
        """ Writes the user credentials to the datastore. """

        # 1. Only users not already registered
        # 2. Ensure that the user is unique
        # 3. Write the user / pass to the db

        if not self.active:
            if not get_user(self.name, by_id=False):
                add_user(self.name, self.pw_hash)
                log.debug(__name__ + ' :: Added user {0}'.format(self.name))
            else:
                log.error(__name__ +
                          'Could not add user {0}'.format(self.name))
            self.active = True
Exemplo n.º 4
0
    def register_user(self):
        """ Writes the user credentials to the datastore. """

        # 1. Only users not already registered
        # 2. Ensure that the user is unique
        # 3. Write the user / pass to the db

        if not self.active:
            if not get_user(self.name, by_id=False):
                add_user(self.name, self.pw_hash)
                log.debug(__name__ + ' :: Added user {0}'.
                    format(self.name))
            else:
                log.error(__name__ + 'Could not add user {0}'.
                    format(self.name))
            self.active = True
Exemplo n.º 5
0
    def __init__(self, username, authenticated=False):

        self.name = escape(unicode(username))
        self.authenticated = authenticated

        user_ref =  get_user(username, by_id=False)
        if user_ref:
            self.id = unicode(user_ref[1])
            self.active = True
            self.pw_hash = unicode(str(user_ref[2]))
        else:
            self.id = None
            self.active = False
            self.pw_hash = None

        log.debug(__name__ + ' :: Initiatializing user obj. '
                                 'user: "******", '
                                 'is active: "{1}", '
                                 'is auth: {2}'.
            format(username, self.active, self.authenticated))
Exemplo n.º 6
0
    def __init__(self, username, authenticated=False):

        self.name = escape(unicode(username))
        self.authenticated = authenticated

        user_ref = get_user(username, by_id=False)
        if user_ref:
            self.id = unicode(user_ref[1])
            self.active = True
            self.pw_hash = unicode(str(user_ref[2]))
        else:
            self.id = None
            self.active = False
            self.pw_hash = None

        log.debug(
            __name__ + ' :: Initiatializing user obj. '
            'user: "******", '
            'is active: "{1}", '
            'is auth: {2}'.format(username, self.active, self.authenticated))
Exemplo n.º 7
0
def login():
    if request.method == 'POST' and 'username' in request.form:

        username = escape(unicode(str(request.form['username'])))
        passwd = escape(unicode(str(request.form['password'])))
        remember = request.form.get('remember', 'no') == 'yes'

        # Initialize user
        user_ref = APIUser(username)
        user_ref.authenticate(passwd)

        log.debug(
            __name__ +
            ' :: Authenticating "{0}"/"{1}" ...'.format(username, passwd))

        if user_ref.is_authenticated():
            login_user(user_ref, remember=remember)
            flash('Logged in.')
            return redirect(request.args.get('next') or url_for('api_root'))
        else:
            flash('Login failed.')
    return render_template('login.html')