Example #1
0
def check_duplicate_name(form, field):
    name = field.data
    existing = operators.get_by_username(name, assert_exists=False)
    if existing:
        if not hasattr(form, 'operator_id') or (hasattr(form, 'operator_id') and \
                                             existing.id != form.operator_id.data):
            raise ValidationError("Operator \"{0}\" already exists.".format(name))
Example #2
0
 def authenticate(self, username, password):
     """
     This function will check the password passed in for the given
     userid against the database, and raise an exception if the authentication
     failse.
     
     :raise :class:`ensconce.exc.InvalidCredentials`: If username and/or password are invalid.
     """
     try:
         user = operators.get_by_username(username)
         if not pwhash.compare(user.password, password):
             raise exc.InvalidCredentials()
     except exc.NoSuchEntity:
         log.exception("No matching user.")
         raise exc.InvalidCredentials()
Example #3
0
 def test_edit_password(self):
     """
     Test changing password.
     """
     # We want to edit the username for an arbitrary not-externally-managed user.
     operator = operators.get_by_username("op1")
 
     new_password = "******"
     self.open_url('/user/edit/{0}'.format(operator.id))
     el = self.wd.find_element(By.ID, "password")
     el.clear()
     el.send_keys(new_password)
     self.submit_form("operator_form")
 
     self.assertEqual("Operator List", self.wd.title)
     self.assert_in_list_table("op1")
     
     self.logout()
     self.login("op1", new_password) # pw from test data; we did not change it.
     self.logout()
     self.fail_login("op1", "pw1")
     
Example #4
0
 def test_edit_username(self):
     """
     Test changing username.
     """
     # We want to edit the username for an arbitrary not-externally-managed user.
     operator = operators.get_by_username("op1")
 
     old_username = operator.username
     new_username = operator.username + "-new"
     
     self.open_url('/user/edit/{0}'.format(operator.id))
     el = self.wd.find_element(By.ID, "username")
     el.clear()
     el.send_keys(new_username)
     self.submit_form("operator_form")
 
     self.assertEqual("Operator List", self.wd.title)
     self.assert_in_list_table(new_username)
     self.assert_not_in_list_table(old_username)
     
     self.logout()
     self.login(new_username, "pw1") # pw from test data; we did not change it.
Example #5
0
 def wrapped(self, *args, **kwargs):
     user = operators.get_by_username(cherrypy.request.login)
     cherrypy.session['username'] = user.username # @UndefinedVariable
     cherrypy.session['user_id'] = user.id # @UndefinedVariable
     return f(self, *args, **kwargs)
Example #6
0
 def resolve_user(self, username):
     """
     Resolves the specified username to a database user, creating one if necessary.
     :rtype: :class:`ensconce.model.Operator` 
     """
     return operators.get_by_username(username)