Ejemplo n.º 1
0
def create_account(signup_form):
    """ Create Account
    
    signup_form:
     - email
     - password
     - firstname
    
    """
    
    # User exists
    try:
        if User.objects.get(username=signup_form['email'].value()):
            return {'email': 'You already have an account.'}
    except User.DoesNotExist:
        pass
    
    user = User()
    user.username = signup_form['email'].value()
    user.email = signup_form['email'].value()
    user.set_password(signup_form['password'].value())
    
    if signup_form['firstname'].value(): user.first_name = signup_form['firstname'].value()
        
    user.save()
    
    profile = user.get_profile()
    if signup_form['icon']: 
        profile.icon = signup_form['icon'].value()
    
    # Create the default board
    b = Board()
    b.creator = user
    b.title = 'home'
    b.id = 'home'
    profile.boards.append(b)
    profile.save()
        
    return {}
Ejemplo n.º 2
0
def add_board(action, user):
    """
    Adds a board.
    
    {
        'type': 'add_board',
        'what': {
            title: <board title>,
            id: <board id>
        }
    }
    
    """

    userprofile = user.get_profile()

    board = Board()
    board.title = action["what"]["title"]
    board.id = action["what"]["id"]
    userprofile.boards.append(board)
    userprofile.save()

    return board