예제 #1
0
 def test_AuthUser_check_password(self):
     """ Test the `check_password` method of the ``AuthUser`` model class.
     """
     self.dummy_user_fixture()
     from anuket.models.auth import AuthUser
     self.assertTrue(AuthUser.check_password(u'username', u'password'))
     self.assertFalse(AuthUser.check_password(u'username', u'wrongpass'))
     self.assertFalse(AuthUser.check_password(u'nobody', u'password'))
예제 #2
0
 def test_AuthUser_check_password(self):
     """ Test the `check_password` method of the ``AuthUser`` model class.
     """
     self.dummy_user_fixture()
     from anuket.models.auth import AuthUser
     self.assertTrue(AuthUser.check_password(u'username', u'password'))
     self.assertFalse(AuthUser.check_password(u'username', u'wrongpass'))
     self.assertFalse(AuthUser.check_password(u'nobody', u'password'))
예제 #3
0
파일: root.py 프로젝트: kailIII/anuket
def login_view(request):
    """ Render the login form.

    Display an empty login form or check the submited credentials with the ones
    from the database. Add a success flash message, an userid in the cookies
    and redirect to the home page if the credentials are goods. Add an error
    flash message and display again the login form if the credentials are
    wrong.

    :param request: a ``pyramid.request`` object
    """
    _ = request.translate
    form = Form(request, schema=LoginForm)
    if 'form_submitted' in request.params and form.validate():
        username = request.params['username']
        password = request.params['password']
        if AuthUser.check_password(username, password):
            auth_user = AuthUser.get_by_username(username)
            headers = remember(request, auth_user.user_id)
            request.session.flash(_(u"Successful login."), 'success')
            return HTTPFound(location=request.route_path('home'),
                             headers=headers)
        else:
            request.session.flash(_(u"Check your login credentials!"), 'error')
    return dict(renderer=FormRenderer(form))
예제 #4
0
파일: root.py 프로젝트: lazaret/anuket
def login_view(request):
    """ Render the login form.

    Display an empty login form or check the submited credentials with the ones
    from the database. Add a success flash message, an userid in the cookies
    and redirect to the home page if the credentials are goods. Add an error
    flash message and display again the login form if the credentials are
    wrong.

    :param request: a ``pyramid.request`` object
    """
    _ = request.translate
    form = Form(request, schema=LoginForm)
    if 'form_submitted' in request.params and form.validate():
        username = request.params['username']
        password = request.params['password']
        if AuthUser.check_password(username, password):
            auth_user = AuthUser.get_by_username(username)
            headers = remember(request, auth_user.user_id)
            request.session.flash(_(u"Successful login."),
                                  'success')
            return HTTPFound(location=request.route_path('home'),
                             headers=headers)
        else:
            request.session.flash(_(u"Check your login credentials!"),
                                  'error')
    return dict(renderer=FormRenderer(form))
예제 #5
0
 def test_initialize_db_default_values(self):
     """ Test than the `initialize_db` method add the default values to the
     initialized database.
     """
     command = self._makeOne()
     command.args.config_uri = self.config_uri
     command.initialize_db()
     from anuket.models.auth import AuthUser
     user = self.DBSession.query(AuthUser).filter_by().first()
     self.assertEqual(user.username, u'admin')
     self.assertTrue(AuthUser.check_password(u'admin', u'admin'))
     self.assertEqual(user.group.groupname, u'admins')
예제 #6
0
 def test_initialize_db_default_values(self):
     """ Test than the `initialize_db` method add the default values to the
     initialized database.
     """
     command = self._makeOne()
     command.args.config_uri = self.config_uri
     command.initialize_db()
     from anuket.models.auth import AuthUser
     user = self.DBSession.query(AuthUser).filter_by().first()
     self.assertEqual(user.username, u'admin')
     self.assertTrue(AuthUser.check_password(u'admin', u'admin'))
     self.assertEqual(user.group.groupname, u'admins')
예제 #7
0
파일: root.py 프로젝트: kailIII/anuket
def root_view(request):
    """ Render the root pages.

    Render the home page, the login page and 404 not found page.

    :param request: a ``pyramid.request`` object
    """
    _ = request.translate
    #check the default admin password if any admin is connected
    from pyramid.security import has_permission
    if has_permission('admin', request.context, request):
        if AuthUser.check_password(username=u'admin', password=u'admin'):
            request.session.flash(_("Change the default password!"), 'error')
    return dict()
예제 #8
0
파일: root.py 프로젝트: lazaret/anuket
def root_view(request):
    """ Render the root pages.

    Render the home page, the login page and 404 not found page.

    :param request: a ``pyramid.request`` object
    """
    _ = request.translate
    #check the default admin password if any admin is connected
    from pyramid.security import has_permission
    if has_permission('admin', request.context, request):
        if AuthUser.check_password(username=u'admin', password=u'admin'):
            request.session.flash(_("Change the default password!"),
                                  'error')
    return dict()