def index(): db = pymysql.connect("localhost", "flasktamsuser", "flasktamsuser", "tamsdb") cursor = db.cursor() form = LoginForm() if form.validate_on_submit(): user = Login.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): flash("Invalid user") return redirect(url_for("index")) else: #try except finally cursor.execute("select role_id from login where username=%s", form.username.data) data = cursor.fetchone() cursor.execute("select role_name from role where role_id=%s", data) role = cursor.fetchone() db.close() if role == ('admin', ): return render_template("adminHome.html") if role == ('coordinator', ): return render_template("coordinatorHome.html") else: flash("Error") return redirect(url_for("index")) else: return render_template("login.html", form=form)
def index(): form=LoginForm() if form.validate_on_submit(): employee=Employee.query.filter_by(username=form.username.data).first() if employee is None or not employee.check_password(form.password.data): flash("Invalid user") return redirect(url_for("index")) else: return redirect(url_for("home")) else: return render_template("login.html",form=form)
def login(): form = LoginForm() if form.validate_on_submit(): admin = Admin.query.filter_by(username=form.username.data).first() if admin is None or not admin.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('login')) else: session["token"] = admin.get_token() return redirect(url_for("menu")) else: return render_template("login.html", title="Login", form=form)
def index(): if current_user.is_authenticated: return redirect(url_for("menu")) else: form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): flash("Invalid user") return redirect(url_for("index")) else: login_user(user, remember=form.remember_me.data) return redirect(url_for("menu")) else: return render_template("login.html", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() 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) 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) return render_template('login.html',title='Sign In', form=form)
def index(): db = pymysql.connect("localhost", "flaskuser", "flaskuser", "studdb") cursor = db.cursor() dbs = pymysql.connect("localhost", "flaskuser", "flaskuser", "studdb") cursor = dbs.cursor() form = LoginForm() if form.validate_on_submit(): user = Login.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): flash("Invalid user") return redirect(url_for("index")) else: cursor.execute("select role_id from login where username=%s", form.username.data) data = cursor.fetchone() cursor.execute("select role_name from role where role_id=%s", data) role = cursor.fetchone() cursor.execute("select reg_id from login where username=%s", form.username.data) nid = cursor.fetchone() cursor.execute("select fullname from registration where reg_id=%s", nid) name = cursor.fetchone() n = str(name) b = n[2:len(n) - 3] db.close() if role == ('admin', ): return render_template("adminmenu.html", name=b) if role == ('academic cordinator', ): return render_template("acedamicmenu.html", name=b) else: flash("Error") return redirect(url_for("index")) else: return render_template("login.html", form=form)
def faculty_login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() varname = 'Guest' if form.validate_on_submit(): user = FacultyUser.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('faculty_login')) flash('You were succesfully logged in.') login_user(user) session['user'] = form.username.data session['type'] = 'faculty' varname = session['user'] return redirect(url_for('faculty_dashboard')) return render_template('faculty_login.html', title='Sign In', form=form, name=varname)
def login(): # controller-view connection # request type # pass parameters # read parameters # redirect # if user logined redirect to index next_page = request.args.get('next') if current_user.is_authenticated: redirect(url_for("hello")) form = LoginForm() # post request if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() next_page = request.args.get('next') if not user or not user.check_password(form.password.data): flash(_("invalid username or password")) # 登陆失败,如果有跳转页面,需要继续追加到 url 后面 if next_page: return redirect(url_for("login",next_page=next_page)) else: return redirect(url_for("login")) # 登陆2成功 login_user(user, remember=form.remember_me.data) 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) # flash('Login requested for user {}, password {} remember_me={}'.format( # form1.username.data, form1.password.data, form1.remember_me.data)) # return redirect(url_for("hello")) return render_template("login.html", title="Sign in", form=form, next_page=next_page)