def delete(self, idx): matchedUser = User.objects(userId=idx) if matchedUser: matchedUser.delete() return "deleted" else: return "failed", 404
def register(): if session.get("email"): return redirect("/index") print(f"request {request.method} {request.form}") form = RegisterForm() print(f"request2 {request.method} {request.form}") if form.validate_on_submit(): print(f"request3 {request.method} {request.form}") user_id = User.objects.count() + 1 email = form.email.data password = form.password.data firstName = form.firstName.data lastName = form.lastName.data user = User(userId=user_id, firstName=firstName, email=email, lastName=lastName) user.set_password(password) user.save() flash("User is successfully registered!", "success") return redirect(url_for("index")) return render_template("register.html", register=True, title="Register", form=form)
def post(self): userData = api.payload print(userData) user_id = User.objects.count() + 1 email = userData["email"] password = userData["password"] firstName = userData["firstName"] lastName = userData["lastName"] user = User(userId=user_id, firstName=firstName, email=email, lastName=lastName) user.set_password(password) user.save() return jsonify(User.objects(email=email))
def enrollment(): userEmail = session.get("email") if not userEmail: return redirect("/login") else: userId = User.objects(email=userEmail) course = None if request.method == "POST": courseId = request.form.get("courseId") title = request.form.get("title") term = request.form.get("term") course = {"courseId": courseId, "title": title, "term": term} Enrollment(courseId=courseId, userId=userId).save() enrolledCourses = User.objects.aggregate(enrollment_query(userId)) print(f"enrolled courses #: {enrolledCourses}") return render_template( "enrollment.html", course=course, enrolledCourses=enrolledCourses, enrollment=True, )
def put(self, idx): data = api.payload User.objects(userId=idx).update(**data) return jsonify(User.objects(userId=idx))
def get(self, idx): return jsonify(User.objects(userId=idx))
def verify_identity(email, password): user = User.objects(email=email).first() if user and user.check_password(password=password): return True else: return False