Example #1
0
def email_signup_user(email, msg, settings, message_data):
    """Do the real import work

    :param iid: import id we need to pull and work on

    """
    from ~~~PROJNAME~~~.lib.message import InvitationMsg
    msg = InvitationMsg(email, msg, settings)
    status = msg.send(message_data)
    if status == 4:
#        from bookie.lib.applog import SignupLog
        trans = transaction.begin()
        LOG.info('Could not send smtp email to signup: ' + email)
        trans.commit()
Example #2
0
File: api.py Project: raowl/initpyr
def invite_user(request):
    """Invite a new user into the system.

    :param username: user that is requested we invite someone
    :param email: email address of the new user

    """
    params = request.params

    email = params.get('email', None)
    user = request.user

    if not email:
        # try to get it from the json body
        email = request.json_body.get('email', None)

    if not email:
        # if still no email, I give up!
        request.response.status_int = 406
        return _api_response(request, {
            'username': user.username,
            'error': "Please submit an email address"
        })

    # first see if the user is already in the system
    exists = UserMgr.get(email=email)
    if exists:
        request.response.status_int = 406
        return _api_response(request, {
            'username': exists.username,
            'error': "This user is already a user!"
        })

    new_user = user.invite(email)
    if new_user:
        LOG.error(new_user.username)
        # then this user is able to invite someone
        # log it
        AuthLog.reactivate(new_user.username)

        # and then send an email notification
        # @todo the email side of things
        settings = request.registry.settings
        msg = InvitationMsg(new_user.email,
                            "Enable your account",
                            settings)

        msg.send(
            request.route_url(
                'reset',
                username=new_user.username,
                reset_key=new_user.activation.code))
        return _api_response(request, {
            'message': 'You have invited: ' + new_user.email
        })
    else:
        # you have no invites
        request.response.status_int = 406
        return _api_response(request, {
            'username': user.username,
            'error': "You have no invites left at this time."
        })
Example #3
0
File: api.py Project: mazz/kifu
def invite_user(request):
    """Invite a new user into the system.

    :param username: user that is requested we invite someone
    :param email: email address of the new user

    """
    params = request.params

    email = params.get('email', None)
    user = request.user

    if not email:
        # try to get it from the json body
        email = request.json_body.get('email', None)

    if not email:
        # if still no email, I give up!
        request.response.status_int = 406
        return _api_response(request, {
            'username': user.username,
            'error': "Please submit an email address"
        })

    # first see if the user is already in the system
    exists = UserMgr.get(email=email)
    if exists:
        request.response.status_int = 406
        return _api_response(request, {
            'username': exists.username,
            'error': "This user is already a user!"
        })

    new_user = user.invite(email)
    if new_user:
        LOG.error(new_user.username)
        # then this user is able to invite someone
        # log it
        AuthLog.reactivate(new_user.username)

        # and then send an email notification
        # @todo the email side of things
        settings = request.registry.settings
        msg = InvitationMsg(new_user.email,
                            "Enable your account",
                            settings)

        msg.send(
            request.route_url(
                'reset',
                username=new_user.username,
                reset_key=new_user.activation.code))
        return _api_response(request, {
            'message': 'You have invited: ' + new_user.email
        })
    else:
        # you have no invites
        request.response.status_int = 406
        return _api_response(request, {
            'username': user.username,
            'error': "You have no invites left at this time."
        })