def hoat_dong(): if request.method == "GET": act_list = Activities.objects() return render_template("hoat_dong.html", act = act_list) else: if "token" in session: user = session["token"] form = request.form act_list = Activities.objects() att_list = Attribute.objects(username = user).first() hstr_list = All_history.objects(user = user) for att in att_list: sort = form.get(att) if sort != None: return redirect("/hoat-dong-sx-ttt-" + att) for act in act_list: action = form.get(act["tit"]) if action != None: hstr = All_history(user = user, tit = act["tit"], cre = act["cre"], st = act["st"], knl = act["knl"], per = act["per"], soc = act["soc"] ) for att in att_list : if att in act and att != "id": att_list[att] = att_list[att] + act[att] if att_list[att] < 0: att_list[att] = 0 att_list.save() hstr.save() break return redirect("/save_post") else: return redirect(url_for("sign_in"))
def sign_up(): if request.method == "GET": return render_template("sign_up.html") else: form = request.form fullname = form["fullname"] username = form["username"] email = form["email"] password = form["password"] confirm = form["confirm"] bday = form["bday"] gender = form["gender"] phone = form["telephone"] existUsername = User.objects(username=username).first() existEmail = User.objects(email=email).first() error = None if fullname == "" or username == "" or email == "" or password == "" or confirm == "" or bday == "" or gender == "" or phone == "": error = "Bạn phải điền đầy đủ thông tin" return render_template("sign_up.html", error=error) elif existUsername is not None: error = "Tên đăng nhập đã tồn tại" return render_template("sign_up.html", error=error) elif len(username) < 8: error = "Tên người dùng không khả dụng" return render_template("sign_up.html", error=error) elif len(password) < 8: error = "Mật khẩu không khả dụng" return render_template("sign_up.html", error=error) elif confirm != password: error = "Rất tiếc. Xác nhận mật khẩu sai" return render_template("sign_up.html", error=error) else: m = User( fullname=fullname, username=username, email=email, password=password, birthday=bday, gender=gender, phone=phone, avt= "https://cdn1.iconfinder.com/data/icons/ninja-things-1/1772/ninja-simple-512.png" ) m.save() att = Attribute(username=username) att.save() hstr_list = All_history(user=username) hstr_list.save() Friend(username=username).save() return redirect("/sign_in")