Exemple #1
0
def activate_user(activation_code, new_password):
    """
    Entrypoint for activating a user. Also sets their password if 
    
    Args:
        activation_code:
            The activation code used to activate a user.
            
        new_password:
            The password that has to be set for the user
    
    Returns:
        A dictionary {'activated': True} if the user was successfully 
        activated. If no user was found matching the activation code, 
        the value will be False.
    """
    um = logic.UserManager()
    try:
        user = um.lookup_user_by_activation_code(activation_code)
        user.activate()
        user.set_password(new_password)
    except ex.UserNotFoundError:
        blogger.debug("no user found with activation code %s" % activation_code)
        transaction.abort()
        return dict(activated=False)
    else:
        transaction.commit()
        return dict(activated=True)
Exemple #2
0
def user_info(client_id, email):
    """
    Returns information about the user and his orders.
    """
    um = logic.UserManager()
    try:
        user = um.lookup_user_by_email(email)
        orders = om.get_orders_of_user(user.id)
    except ex.TickeeError as e:
        transaction.abort()
        return marshalling.error(e)
    except Exception as e:
        transaction.abort()
        return marshalling.internal_error(e)
    else:
        result = dict(first_name=user.first_name,
                      last_name=user.last_name,
                      email=user.email,
                      orders=map(lambda o: dict(id=o.id,
                                                tickets=map(lambda t: marshalling.ticket_to_dict(t, include_scanned=True,
                                                                                                 include_user=False), 
                                                            o.get_tickets()),
                                                status=o.status,
                                                date=marshalling.date(o.session_start)), 
                                 orders))
        return result
Exemple #3
0
 def test_lookup_user(self):
     # Setup
     um = logic.UserManager()
     # Test
     user = um.lookup_user_by_id(self.user.id)
     # Validate
     self.assertEqual(user.id, self.user.id, "User id's did not match.")
Exemple #4
0
 def test_reset_user(self):
     # Setup
     um = logic.UserManager()
     # Test
     um.reset_user(self.user.id)
     # Validate
     self.assertFalse(self.user.is_active(), "User is active.")
Exemple #5
0
def create_user(email, password):
    """
    Entrypoint for creating new users.
    
    Args:
        email:
            Personal email address of the user
        password:
            Password of the user.
            
    Returns:
        A dictionary containing the information of the newly created user
        including his identifier. A ``created`` key-value pair is added 
        indicating the success of the attempt. For example:
        
        {'created': True,
         'user': {"id": 42, 
                  "email": "*****@*****.**"}}
         
        The dictionary will only contain the created key if the attempt was not
        successful:
        
        {'created': False}
    """
    um = logic.UserManager()
    try:
        # validate if email contains actually a valid email address:
        validate_email(email)
        # create account
        user = um.create_user(email)
        if password:
            user.set_password(password)
        else:
            user.reset()
    except ex.TickeeError as e:
        transaction.abort()
        # build failed result
        return marshalling.error(e)
    except ValidationError as e:
        transaction.abort()
        return marshalling.error(e)
    else:
        user_info = marshalling.user_to_dict(user)
        transaction.commit()
        # build success result
        result = marshalling.created_success_dict.copy()
        result['user'] = user_info
        return result
Exemple #6
0
def user_exists(email):
    """
    Entrypoint for checking if a user with a given email already exists.
    
    Args:
        email:
            The email address that needs to be checked for existence.
            
    Returns:
        A dictionary {'exists': True} if it exists. If there is no user found
        with the email address, the value will be False.
    """
    um = logic.UserManager()
    try:
        user = um.lookup_user_by_email(email)
    except ex.TickeeError, e:
        transaction.abort()
        return dict(exists=False)
Exemple #7
0
def create_account(user_id, account_name, email):
    """
    Entrypoint for creating an account and returning its information back as a
    dictionary. 
    
    Args:
        user_id:
            Id of the user who will own the account
        account_name
            Name of the account to create
        email
            Email of the account. This should be a general email address
            and not a user-specific one.

    Returns:
        A dictionary containing the information of the newly created account
        including its identifier. A ``created`` key-value pair is added 
        indicating the success of the attempt. For example:
        
        {'created': True,
         'account': {"id": 42, "name": "Tickee", "email": "*****@*****.**"}}
         
        The dictionary will only contain the created key if the attempt was not
        successful:
        
        {'created': False}
    """
    am = logic.AccountManager()
    sm = logic.SecurityManager()
    try:
        # find user
        um = logic.UserManager()
        user = um.lookup_user_by_id(user_id)
        # create account
        account = am.create_account(account_name, email)
        # create default oauth2 client
        client = sm.create_oauth_client()
        account.client_id = client.id
    except ex.TickeeError, e:
        transaction.abort()
        # build failed result
        return marshalling.error(e)
Exemple #8
0
from tickee import logic
from tickee.db.models.event import Event
from tickee.db.models.user import User
import sqlahelper
import tests
import tickee.exceptions as ex

Session = sqlahelper.get_session()

um = logic.UserManager()


class CreateUserTest(tests.BaseTestCase):
    def setUp(self):
        super(CreateUserTest, self).setUp()

    def test_create_user(self):
        # Test
        user = User("*****@*****.**")
        # Validate
        self.assertFalse(user.has_usable_password())
        self.assertEquals("*****@*****.**", user.email)
        self.assertFalse(user.is_active())

    def test_activate_user(self):
        # Prepare
        user = User("*****@*****.**")
        activation_key = user.activation_key
        # Test
        user.activate(activation_key, "test")
        # Validate
Exemple #9
0
 def test_lookup_unexisting_user(self):
     # Setup
     um = logic.UserManager()
     # Test
     self.assertRaises(ex.UserNotFoundError, um.lookup_user_by_id, 999)
Exemple #10
0
 def test_reset_unexisting_user(self):
     # Setup
     um = logic.UserManager()
     # Test
     self.assertRaises(ex.UserNotFoundError, um.reset_user, 999)
Exemple #11
0
 def setUp(self):
     super(UserActions, self).setUp()
     # create user
     um = logic.UserManager()
     self.user = um.create_user("")
     self.user.activate(self.user.activation_key, "")
Exemple #12
0
 def test_create_existing_user(self):
     # Setup
     um = logic.UserManager()
     um.create_user("*****@*****.**")
     # Validate
     self.assertRaises(ex.UserError, um.create_user, "*****@*****.**")
Exemple #13
0
 def test_create_user(self):
     # Setup
     um = logic.UserManager()
     # Test
     um.create_user("")