Esempio n. 1
0
def studentadd():
	try:
		if session['type']!="admin":
			return redirect(url_for("logout"))
	except:
		return redirect(url_for("logout"))
	result=request.form
	srn,name,pgm,address,phone,branch=result["StudentSRN"],result["StudentName"],result["Program"],result["Address"],result["Phone"],result["Branch"]
	email,passw,repassw=result["email"],result["password"],result["repassword"]
	error,success="",""
	if passw!=repassw:
		error="Passwords Didn't Match!"
	else:
		db_conn=mysql.connector.connect(host = "localhost", port = 3306, user = "******",password="******", database = "pesuapp")
		cur=db_conn.cursor()
		A1=Admin(db_conn,session['email'])
		k=A1.AddStudent(db_conn,email,srn,name,address,phone,pgm,branch)
		if k[0]:
			success=k[1]
			acct_type='student'
			passw=sha256_crypt.hash(passw)
			query="INSERT INTO users(`password`,account_type,email) VALUES(%s,%s,%s)"
			cur.execute(query,(passw,acct_type,email,))
			db_conn.commit()
		else:
			error=k[1]
	db_conn=mysql.connector.connect(host = "localhost", port = 3306, user = "******",password="******", database = "pesuapp")
	cur=db_conn.cursor()
	query="SELECT srn,studname FROM student"
	cur.execute(query)
	res=cur.fetchall()
	if success:
		return render_template("admin_students.html",students=res,success="Student Successfully Added")
	return render_template("admin_students.html",students=res,error=error)