示例#1
0
def confirm_email(token):
    if current_user.is_authenticated:
        try:
            signature = URLSafeTimedSerializer(VAR_SAFE_TIMED_KEY)
            # check if URL correct and still valid
            signature.loads(token,
                            salt=VAR_MAIL_SALT + current_user.email,
                            max_age=VAR_TOKEN_MAX_AGE)
        except SignatureExpired:
            return '<h1>Старе посилання. Для підтвердження пошти зверніться до адміністратора.</h1><br> \
				   <a href="' + url_for('index') + '">Повернутись на сайт</a>'

        except BadSignature:
            return '<h1>Посилання не є дійсним. Для підтвердження пошти перейдіть по посиланню надісланому вам на пошту \
					або зверніться до адміністратора.</h1><br> \
							   <a href="' + url_for('index') + '">Повернутись на сайт</a>'

        # confirm user's email
        current_user.confirm_email(True)

        flash(
            'Пошта ' + current_user.email + ' прив\'язана до аккаунту - ' +
            current_user.username, 'success')
        return redirect(url_for('account'))
    else:
        flash('Спочатку авторизуйтесь!', 'danger')
        return redirect(url_for('login'))
示例#2
0
def change_email(token):
    # 确认token中的id信息
    if current_user.confirm_email(token=token):
        db.session.commit()
        flash('You have confirmed your email. Thanks!')
    else:
        flash('The confimed link is invalid or has expired.')
    return redirect(url_for('main.index'))
示例#3
0
def confirm_email(token):
    if getattr(current_user, 'confirmed', False):
        return redirct(
            url_for('main.userpage', user_slug=current_user.user_slug))
    if current_user.confirm_email(token):
        flash('You have successfully activated your account.', 'success')
    else:
        flash('Your account activation was denied', 'error')
    return redirect(url_for('main.index'))
示例#4
0
def update_email(token):
    input = current_user.confirm_email(token)
    if input[0]:
        flash(f'{input[1]}')
        db.session.commit()
        return redirect(url_for('.change_info'))
    else:
        flash(f'{input[1]}')
        return redirect(url_for('.change_info'))
示例#5
0
    def get(self, token):
        if current_user.is_email_confirmed:
            return redirect(url_for('accounts.password'))

        if current_user.confirm_email(token):
            flash('Your email has been confirmed', 'success')
        else:
            flash('The confirmation link is invalid or has expired', 'danger')

        return redirect(url_for('accounts.password'))
示例#6
0
    def get(self, token):
        if current_user.confirmed:
            return redirect(url_for('blog_admin.index'))

        if current_user.confirm_email(token):
            flash('Your email has been confirmed', 'success')
        else:
            flash('The confirmation link is invalid or has expired', 'danger')

        return redirect(url_for('blog_admin.index'))
示例#7
0
def confirm_email(token):
    if current_user.confirmed_email:
        return redirect(url_for('main.index'))

    if current_user.confirm_email(token):
        flash('Xác nhận email thành công.')
        current_user.notify_first_login()
    else:
        flash('Link xác nhận không chính xác hoặc đã hết hạn.')

    return redirect(url_for('main.index'))
示例#8
0
def confirm_email(token):
    if current_user.confirm_email(token):
        flash('Verification success!')
    else:
        flash('Verification failure!')
    return redirect(url_for('main.index'))
示例#9
0
def confirm_email(token):
    if current_user.confirm_email(token):
        flash('change email successfully')
    else:
        flash('wrong or expired token')
    return redirect(url_for('main.index'))
示例#10
0
def update_account():
    form = UpdateAccountForm()
    if current_user.is_authenticated:
        if request.method == 'POST':
            if form.validate_on_submit():
                email = form.email.data.lower()
                # user changing email address
                if current_user.email != email:
                    token = generate_confirmation_token(email)
                    msg = Message('confirm new email',
                                  sender='*****@*****.**',
                                  recipients=[email])
                    confirm_url = url_for('confirm_email',
                                          token=token,
                                          _external=True)
                    msg.html = render_template(
                        'emails/confirmation_email_change.html',
                        full_link=confirm_url)
                    try:
                        mail.send(msg)
                        current_user.username = form.username.data
                        current_user.email = email

                        # user's new email unconfirmed
                        current_user.confirm_email(False)
                        flash(
                            'Обліковий запис успішно відредаговано. Для підтвердження поштової адреси перейдіть по посиланню \
								яке було надіслано на адресу: ' + email, 'success')
                        print()
                        print(
                            colored(
                                'User new name: ' + form.username.data +
                                ' , changed email to: ' + email, 'blue'))
                        print(colored('token: ' + token, 'blue'))
                        print()
                        return redirect(url_for('account'))
                    # catch GMAIL/SMTP error here
                    except SMTPException:
                        # https://stackoverflow.com/a/16120288/10103803 - add
                        # logging here !!
                        print(
                            colored(
                                'User: '******' , email: ' +
                                email + ' didn\'t change account', 'red'))
                        print(colored("SMTP error ", 'red'))
                        flash(
                            'Щось пішло не так, спробуйте пізніше або зверніться до адміністратора!',
                            'danger')

                # user provided same email and username
                elif current_user.username == form.username.data and current_user.email == email:
                    flash(
                        'Ви ввели старе ім\'я та адресу, змініть хоча б шось одне з двох!',
                        'danger')
                # just change username
                else:
                    current_user.username = form.username.data
                    db.session.commit()
                    flash('Обліковий запис успішно відредаговано.', 'success')
                    print()
                    print(
                        colored(
                            "User new name: " + form.username.data +
                            " , old email : " + email, 'blue'))
                    print()
                    return redirect(url_for('account'))

        elif request.method == 'GET':
            return render_template('update_account.html',
                                   title='Редагувати профіль',
                                   form=form,
                                   legend='Редагувати профіль')

    else:
        flash('Спочатку увійдіть у свій обліковий запис', 'danger')
        return redirect(url_for('login'))

    return render_template('update_account.html',
                           title='Редагувати профіль',
                           form=form,
                           legend='Редагувати профіль')