def post(self): """Create the new member. """ logging.info('SelfJoinPage.POST') logging.info('headers: %s', self.request.headers.items()) logging.info('params: %s', self.request.params.items()) logging.info('cookies: %s', self.request.cookies.items()) logging.info('body: %s', self.request.body) # Make sure (as best we can) that this is being requested from a site # that's allowed to embed our join form. # This is such a weak check that I'm not sure it's worth it. #if not config.DEBUG: # if not self.request.referer or \ # urlparse(self.request.referer).hostname not in config.ALLOWED_EMBED_REFERERS: # webapp2.abort(403, detail='bad referer') # HACK: Safari doesn't allow cookie setting in an iframe without # direct user interaction. So this fails every time on desktop and # mobile Safari. # TODO: Use new CSRF approach that doesn't need cookies. #helpers.check_csrf(self.request) # TODO: Don't hardcode key referrer = self.request.params.get('_referrer') or self.request.referer # Create a dict of the member info. new_member = gapps.member_dict_from_request(self.request, referrer, 'join') # "Paid" field shouldn't be set by form in self-serve. new_member[config.MEMBER_FIELDS.paid.name] = 'N' if self.request.params.get('payment_method') == 'paypal': new_member[config.MEMBER_FIELDS.paid.name] = 'paypal' # Write the member info to the member candidate store. member_candidate = MemberCandidate( member_json=webapp2_extras.json.encode(new_member), created=datetime.datetime.now(), expire=datetime.datetime.now()+datetime.timedelta(days=1)) member_candidate_key = member_candidate.put() invoice_id = member_candidate_key.urlsafe() # If the payment method is "cheque" create the new member directly, # otherwise start the PayPal process. # TODO: Don't hardcode field name if self.request.params.get('payment_method') == 'cheque': params = {'invoice': invoice_id} taskqueue.add(url='/self-serve/process-member-worker', params=params) self.response.write('success') else: # We put the key value into the URL so we can retrieve this member # after payment. paypal_url = config.PAYPAL_PAYMENT_URL % (invoice_id,) self.response.write(paypal_url)
def submit_renew_member(): """Processing the member renewal form. """ user_email = flask_login.current_user.id renew_member = gapps.member_dict_from_request(flask.request, user_email, 'renew') gapps.renew_member_from_dict(renew_member) # Enqueue the renewal email gapps.enqueue_task('/tasks/renew-member-mail', renew_member) return 'success'
def post(self): helpers.check_csrf(self.request) user = users.get_current_user() if not user or not gapps.is_user_authorized(user): detail = 'user not authorized' if user else 'user not logged in' webapp2.abort(401, detail=detail) renew_member = gapps.member_dict_from_request(self.request, user.email(), 'renew') gapps.renew_member_from_dict(renew_member) self.response.write('success') # Queue the welcome email taskqueue.add(url='/tasks/renew-member-mail', params=renew_member)
def submit_new_member(): """Create the new member. '409 Conflict' is thrown if the email address is already associated with an existing member. """ user_email = flask_login.current_user.id new_member = gapps.member_dict_from_request(flask.request, user_email, 'join') join_or_renew = gapps.join_or_renew_member_from_dict(new_member) if join_or_renew == 'join': # Enqueue the welcome email gapps.enqueue_task('/tasks/new-member-mail', new_member) # else the member already existed and we're going to email. This is especially # important because App Engine 500s even after a successful member creation. We don't # want a retry to spam the member. return f'success: {join_or_renew}'
def post(self): """Create the new member. '409 Conflict' is thrown if the email address is already associated with an existing member. """ helpers.check_csrf(self.request) user = users.get_current_user() if not user or not gapps.is_user_authorized(user): detail = 'user not authorized' if user else 'user not logged in' webapp2.abort(401, detail=detail) new_member = gapps.member_dict_from_request(self.request, user.email(), 'join') join_or_renew = gapps.join_or_renew_member_from_dict(new_member) self.response.write('success: %s' % join_or_renew) # Queue the welcome email taskqueue.add(url='/tasks/new-member-mail', params=new_member)
def submit_join(): """Handle submission of the embedded member self-registration form. """ logging.info('self_serve.submit_join') logging.info('headers: %s', list(flask.request.headers.items())) logging.info('values: %s', list(flask.request.values.items())) referrer = flask.request.values.get( _EMBEDDER_VALUE_KEY) or flask.request.referrer or flask.request.origin # Create a dict of the member info. new_member = gapps.member_dict_from_request(flask.request, referrer, 'join') # "Paid" field shouldn't be set by form in self-serve. new_member[config.SHEETS.member.fields.paid.name] = 'N' if flask.request.values.get(_PAYMENT_METHOD_VALUE_KEY) == 'paypal': new_member[config.SHEETS.member.fields.paid.name] = 'paypal' # Write the member info to the member candidate store. # This will be retrieved for processing by process_member_worker() member_candidate = MemberCandidate( member_json=flask.json.dumps(new_member), created=datetime.datetime.now(), expire=datetime.datetime.now() + datetime.timedelta(days=1)) member_candidate_key = member_candidate.store() invoice_id = member_candidate_key.urlsafe().decode('ascii') # If the payment method is "cheque" create the new member directly, # otherwise start the PayPal process. if flask.request.values.get(_PAYMENT_METHOD_VALUE_KEY) == 'cheque': params = {'invoice': invoice_id} gapps.enqueue_task('/self-serve/process-member-worker', params) return 'success' logging.debug('self_serve.submit_join: awaiting PayPal IPN') # We put the key value into the URL so we can retrieve this member # after payment. paypal_url = config.PAYPAL_PAYMENT_URL % (invoice_id, ) # If this is the demo server, then we skip PayPal and just create the user. if config.DEMO: params = { 'payer_email': new_member.get(config.SHEETS.member.fields.email.name), 'payer_id': 'FAKE-ID', 'first_name': new_member.get(config.SHEETS.member.fields.first_name.name), 'last_name': new_member.get(config.SHEETS.member.fields.last_name.name), 'invoice': invoice_id, } gapps.enqueue_task('/self-serve/process-member-worker', params) return 'demo' # Write the URL in the response so it can be shown to the user for follow-up return paypal_url