Esempio n. 1
0
def forgot():
    session.pop('email', None)
    form = ForgotForm(request.form)
    if request.method == 'POST':
        if not form.validate():
            return render_template('forgot.html', form=form, user=get_user())
        else:
            user = User.query.filter_by(email=form.email.data.lower()).first()
            m = mail.mail()
            e = crypto.crypto()
            # get encrypted link
            encrypted = e.encrypt(user.id, True)
            # email link
            result = m.send_forgot_password(user.email, encrypted)
            form.email.errors.append(result)
            return render_template('forgot.html', form=form, user=get_user())
    else:
        return render_template('forgot.html', form=form, user=get_user())
Esempio n. 2
0
def password_reset(payload=None):
    form = PasswordForm()
    if request.method == 'POST':
        if not form.validate():
            return render_template('passwordreset.html', form=form, user=get_user(), msg=None)
        else:
            # update password
            reset_id = form.reset_id.data
            user = User.query.get(reset_id)
            if user:
                user.set_password(form.password.data)
                db.session.commit()
                msg = "password has been changed. please login again."
            else:
                msg = "user not found."
            return render_template('passwordreset.html', form=form, user=get_user(), msg=msg)
    else:
        e = crypto.crypto()
        decrypted = e.decrypt(payload, True)
        p = User.query.get(decrypted)
        if p:
            return render_template('passwordreset.html', form=form, user=p, msg=None)
        else:
            return render_template('passwordreset.html', form=form, user=get_user(), msg=decrypted)
Esempio n. 3
0
from mail import mail
from crypto import crypto
from threading import Thread

if __name__ == '__main__':
    encryption = crypto.crypto()
    
    encrypted = encryption.encrypt('payload', True)
    print('encrypted \t' + encrypted)
    
    decrypted = encryption.decrypt(encrypted, True)
    print('decrypted \t' + decrypted)
    
    mail = mail.mail()    
    thread = Thread(target = mail.send_forgot_password, args = ("[email protected]", encrypted, ))
    thread.start()
    thread.join()
    
    #mail.send_forgot_password("[email protected]", encrypted)