def login(): # TODO: make this do better auth, it needs to set a cookie for a period of # time if request.method == 'POST': form = LoginForm.from_flat(request.form) if form.validate(): user = User.query.filter_by( username=request.form['username']).first() if user == None: form['username'].add_error('Username %s not found' % form['username'].value) gen = Generator() return render_template("admin/login.html", form=form, html=gen) if user.check_password(request.form['password']): g.user = user set_user() if request.args: return redirect(request.args.get('next')) else: return redirect(url_for('frontend.index')) else: gen = Generator() return render_template("admin/login.html", form=form, html=gen) form = LoginForm() gen = Generator() return render_template("admin/login.html", form=form, html=gen, **request.args)
def login(): # TODO: make this do better auth, it needs to set a cookie for a period of # time if request.method == 'POST': form = LoginForm.from_flat(request.form) if form.validate(): user = User.query.filter_by( username=request.form['username']).first() if user == None: form['username'].add_error( 'Username %s not found' % form['username'].value) gen = Generator() return render_template("admin/login.html", form=form, html=gen) if user.check_password(request.form['password']): g.user = user set_user() if request.args: return redirect(request.args.get('next')) else: return redirect(url_for('frontend.index')) else: gen = Generator() return render_template("admin/login.html", form=form, html=gen) form = LoginForm() gen = Generator() return render_template("admin/login.html", form=form, html=gen, **request.args)
def login(): gen = Generator() if request.method == "POST": form = LoginForm.from_flat(request.form) if form.validate(): user = User.query.filter_by(username=request.form["username"]).first() if user != None: if not user.activestatus: form.add_error( """Username %s need to be activated before 1st login. It can only be activated with the link sent to email of this username.""" % form["username"].value ) form.add_error(url_for("admin.activatelogin", _external=True)) return render_template("admin/login.html", form=form, html=gen) if user.check_password(request.form["password"]): save_identity(user) identity_changed.send(cockerel.webapp.app, identity=Identity(user.username)) if "next" in request.args: return redirect(request.args.get("next")) else: return redirect(url_for("frontend.index")) form.add_error("Invalid username %s or password." % form["username"].value) return render_template("admin/login.html", form=form, html=gen) else: return render_template("admin/login.html", form=form, html=gen) form = LoginForm() return render_template("admin/login.html", form=form, html=gen, **request.args)
def activatelogin(): gen = Generator() if request.method == "POST": form = ActivateLoginForm.from_flat(request.form) if form.validate(): user = User.query.filter_by(username=request.form["username"]).first() if user == None: form["username"].add_error("Username %s is invalid" % form["username"].value) return render_template("admin/activatelogin.html", form=form, html=gen) if "activationcode" in request.args: if get_activationcode(user) == request.args["activationcode"]: user.activestatus = True db.session.commit() form = LoginForm() return render_template("admin/login.html", form=form, html=gen) form.add_error("incorrect user name or invalid activation code.") # TODO: Work around until link sent to email feature is setup. activationURL = url_for("activatelogin", activationcode=get_activationcode(user), _external=True) form.add_error(activationURL) return render_template("admin/activatelogin.html", form=form, html=gen) else: return render_template("admin/activatelogin.html", form=form, html=gen) form = ActivateLoginForm() return render_template("admin/activatelogin.html", form=form, html=gen)