def referral_create(): if not use_referrals: return bad_request(web_utils.NOT_AVAILABLE) recipient, api_key, err_response = auth_request_get_single_param( db, "recipient") if err_response: return err_response if not utils.is_email(recipient): return bad_request(web_utils.INVALID_EMAIL) recipient = recipient.lower() user = User.from_email(db.session, recipient) if user: time.sleep(5) return bad_request(web_utils.USER_EXISTS) reward_sender_type = app.config["REFERRAL_REWARD_TYPE_SENDER"] reward_sender = app.config["REFERRAL_REWARD_SENDER"] reward_recipient_type = app.config["REFERRAL_REWARD_TYPE_RECIPIENT"] reward_recipient = app.config["REFERRAL_REWARD_RECIPIENT"] recipient_min_spend = app.config["REFERRAL_RECIPIENT_MIN_SPEND"] ref = Referral(api_key.user, recipient, reward_sender_type, reward_sender, reward_recipient_type, reward_recipient, recipient_min_spend) utils.email_referral(logger, ref) db.session.add(ref) db.session.commit() return 'ok'
def share_to_friends(): phone_numbers = request.values.get('Nums') referrer = request.values.get('From') user = User.objects(phone_number=str(referrer)[-10:]).first() time = request.values.get('Timestamp') for phone_number in phone_numbers: referral = Referral(phone_number=str(phone_number)[-10:], date_referred=datetime.datetime.fromtimestamp( time / 1000.0)) referral.save() user.referrals.append(referral) user.save() return jsonify(success=True)
def create(): """Create a new post for the current user.""" db_session = current_app.config["db_session"] user = db_session.query(User).filter(User.id_ == session.get("user_id")).first() if request.method == 'POST': content = {} content["user_id"] = user.id_ content["title"] = request.form['title'] content["enum"] = request.form['enum'] content["turnover"] = request.form['turnover'] pdate = request.form['project_date'] content["project_date"] = datetime.strptime(pdate, "%Y-%m-%d").date() content["budget"] = request.form['budget'] content["description"] = request.form['desc'] referral = Referral(**content) db_session.add(referral) db_session.commit() return redirect(url_for('index')) return render_template('blog/create.html', user=user)
def register(): from random import randint from sbb import application, db from lib.email2 import send_email from models import User, ReferralProgram, Account, Referral referral = None if 'referral' in session: referral = session['referral'] if request.method == 'GET': session['a'] = randint(1, 10) session['b'] = randint(1, 10) referral = None if 'referral' in session: referral = session['referral'] return render_template('home/register.html', referral=referral, a=session['a'], b=session['b']) form = RegistrationForm(request.form) if form.validate_on_submit(): captcha = form.captcha.data.strip() if captcha != '' and int(captcha) == session['a'] + session['b']: cur = User.query.filter_by(username=form.username.data).first() ecur = User.query.filter_by(email=form.email.data).first() if cur is None and ecur is None: # refereal program 521 rp = ReferralProgram.query.filter_by(id=1).first() # Account User account = Account(0, 0) account.referralProgram = rp db.session.add(account) #db.session.commit() user = User(username=form.username.data, password=form.password.data, email=form.email.data) user.account = account if form.fb.data != '': user.fb = form.fb.data if form.skype.data != '': user.skype = form.skype.data user.pin = form.pin_number.data db.session.add(user) #db.session.commit() # referral account refUsername = form.refemail.data.strip() if refUsername != '': refUser = User.query.filter_by( username=refUsername).first() if refUser: referral = Referral(accountId=account.id) referral.referralAccount = refUser.account db.session.add(referral) else: flash("Wrong referral. Referral data skiped.") db.session.commit() token = generate_confirmation_token(user.email, application.config) confirm_url = url_for('home.confirm_email', token=token, _external=True) html = render_template('home/activate_email.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(user.email, subject, html, application.config) login_user(user) flash('A confirmation email has been sent via email.', 'success') return redirect(url_for('home.unconfirmed')) else: flash('User with specified data already exists in a system', 'warning') else: flash("Wrong captcha") else: flash_errors(form) session['a'] = randint(1, 10) session['b'] = randint(1, 10) return render_template('home/register.html', referral=referral, a=session['a'], b=session['b'])