コード例 #1
0
ファイル: app.py プロジェクト: benjaminjenkins1/magic_frame
def resend_otp():
    if request.method == 'GET':
        return render_template('resend.html', phone=session['phone'])
    if request.method == 'POST':
        phone_number = re.sub('[^0-9]', '', request.form['phone-number'])
        if len(phone_number) != 10:
            flash(
                'Oops, that didn\'t look like a phone number.<br>Please try again.'
            )
            return render_template('resend.html',
                                   phone=request.form['phone-number'])
        captcha_data = {
            'secret': RECAPTCHA_KEY,
            'response': request.form['g-recaptcha-response']
        }
        r = requests.post('https://www.google.com/recaptcha/api/siteverify',
                          data=captcha_data)
        if r.json()['success']:
            session['phone'] = request.form['phone-number']
            user = User(phone_number)
            user.add_otp()
            flash('Another code has been sent to ' +
                  request.form['phone-number'] + '.')
            return render_template('signin.html',
                                   page='code',
                                   phone_number=session['phone'])
        else:
            flash('Please complete the captcha.')
            return render_template('resend.html',
                                   phone=request.form['phone-number'])
コード例 #2
0
ファイル: app.py プロジェクト: benjaminjenkins1/magic_frame
def sign_in():
    if request.method == 'GET':
        if session.get('logged_in') is not None:
            return redirect('/photos')
        else:
            return render_template('signin.html', page='phone')
    elif request.method == 'POST':
        phone_number = re.sub('[^0-9]', '', request.form['phone-number'])
        if len(phone_number) != 10:
            flash(
                'Oops, that didn\'t look like a phone number.<br>Please try again.'
            )
            return render_template('signin.html', page='phone')
        session['phone'] = request.form['phone-number']
        # make a new otp for the phone number and send to code input
        user = User(phone_number)
        otp_age = user.otp_age()
        #print(otp_age)
        if otp_age is None or otp_age > OTP_COOLDOWN:
            user.add_otp()
        return render_template('signin.html',
                               page='code',
                               phone_number=session['phone'])