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 { '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 { 'username': exists.username, 'error': "This user is already a Bookie 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 Bookie account", settings) msg.send(request.route_url('reset', username=new_user.username, reset_key=new_user.activation.code)) return { 'message': 'You have invited: ' + new_user.email } else: # you have no invites request.response.status_int = 406 return { 'username': user.username, 'error': "You have no invites left at this time." }
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 { '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 { 'username': exists.username, 'error': "This user is already a Bookie 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 Bookie account", settings) msg.send( request.route_url('reset', username=new_user.username, reset_key=new_user.activation.code)) return {'message': 'You have invited: ' + new_user.email} else: # you have no invites request.response.status_int = 406 return { 'username': user.username, 'error': "You have no invites left at this time." }
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 bookie.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() SignupLog(SignupLog.ERROR, 'Could not send smtp email to signup: ' + email) trans.commit()