1 from random import Random
4 from cas_provider.models import ServiceTicket, LoginTicket
6 def _generate_string(length=8, chars=string.ascii_letters + string.digits):
7 """ Generates a random string of the requested length. Used for creation of tickets. """
8 return ''.join(Random().sample(chars, length))
10 def create_service_ticket(user, service):
11 """ Creates a new service ticket for the specified user and service.
12 Uses _generate_string.
14 ticket_string = 'ST-' + _generate_string(29) # Total ticket length = 29 + 3 = 32
15 ticket = ServiceTicket(service=service, user=user, ticket=ticket_string)
19 def create_login_ticket():
20 """ Creates a new login ticket for the login form. Uses _generate_string. """
21 ticket_string = 'LT-' + _generate_string(29)
22 ticket = LoginTicket(ticket=ticket_string)