source: TracAccountManager/0.10/acct_mgr/http.py @ 14

Last change on this file since 14 was 2, checked in by guillaume, 17 years ago

Ajout TracAccountManager en français

File size: 1.1 KB
RevLine 
[2]1# -*- coding: utf8 -*-
2#
3# Copyright (C) 2005 Matthew Good <trac@matt-good.net>
4#
5# "THE BEER-WARE LICENSE" (Revision 42):
6# <trac@matt-good.net> wrote this file.  As long as you retain this notice you
7# can do whatever you want with this stuff. If we meet some day, and you think
8# this stuff is worth it, you can buy me a beer in return.   Matthew Good
9#
10# Author: Matthew Good <trac@matt-good.net>
11
12from urllib2 import build_opener, HTTPBasicAuthHandler, \
13                    HTTPDigestAuthHandler, HTTPPasswordMgrWithDefaultRealm
14
15from trac.core import *
16from trac.config import Option
17
18from api import IPasswordStore
19
20class HttpAuthStore(Component):
21    implements(IPasswordStore)
22
23    auth_url = Option('account-manager', 'authentication_url')
24
25    def check_password(self, user, password):
26        mgr = HTTPPasswordMgrWithDefaultRealm()
27        mgr.add_password(None, self.auth_url, user, password)
28        try:
29            build_opener(HTTPBasicAuthHandler(mgr),
30                         HTTPDigestAuthHandler(mgr)).open(self.auth_url)
31        except IOError:
32            return False
33        else:
34            return True
35
Note: See TracBrowser for help on using the repository browser.