<commit_before>#!/usr/bin/env python
import re
import json

from flask import Flask, request, render_template, redirect
from werkzeug.datastructures import ImmutableOrderedMultiDict

import requests
import redis

import config

from user import User, UserPassword
from passwordly import generatePassword, createHash, checkHash
from util import db

app = Flask(__name__)

@app.route('/', methods=['GET'])
def landing(name=None):
  return render_template('public/index.htm', name=name)

@app.route('/', methods=['POST'])
def public_post(name=None):
  password = str(request.form['password'])
  identifier = str(request.form['identifier'])
  
  result = generatePassword(password, identifier)
  params = {
    'password': password,
    'hash': createHash(password),
    'identifier': identifier,
    'result': result
  }
  return render_template('public/password.htm', **params)

@app.route('/signup', methods=['POST'])
def signup():
  hash = str(request.form['hash'])
  identifier = str(request.form['identifier'])
  username = str(request.form['username'])
  
  error = None

  if User.fetch(db, username):
    error = "The username you selected is taken."
  elif not re.match(r'^[a-z]+$', username):
    error = 'Your username can only be made of lowercase letters'
  elif username in config.reserved:
    error = 'Sorry, the username you have selected is reserved'

  if error:
    params = {
      'hash': hash,
      'identifier': identifier,
      'new_username': username,
      'error': error
    }
    return render_template('public/password.htm', **params)
  else:
    db.hset('signups', username, json.dumps({
        'hash': hash,
        'identifier': identifier
      }))

    return redirect((config.paypal_url + '?cmd=_xclick' + \
        '&item_name=Signup+for+password.ly:+{username}' + \
        '&item_number={username}&amount=15&business={email}' + \
        '&custom={username}' + \
        '&currency_code=USD' + \
        '&cancel_return=http://password.ly/paypal/cancl' + \
        '&return=http://password.ly/{username}').format(
          username=username, email=config.paypal_email
        ))

@app.route('/user/get-sites', methods=['POST'])
def user_get_sites():
  username = str(request.form['username'])
  password = str(request.form['password'])

  user = User.fetch(db, username)

  sites = user and user.getSites(password)

  if sites is None:
    return '{"result": false, "sites": []}'
  else:
    return json.dumps({"result": True, "sites": sites})

@app.route('/<string:username>')
def user_landing(username):<commit_msg>Add notify_url for paypal ipn<commit_after>#!/usr/bin/env python
import re
import json

from flask import Flask, request, render_template, redirect
from werkzeug.datastructures import ImmutableOrderedMultiDict

import requests
import redis

import config

from user import User, UserPassword
from passwordly import generatePassword, createHash, checkHash
from util import db

app = Flask(__name__)

@app.route('/', methods=['GET'])
def landing(name=None):
  return render_template('public/index.htm', name=name)

@app.route('/', methods=['POST'])
def public_post(name=None):
  password = str(request.form['password'])
  identifier = str(request.form['identifier'])
  
  result = generatePassword(password, identifier)
  params = {
    'password': password,
    'hash': createHash(password),
    'identifier': identifier,
    'result': result
  }
  return render_template('public/password.htm', **params)

@app.route('/signup', methods=['POST'])
def signup():
  hash = str(request.form['hash'])
  identifier = str(request.form['identifier'])
  username = str(request.form['username'])
  
  error = None

  if User.fetch(db, username):
    error = "The username you selected is taken."
  elif not re.match(r'^[a-z]+$', username):
    error = 'Your username can only be made of lowercase letters'
  elif username in config.reserved:
    error = 'Sorry, the username you have selected is reserved'

  if error:
    params = {
      'hash': hash,
      'identifier': identifier,
      'new_username': username,
      'error': error
    }
    return render_template('public/password.htm', **params)
  else:
    db.hset('signups', username, json.dumps({
        'hash': hash,
        'identifier': identifier
      }))

    return redirect((config.paypal_url + '?cmd=_xclick' + \
        '&item_name=Signup+for+password.ly:+{username}' + \
        '&item_number={username}&amount=15&business={email}' + \
        '&custom={username}' + \
        '&currency_code=USD' + \
        '&notify_url={ipn}' + \
        '&cancel_return=http://password.ly/paypal/cancel' + \
        '&return=http://password.ly/{username}').format(
          username=username,
          email=config.paypal_email,
          ipn=config.ipn_url
        ))

@app.route('/user/get-sites', methods=['POST'])
def user_get_sites():
  username = str(request.form['username'])
  password = str(request.form['password'])

  user = User.fetch(db, username)

  sites = user and user.getSites(password)

  if sites is None:
    return '{"result": false, "sites": []}'
  else:
    return json.dumps({"result": True, "sites": sites})

@app.route('/<string:username>')
def user_landing(username):
{'fraction_non_alphanumeric': 0.15389048991354468, 'fraction_numerical': 0.0007684918347742555, 'mean_word_length': 3.8974600188146753, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4236956', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1592, 'n_words': 373}