예제 #1
0
def signup_post():
    email = request.json['email']
    name = request.json['name']
    password = request.json['password']
    admin = False,
    confirmed = False,
    confirmed_on = datetime.datetime.now()
    token_confirmations = random_token()

    user = User.query.filter_by(email=email).first()

    if user:
        return jsonify({'mensaje': 'Ya te encuentras registrado'})

    new_user = User(email=email,
                    name=name,
                    confirmed=False,
                    token_confirmations=token_confirmations,
                    password=generate_password_hash(password, method='sha256'))

    msg = Message('Codigo de confirmacion',
                  sender='*****@*****.**',
                  recipients=[email])
    msg.body = "Su codigo de confirmacion es:" + str(token_confirmations)
    mail.send(msg)

    db.session.add(new_user)
    db.session.commit()

    return jsonify({'mensaje': 'Confirma el codigo enviado para ingresar'})
예제 #2
0
def generate_token(username, password):
    """Generate a secure token for the user"""
    data = {"username": username, "password": password}
    if not utils.login(data):
        return render_template('json.html', content=jsonify({"result": False}))
    token = utils.random_token()
    db = utils.get_db()
    while utils.row_exists(db, 'users', 'token', token):
        token = utils.random_token()
    utils.update('users', 'username = ? and password = ?', ['token'],
                 [token, username, password])
    return render_template('json.html',
                           content=jsonify({
                               "result": True,
                               "token": token
                           }))
예제 #3
0
 def create(cls, email_address):
     key = random_token([email_address.email])
     return cls._default_manager.create(email_address=email_address,
                                        key=key)
예제 #4
0
 def create(cls, email_address):
     key = random_token([email_address.email])
     return cls._default_manager.create(email_address=email_address, key=key)