X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/blobdiff_plain/cc61c5969227c2d49544997ebbf074541029400b..c0233065b189d69f16d18cbdb2c4b503042bac51:/cas_provider/utils.py?ds=inline diff --git a/cas_provider/utils.py b/cas_provider/utils.py index 501f63a..04a5c12 100644 --- a/cas_provider/utils.py +++ b/cas_provider/utils.py @@ -3,16 +3,21 @@ import string from models import ServiceTicket, LoginTicket -def _generate_string(length=8, chars=string.letters + string.digits): - return ''.join(Random().sample(string.letters+string.digits, length)) +def _generate_string(length=8, chars=string.ascii_letters + string.digits): + """ Generates a random string of the requested length. Used for creation of tickets. """ + return ''.join(Random().sample(chars, length)) def create_service_ticket(user, service): + """ Creates a new service ticket for the specified user and service. + Uses _generate_string. + """ ticket_string = 'ST-' + _generate_string(29) # Total ticket length = 29 + 3 = 32 ticket = ServiceTicket(service=service, user=user, ticket=ticket_string) ticket.save() return ticket def create_login_ticket(): + """ Creates a new login ticket for the login form. Uses _generate_string. """ ticket_string = 'LT-' + _generate_string(29) ticket = LoginTicket(ticket=ticket_string) ticket.save()