def login(): if current_user.is_authenticated: if current_user.is_confirmed(): print("authenticated, confirmed") return redirect(url_for('index')) if not current_user.is_confirmed(): token = generate_confirmation_token(current_user.email) confirm_url = url_for('confirm_email', token=token, _external=True) email_sender.send(json.dumps({"email": current_user.email, "token":confirm_url})) flash('To complete your registration, confirm your email') print("authenticated, not confirmed") logout_user() return redirect(url_for('login')) form = LoginForm() if form.validate_on_submit(): user = USM.select(form.username.data, category='login') if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) if user.confirmed: print("authenticated, confirmed after login") next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) else: print("authenticated, not confirmed after login") token = generate_confirmation_token(user.email) confirm_url = url_for('confirm_email', token=token, _external=True) email_sender.send(json.dumps({"email": user.email, "token":confirm_url})) flash('Uups, you have not confirmed your email.') logout_user() return redirect(url_for('login')) return render_template('login.html', title='Sign In', form=form)
def check_paste(): if current_user.is_confirmed(): flash("您已认证") return redirect('/') class queryform(FlaskForm): username = StringField('用户名', validators=[DataRequired(), Length(1, 20)]) luoguid = StringField('洛谷ID', validators=[DataRequired(), Length(1, 20)]) paste = StringField( '剪贴板ID', validators=[DataRequired(), Length(1, 20), CheckPaste()]) submit = SubmitField('查询') form = queryform() if form.validate_on_submit(): luser = LuoguUser.query.filter( LuoguUser.uid == form.luoguid.data).first() if not luser: flash("洛谷用户不存在,请尝试加入") return render_template("check_paste.html", form=form) if luser.user: flash("该用户已被认证!") return redirect('/') current_user.luogu_user = luser db.session.commit() return redirect('/') return render_template("check_paste.html", form=form)
def decorated_function(*args, **kwargs): if not current_user or not current_user.is_authenticated: return err('You must be logged in to access this page') if current_user and not current_user.is_confirmed(): logout_user() return err('Please verify your email first') return f(*args, **kwargs)
def login(): if current_user is not None and current_user.is_authenticated() \ and current_user.is_confirmed(): return redirect(url_for('main.index')) 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) \ and user.is_confirmed(): login_user(user, form.remember_me.data) return redirect( request.args.get('next', '') or url_for('main.index')) flash(u'Invalid combination', 'warning') return render_template('user/login.html', form=form)
def login(): if current_user is not None and current_user.is_authenticated() \ and current_user.is_confirmed(): return redirect(url_for('main.index')) 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) \ and user.is_confirmed(): login_user(user, form.remember_me.data) return redirect(request.args.get('next', '') or url_for('main.index')) flash(u'Invalid combination', 'warning') return render_template('user/login.html', form=form)
def index(): if not current_user.is_confirmed(): flash('Uups, you have not confirmed your email.') return redirect(url_for('login')) posts = [ { 'author': {'username': '******'}, 'body': 'Beautiful day in Portland!', }, { 'author': {'username': '******'}, 'body': 'The Avengers movie was so cool!', 'image': 'http://redcapes.it/wp-content/uploads/2018/04/Avengers-Infinity-War-official-poster-1.jpg' }, { 'author': {'username': '******'}, 'body': 'The raccoon is still counting our chances to pass this project!', 'image': 'https://media.giphy.com/media/uJi32NRF7jOA8/giphy-downsized-large.gif' }, ] return render_template('index.html', login=current_user.login, title='Home', posts=posts)
def decorated_view(*args, **kwargs): if not current_user.is_authenticated: return login_manager.unauthorized() elif not current_user.is_confirmed(): return unconfimerd() return func(*args, **kwargs)