Пример #1
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        # Login and validate the user
        user = User.getByUsername(form.username.data)
        if user is not None and user.checkPassword(form.password.data):
            login_user(user, form.rememberMe.data)
            flash("Logged in sucessfully as {}.".format(user.username))
            return redirect(
                request.args.get('next')
                or url_for('user', username=user.username))
        flash('Incorrect username or password')
    return render_template("login.html", form=form)
Пример #2
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        invalidUsername = User.getByUsername(form.username.data)
        invalidEmail = User.getByEmail(form.email.data)
        if invalidUsername is None and invalidEmail is None:
            db.session.add(user)
            db.session.commit()
            flash('Welcome, {}! Please login.'.format(user.username))
            return redirect(url_for('login'))
        elif invalidUsername:
            flash('Username has already been registered by another user.')
        elif invalidEmail:
            flash(
                'E-mail address has already been registered by another user.')
    return render_template("signup.html", form=form)