Python flask.ext.login.current_user 模块,email() 实例源码

我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用flask.ext.login.current_user.email()

项目:Plog    作者:thundernet8    | 项目源码 | 文件源码
def find_pass():
    """ ?????? """
    form = FindPassForm()
    email = None
    if form.validate_on_submit():
        email = form.email.data
        form.email.data = ''
        user = User(email=email)
        if user and user.user_id:
            token = user.generate_reset_token(expiration=600)
            send_mail(email, Setting.get_setting('blog_name', 'Plog')+u'??????', 'auth/emails/find_pass',
                      username=user.nickname or user.name, blogname=Setting.get_setting('blog_name', 'Plog'),
                      token=token)
            message = u"?????????????????????, ????????????????????????"
        else:
            message = u"?????????, ?????"
        return render_template('utils/pure.html', message=message, title=u"????")  # TODO post redirect
    return render_template('auth/find_pass.html', form=form)
项目:mensa-tracker    作者:annyanich    | 项目源码 | 文件源码
def delete_email_address():

    if current_user.is_anonymous:
        flash('You need to be logged in to do that')
        return redirect(url_for('index'))

    try:
        current_user.email = None
        db.session.commit()
    except exc.SQLAlchemyError:
        #  TODO log this
        flash('Something went wrong while deleting your email from our database.')
        db.session.rollback()

    oauth = OAuthSignIn.get_provider('facebook')
    # Strip out the 'facebook$' at the start of the id
    user_id = re.findall('\d+', current_user.social_id)[0]
    permission_revoked = oauth.revoke_email_permission(user_id)

    if not permission_revoked:
        flash('There was a problem giving up the permission to access your email address.  '
              'It may be re-added to your account here the next time you sign in.  '
              'To permanently remove it, please use your privacy settings in Facebook.')

    return redirect(url_for('index'))
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        send_mail(user.email, '????', 'auth/email/confirm', user=user, token=token)
        flash('?????????')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)


# ????
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def reset_password(token):
    if current_user.is_authenticated:
        return redirect('main.index')
    form = ResetPasswordForm()
    if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user is None:
                flash('????!??????')
                form.email.data = ''
                return redirect(url_for('auth.reset_password'))
            else:
                if user.reset_password(token, form.password.data):
                    flash('?????????????')
                else:
                    flash('?????????????')
                    return redirect(url_for('auth.request_reset_password'))
                return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)


# ??????
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def password_reset_request():
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = PasswordResetRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            token = user.generate_reset_token()
            send_email(user.email, 'Reset Your Password',
                       'auth/email/reset_password',
                       user=user, token=token,
                       next=request.args.get('next'))
        flash('An email with instructions to reset your password has been '
              'sent to you.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
项目:project    作者:Junctionzc    | 项目源码 | 文件源码
def password_reset_request():
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = PasswordResetRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email = form.email.data).first()
        if user:
            token = user.generate_reset_token()
            send_email(user.email, 'Reset Your Password',
                       'auth/email/reset_password',
                       user = user, token = token,
                       next = request.args.get('next'))
        flash('An email with instructions to reset your password has been '
              'send to you.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form = form)
项目:Blog_Flask    作者:xiaohu2015    | 项目源码 | 文件源码
def pwd_reset_request():
    if not current_user.is_anonymous:  #???????????????
        return redirect('main.index')
    form = ResetpwdReqForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            token = user.generate_reset_token()
            send_email(user.email, 'Reset Your Password',
                       'auth/email/reset_password',
                       user=user, token=token,
                       next=request.args.get('next'))
            flash('???????????????')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)

#??????????
项目:Blog_Flask    作者:xiaohu2015    | 项目源码 | 文件源码
def password_reset(token):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = ResetpwdForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            return redirect('main.index')
        if user.reset_password(token, form.password.data):
            flash('??????.')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form=form)

#??????
项目:otp_demo_server    作者:ownpush    | 项目源码 | 文件源码
def test_validate_invalid_email_format(self):
        # Ensure invalid email format throws error.
        form = LoginForm(email='unknown', password='example')
        self.assertFalse(form.validate())
项目:Plog    作者:thundernet8    | 项目源码 | 文件源码
def resend_confirm_email():
    """ ???????????? """
    # ??????
    if current_user and current_user.is_logged_in:
        send_mail(current_user.email, Setting.get_setting('blog_name', 'Plog')+u'???????',
                  'auth/emails/email_reconfirm', username=current_user.nickname or current_user.name,
                  blogname=Setting.get_setting('blog_name', 'Plog'), token=current_user.generate_confirmation_token())
        message = u"???????????????????, ???????????????????"
    else:
        message = u"????, ?????, ??? cookie ??????????"
    return render_template('utils/pure.html', message=message, title=u"????")
项目:mensa-tracker    作者:annyanich    | 项目源码 | 文件源码
def oauth_rerequest_permissions():
    """
    Lets the user grant us permission to access their email address, should they
    have denied us permission the first time around.
    Sends them to Facebook's OAuth permissions dialog.
    """
    if current_user.is_anonymous:
        flash('You need to be logged in to do that.')
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider('facebook')
    return oauth.rerequest_permissions()
项目:mensa-tracker    作者:annyanich    | 项目源码 | 文件源码
def oauth_callback_authorize():
    if not current_user.is_anonymous:
        return redirect(url_for('index'))

    oauth = OAuthSignIn.get_provider('facebook')
    search_terms = request.args.get('search_terms_to_save', '')
    social_id, username, email, is_email_granted = oauth.callback_authorize(search_terms)
    if social_id is None:
        flash('Authentication failed.')
        return redirect(url_for('index'))

    user = User.query.filter_by(social_id=social_id).first()
    if not user:
        user = User(social_id=social_id, nickname=username, email=email)
        try:
            db.session.add(user)
            db.session.commit()
        except exc.SQLAlchemyError:
            flash('Something went wrong while adding you as a user.  Sorry!')
            #  TODO log this
            return redirect(url_for('index'))
    else:
        # Update email and nickname upon login to those provided by Facebook.
        if email and email != user.email:
            update_email_address(email)
        if username and username != user.nickname:
            update_nickname(username)

    login_user(user, True)

    return redirect(url_for('index', search_terms_to_save=search_terms))
