Пример #1
0
def password_reset_request():
    if not current_user.is_anonymous():
        flash('To reset your password logout first please.')
        return redirect(url_for('general.index'))
    form = PasswordResetRequestForm()
    if form.validate_on_submit():
        user = g.db.query(User).\
            filter_by(profireader_email=form.email.data).first()
        if user.is_banned():
            return redirect(url_for('general.index'))
        if user:
            token = user.generate_reset_token()
            SendEmail().send_email(subject='Reset Your Password',
                                   template='auth/email/reset_password',
                                   send_to=(user.profireader_email, ),
                                   user=user,
                                   token=token,
                                   next=request.args.get('next'))
            flash(
                'An email with instructions to reset your password has been sent to you.'
            )
        else:
            flash(
                'You are not Profireader user yet. Sign up Profireader first please.'
            )
        return redirect(
            url_for('auth.login_signup_endpoint') + '?login_signup=login')
    return render_template('auth/reset_password.html', form=form)
Пример #2
0
def resend_confirmation(json):
    current_user.generate_confirmation_token().save()
    SendEmail().send_email(subject='Confirm Your Account',
                           html=render_template('auth/email/resend_confirmation.html', user=current_user),
                           send_to=(current_user.profireader_email, ))
    flash('A new confirmation email has been sent to you by email.')
    return True
Пример #3
0
def help_message(json):

        SendEmail().send_email(subject='Send help message', send_to=("*****@*****.**", ''),
                               html=('From '+json['data']['email']+': '+json['data']['message']))

        flash('Your message has been sent! ')
        redirect(url_for('reader.list_reader'))
        return True
Пример #4
0
def resend_confirmation():
    token = current_user.generate_confirmation_token()
    SendEmail().send_email(subject='Confirm Your Account',
                           template='auth/email/confirm',
                           send_to=(current_user.profireader_email, ),
                           user=current_user,
                           token=token)
    flash('A new confirmation email has been sent to you by email.')
    return redirect(url_for('general.index'))
Пример #5
0
def signup():

    # if g.user_init and g.user_init.is_authenticated():

    email = request.form.get('email')
    display_name = request.form.get('display_name')
    password = request.form.get('password')

    def check_fields():
        form = request.form
        required_fields = ['email', 'display_name', 'password', 'password1']
        for field in required_fields:
            if field not in form.keys():
                return False
            else:
                if not form.get(field):
                    return False
                elif form.get('password') != form.get('password1'):
                    return False
        if db(User, profireader_email=request.form.get('email')).first():
            flash('User with this email already exist')
            return False
        return True

    if check_fields():  # # pass1 == pass2
        profireader_all = SOC_NET_NONE['profireader'].copy()
        profireader_all['email'] = email
        profireader_all['name'] = display_name
        user = User(
            PROFIREADER_ALL=profireader_all,
            password=password  # # pass is automatically hashed
        )
        user.avatar('gravatar', size=AVATAR_SIZE, small_size=AVATAR_SMALL_SIZE)
        user.generate_confirmation_token()
        g.db.add(user)
        g.db.commit()
        addtourl = {}
        if session.get('portal_id'):
            addtourl['subscribe_to_portal'] = session['portal_id']
            session.pop('portal_id')
        SendEmail().send_email(subject='Confirm Your Account',
                               html=render_template(
                                   'auth/email/resend_confirmation.html',
                                   user=user,
                                   addtourl=addtourl),
                               send_to=(user.profireader_email, ))
        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('auth.login_signup_endpoint'))
    return render_template('auth/login_signup.html', login_signup='signup')
Пример #6
0
def password_reset_request(json):
    if not current_user.is_anonymous():
        flash('To reset your password logout first please.')
        redirect(url_for('reader.list_reader'))
        return False

    user = db(User, profireader_email=json.get('email')).first()
    if user:
        user.generate_pass_reset_token().save()
        SendEmail().send_email(subject='Reset password', send_to=(user.profireader_email, ""),
                               html=render_template('auth/email/reset_password.html', user=user),)
        flash('An email with instructions to reset your password has been sent to you.')
        redirect(url_for('auth.login_signup_endpoint') + '?login_signup=login')
    else:
        flash('You are not Profireader user yet. Sign up Profireader first please.')
    return {}
Пример #7
0
def help_message(json):
    if not 'email' in json['data']:
        return 'Please enter valid email!'
    else:
        print(json['data']['email'])
    if not 'message' in json['data']:
        return 'Please write message!'

    SendEmail().send_email(subject='Send help message',
                           send_to=("*****@*****.**", ''),
                           html=('From ' + json['data']['email'] + ': ' +
                                 json['data']['message']))

    flash('Your message has been sent! ')
    redirect(url_for('reader.list_reader'))
    return True
Пример #8
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            SendEmail().send_email(subject='Confirm your email address',
                                   template='auth/email/change_email',
                                   send_to=(new_email, ),
                                   user=current_user,
                                   token=token)
            flash(
                'An email with instructions to confirm your new email address has been sent to you.'
            )
            return redirect(url_for('general.index'))
        else:
            flash('Invalid email or password.')
    return render_template("auth/change_email.html", form=form)
Пример #9
0
def signup():
    # if g.user_init and g.user_init.is_authenticated():
    if g.user_init.is_authenticated():
        # raise BadDataProvided
        flash(
            'You are already logged in. To sign up Profireader with new account you should logout first'
        )
        return redirect(
            url_for('auth.login_signup_endpoint') + '?login_signup=signup')

    signup_form = RegistrationForm()
    login_form = LoginForm()
    if signup_form.validate_on_submit():  # # pass1 == pass2
        profireader_all = SOC_NET_NONE['profireader'].copy()
        profireader_all['email'] = signup_form.email.data
        profireader_all['name'] = signup_form.displayname.data
        user = User(
            PROFIREADER_ALL=profireader_all,
            password=signup_form.password.
            data  # # pass is automatically hashed
        )
        user.avatar('gravatar', size=AVATAR_SIZE, small_size=AVATAR_SMALL_SIZE)
        # # user.password = signup_form.password.data  # pass is automatically hashed

        g.db.add(user)
        g.db.commit()
        token = user.generate_confirmation_token()
        SendEmail().send_email(subject='Confirm Your Account',
                               template='auth/email/confirm',
                               send_to=(user.profireader_email, ),
                               user=user,
                               token=token)
        flash('A confirmation email has been sent to you by email.')
        # return redirect(url_for('auth.login_signup_endpoint') + '?login_signup=login')
        return redirect(url_for('auth.login_signup_endpoint'))
    return render_template('auth/login_signup.html',
                           login_signup='signup',
                           login_form=login_form,
                           signup_form=signup_form)