Пример #1
0
def recover_password():
    """change_Password Form"""
    logger.info(str(request))
    email = request.form['email']
    if not check_mail(email):
        return jsonify(result='Not valid email'), 400

    new_password = randomPassword()

    try:
        data = User.query.filter_by(email=email).first()
        if data is not None and data.active:
            with app.app_context():
                data.password = hashlib.md5(new_password.encode()).hexdigest()
                new_action = Registry(username=data.username, action='recoverPassword')
                db.session.add(new_action)
                db.session.commit()
                msg = Message(subject='Password changed',
                              sender=app.config.get('MAIL_USERNAME'),
                              recipients=[email],  # replace with your email for testing
                              html=render_template('recover.html',
                                                   user=data.username, password=new_password))
                mail.send(msg)
            return jsonify(result='New password for ' + email + ' Look your email for getting it.')
        else:
            return jsonify(result='No user registered/active with that user/password'), 400
    except Exception as e:
        return jsonify(result=('Change password failed: ' + str(e))), 400
Пример #2
0
def notify_user(email, action):
    if action == 'delete':
        subject = 'Your account has been not validated'
        body = 'Dear sir or madam,\n\n' \
               'The Administrator decided to revoke your account creation. ' \
               'If you need access to the service, you should contact with the Admin before creating a new account.' \
               '\n\nThank you for your understanding,'
    else:
        subject = 'Your account has been validated'
        body = 'Dear sir or madam,\n\n' \
               'The Administrator decided to validate your account. ' \
               'Now you can access with your username and password. ' \
               '\n\nThanks for your patience and welcome,'

    msg = Message(subject=subject,
                  sender=app.config.get('MAIL_USERNAME'),
                  recipients=[email],  # replace with your email for testing
                  body=body)
    mail.send(msg)
Пример #3
0
def admin_confirmation(username, email):
    now = datetime.now()
    Etoken = jwt.JWT(header={'alg': 'A256KW', 'enc': 'A256CBC-HS512'},
                     claims={'username': username, 'email': email, 'action': 'delete', 'time': datetime.timestamp(now)})
    Etoken.make_encrypted_token(key)
    token_not_provide = str(Etoken.serialize())

    Etoken = jwt.JWT(header={'alg': 'A256KW', 'enc': 'A256CBC-HS512'},
                     claims={'username': username, 'email': email, 'action': 'activated',
                             'time': datetime.timestamp(now)})
    Etoken.make_encrypted_token(key)
    token_provide = str(Etoken.serialize())

    msg = Message(subject='User validation',
                  sender=app.config.get('MAIL_USERNAME'),
                  recipients=[app.config.get('MAIL_USERNAME')],  # replace with your email for testing
                  html=render_template('validate_user.html',
                                       user=username, email=email, token_provide=token_provide,
                                       token_not_provide=token_not_provide))
    mail.send(msg)
Пример #4
0
def admin_confirmation(email=None, username=None, platformName=None, ip=None):
    now = datetime.now()
    header_token = {'alg': 'A256KW', 'enc': 'A256CBC-HS512'}
    if username:
        claims_not_provide = {
            'username': username,
            'email': email,
            'action': 'delete',
            'time': datetime.timestamp(now)
        }
        claims_provide = {
            'username': username,
            'email': email,
            'action': 'activated',
            'time': datetime.timestamp(now)
        }
    else:

        claims_not_provide = {
            'platformName': platformName,
            'action': 'delete',
            'time': datetime.timestamp(now)
        }
        claims_provide = {
            'platformName': platformName,
            'action': 'activated',
            'time': datetime.timestamp(now)
        }

    Etoken = jwt.JWT(header=header_token, claims=claims_not_provide)
    Etoken.make_encrypted_token(key)
    token_not_provide = str(Etoken.serialize())

    Etoken = jwt.JWT(header=header_token, claims=claims_provide)
    Etoken.make_encrypted_token(key)
    token_provide = str(Etoken.serialize())

    if username:
        subject = 'User validation'
        url_yes = url_for('auth_page.validate_user',
                          data=token_provide,
                          _external=True)
        url_yes = proxify_url(url_yes)
        url_no = url_for('auth_page.validate_user',
                         data=token_not_provide,
                         _external=True)
        url_no = proxify_url(url_no)
        template = render_template('validate_user.html',
                                   user=username,
                                   email=email,
                                   url_yes=url_yes,
                                   url_no=url_no)
    else:
        subject = 'Platform validation'
        url_yes = url_for('auth_page.validate_platform',
                          data=token_provide,
                          _external=True)
        url_yes = proxify_url(url_yes)
        url_no = url_for('auth_page.validate_platform',
                         data=token_not_provide,
                         _external=True)
        url_no = proxify_url(url_no)
        template = render_template('validate_platform.html',
                                   current_platform=get_platform_name(),
                                   platform=platformName,
                                   ip=ip,
                                   url_yes=url_yes,
                                   url_no=url_no)

    msg = Message(
        subject=subject,
        sender=app.config.get('MAIL_USERNAME'),
        recipients=[app.config.get('MAIL_USERNAME')
                    ],  # replace with your email for testing
        html=template)
    try:
        mail.send(msg)
    except Exception:
        logger.error("Mail does not work properly")