项目:mensa-tracker    作者:annyanich    | 项目源码 | 文件源码
def update_email_address(email):
    try:
        current_user.email = email
        db.session.commit()
    except exc.SQLAlchemyError:
        #  TODO log this
        flash('Something went wrong while saving your email to our database.')
        db.session.rollback()
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data)
            flash('????!')
            return redirect(request.args.get('next') or url_for('main.index'))
        flash('?????????')
    return render_template('auth/login.html', form=form)

# ????
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def resend_confirmation():
    token = current_user.generate_confirmation_token()
    send_mail(current_user.email, 'Confirm Your Account', 'auth/email/confirm', user=current_user, token=token)
    flash('??????????????????????????')
    return redirect(url_for('main.index'))


# ????
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def request_reset_password():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            flash('???????????????????')
            return redirect(url_for('auth.login'))
        token = user.generate_reset_password_token()
        send_mail(form.email.data, '??????', 'auth/email/reset_password_confirm', user=user, token=token)
        flash('????????????????????????')
    return render_template('auth/reset_password_request.html', form=form)

# ????
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user,form.remember_me.data)
            return redirect(request.args.get('next') or url_for('main.index'))
        flash('Invalid username or password.')
    return render_template('auth/login.html',form=form)
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email,'Confirm Your Account','auth/email/confirm',user=user,token=token)

        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('main.index'))
    return render_template('auth/register.html',form=form)
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    oauth = OAuthSignIn.get_provider(provider)
    social_id, username, email = oauth.callback()
    if social_id is None:
        flash('Authentication failed.')
        return redirect(url_for('main.index'))
    user = User.query.filter_by(social_id=social_id).first()
    if not user:
        user = User(social_id=social_id, username=username, email=email,password=generate_pass(),confirmed=True)
        db.session.add(user)
        db.session.commit()
    login_user(user, True)
    return redirect(url_for('main.index'))
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def resend_confirmation():
    token = current_user.generate_confirmation_token()
    send_email(current_user.email, 'Confirm Your Account',
               'auth/email/confirm', user=current_user, token=token)
    flash('A new confirmation email has been sent to you by email.')
    return redirect(url_for('main.index'))
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
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)
            send_email(new_email, 'Confirm your email address',
                       'auth/email/change_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('main.index'))
        else:
            flash('Invalid email or password.')
    return render_template("auth/change_email.html", form=form)
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def change_email(token):
    if current_user.change_email(token):
        flash('Your email address has been updated.')
    else:
        flash('Invalid request.')
    return redirect(url_for('main.index'))
项目:project    作者:Junctionzc    | 项目源码 | 文件源码
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email = form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data)
            return redirect(request.args.get('next') or url_for('main.index'))
        flash('Invalid username or password.')
    return render_template('auth/login.html', form = form)
项目:project    作者:Junctionzc    | 项目源码 | 文件源码
def resend_confirmation():
    token = current_user.generate_confirmation_token()
    send_email(current_user.email, 'Confirm Your Account',
               'auth/email/confirm', user = current_user, token = token)
    flash('A new confirmation email has been sent to you by email.')
    return redirect(url_for('main.index'))
项目:project    作者:Junctionzc    | 项目源码 | 文件源码
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email = form.email.data,
                    username = form.username.data,
                    password = form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email, 'Confirm Your Account',
                   'auth/email/confirm', user = user, token = token)
        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', form = form)
项目:project    作者:Junctionzc    | 项目源码 | 文件源码
def password_reset(token):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email = form.email.data).first()
        if user is None:
            return redirect(url_for('main.index'))
        if user.reset_password(token, form.password.data):
            flash('Your password has been updated.')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form = form)
项目:project    作者:Junctionzc    | 项目源码 | 文件源码
def change_email(token):
    if current_user.change_email(token):
        flash('Your email address has been updated.')
    else:
        flash('Invalid request.')
    return redirect(url_for('main.index'))
项目:Blog_Flask    作者:xiaohu2015    | 项目源码 | 文件源码
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):   #????
            login_user(user, form.remember_me.data)    #????????????????
            #??????????
            return redirect(request.args.get('next') or url_for('main.index'))
        #???????????????
        flash('????????.')
    return render_template('auth/login.html', form=form)

#????
项目:Blog_Flask    作者:xiaohu2015    | 项目源码 | 文件源码
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data, username=form.username.data, \
        password=form.password.data)
        db.session.add(user)
        db.session.commit()  #?????????
        token = user.generate_confirmation_token()  #????????
        #??????
        send_email(user.email, 'Confirm Your Account', 'auth/email/confirm', user=user, token=token)
        flash('????????????.')
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', form=form)

#??????????
项目:Blog_Flask    作者:xiaohu2015    | 项目源码 | 文件源码
def resend_confirmation():
    token = current_user.generate_confirmation_token()
    send_email(current_user.email, 'Confirm Your Account',
               'auth/email/confirm', user=current_user, token=token)
    flash('??????????????.')
    return redirect(url_for('main.index'))

#??????
项目:Blog_Flask    作者:xiaohu2015    | 项目源码 | 文件源码
def change_email(token):
    if current_user.change_email(token):
        flash('Your email address has been updated.')
    else:
        flash('Invalid request.')
    return redirect(url_for('main.index'))